Alex Grönholm avatar Alex Grönholm committed 5b8eb97

fixed syntax errors on py < 2.5

Comments (0)

Files changed (1)

     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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.