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

login
register
mail settings
Submitter Brett Cannon
Date March 7, 2015, 3:15 p.m.
Message ID <9612272f5697fb3895c6.1425741321@bcannon-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/7925/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Brett Cannon - March 7, 2015, 3:15 p.m.
# HG changeset patch
# User Brett Cannon <brett@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.
Matt Mackall - March 7, 2015, 8:24 p.m.
On Sat, 2015-03-07 at 10:15 -0500, Brett Cannon wrote:
> # HG changeset patch
> # User Brett Cannon <brett@python.org>
> # Date 1425740932 18000
> #      Sat Mar 07 10:08:52 2015 -0500
> # Node ID 9612272f5697fb3895c65b0eca4e68dcbd68ffa0
> # Parent  9c4f5246720808b9862550159a5fa35ec1c8756b
> hglib: Introduce util.b() (issue4520)

Queued for hglib, thanks.

Patch

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)] '''