Commits

Alex Grönholm  committed 5b8eb97

fixed syntax errors on py < 2.5

  • Participants
  • Parent commits 1125f45

Comments (0)

Files changed (1)

File pymta/compat.py

     binary = bytes = str
     unicode = unicode
     range = xrange
-    b = lambda x, encoding='iso-8859-1': x.encode(encoding) if isinstance(x, unicode) else str(x)
-    b64encode = lambda x: base64.b64encode(x)
-    b64decode = lambda x: base64.b64decode(x)
+    b64encode = lambda x: x.encode('base64')
+    b64decode = lambda x: x.decode('base64')
     func_code = lambda func: func.im_func.func_code
     dict_items = lambda dct: dct.items()
     dict_keys = lambda dct: dct.keys()
     binary = bytes = b = bytes
     unicode = str
     range = range
-    b = lambda x, encoding='iso-8859-1': x.encode(encoding) if isinstance(x, unicode) else bytes(x)
     b64encode = lambda x: base64.b64encode(b(x)).decode('ascii')
     b64decode = lambda x: base64.b64decode(b(x)).decode('ascii')
     func_code = lambda func: func.__func__.__code__
     from sets import Set as set
 else:
     set = set
+
+
+def b(x, encoding='iso-8859-1'):
+    if isinstance(x, unicode):
+        return x.encode(encoding)
+    return bytes(x)