diff hglib/util.py @ 141:ea80bd2775f6

hglib: introduce util.b() (issue4520) The util.b() function will be used to mark all string literals in the code base which should be treated as bytes instead of text. This is to help with supporting Python 3.
author Brett Cannon <brett@python.org>
date Sat, 07 Mar 2015 10:08:52 -0500
parents 1b47146a4a2c
children fe74d5599539
line wrap: on
line diff
--- a/hglib/util.py	Sat Jan 17 17:54:40 2015 -0800
+++ b/hglib/util.py	Sat Mar 07 10:08:52 2015 -0500
@@ -1,4 +1,13 @@
-import itertools, cStringIO, error, os, subprocess
+import itertools, cStringIO, error, os, subprocess, sys
+
+if sys.version_info[0] > 2:
+    def b(s):
+        """Encode the string as bytes."""
+        return s.encode('latin-1')
+else:
+    def b(s):
+        """Encode the string as bytes."""
+        return s
 
 def grouper(n, iterable):
     ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''