# HG changeset patch # User Brett Cannon # Date 1425740932 18000 # Node ID ea80bd2775f6612399eb3aedf2444fcb11b0cf8a # 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 ea80bd2775f6 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)] '''