[PATCH hglib] hglib: Introduce util.b() (issue4520)

Brett Cannon brett at python.org
Sat Mar 7 15:15:21 UTC 2015


# HG changeset patch
# User Brett Cannon <brett at python.org>
# Date 1425740932 18000
#      Sat Mar 07 10:08:52 2015 -0500
# Node ID 9612272f5697fb3895c65b0eca4e68dcbd68ffa0
# Parent  9c4f5246720808b9862550159a5fa35ec1c8756b
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.

diff -r 9c4f52467208 -r 9612272f5697 hglib/util.py
--- 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)] '''


More information about the Mercurial-devel mailing list