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

login
register
mail settings
Submitter Brett Cannon
Date March 19, 2015, 9:43 p.m.
Message ID <b94e1263836c4fdcc480.1426801427@bcannon-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/8182/
State Accepted
Headers show

Comments

Brett Cannon - March 19, 2015, 9:43 p.m.
# HG changeset patch
# User Brett Cannon <brett@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.

Patch

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