[PATCH 1 of 2 hglib] util: introduce strtobytes() (issue4520)

Brett Cannon brett at python.org
Thu Mar 19 21:43:47 UTC 2015


# HG changeset patch
# User Brett Cannon <brett at python.org>
# Date 1426801346 14400
#      Thu Mar 19 17:42:26 2015 -0400
# Node ID b94e1263836c4fdcc4809e2199b97ab24cbd123d
# Parent  958307b30af3a4f1735831db623fcb64ec77be4f
util: introduce strtobytes() (issue4520)

The strtobytes() function takes an object, gets its string
representation, and then convert that to bytes.

diff -r 958307b30af3 -r b94e1263836c hglib/util.py
--- a/hglib/util.py	Mon Mar 16 17:59:27 2015 -0400
+++ b/hglib/util.py	Thu Mar 19 17:42:26 2015 -0400
@@ -14,6 +14,10 @@
         """Encode the string as bytes."""
         return s
 
+def strtobytes(s):
+    """Return the bytes of the string representation of an object."""
+    return str(s).encode('latin-1')
+
 def grouper(n, iterable):
     ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''
     args = [iter(iterable)] * n


More information about the Mercurial-devel mailing list