Commits

Peter Sanchez committed cd65dd3

Added errors support for encode helpers

  • Participants
  • Parent commits 9e5a409
  • Branches trunk

Comments (0)

Files changed (2)

File webutils/__init__.py

-__version__ = '0.8'
+__version__ = '0.9'

File webutils/helpers.py

 '''
 
 
-def easy_encode(value, enc_type='utf-8'):
+def easy_encode(value, enc_type='utf-8', errors='strict'):
     ''' Try to .encode(enc_type) on value.
     '''
     try:
-        return value.encode(enc_type)
+        return value.encode(enc_type, errors)
     except AttributeError:
         return value
 
 
-def encode_dict(data, enc_type='utf-8'):
+def encode_dict(data, enc_type='utf-8', errors='strict'):
     ''' Take a dictionary and encode appropriate variables 
         to specified encoding.
     '''
     for key, value in data.items():
-        data[key] = easy_encode(value, enc_type)
+        data[key] = easy_encode(value, enc_type, errors)
     return data
 
 
     ''' Take "data" variable and strip out every character
         that isn't in "allowed_chars" variable
     '''
-    return ''.join([x for x in data if x in allowed_chars])
+    return ''.join([x for x in data if x in allowed_chars])