[PATCH 1 of 3 py3] store: slice over a bytestring to get characters instead of ascii values

Pulkit Goyal 7895pulkit at gmail.com
Tue Mar 7 19:21:23 UTC 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1488913815 -19800
#      Wed Mar 08 00:40:15 2017 +0530
# Node ID f8ec9104d219a01357e8f6118286d9b212695bbe
# Parent  b9834a28d200fad7584c6c98efb1b81bdc5f4106
store: slice over a bytestring to get characters instead of ascii values

On Python 2,

>>> a = b'abc'
>>> a[1]
'b'

Whereas on python 3,

>>> a = b'abc'
>>> a[1]
98
>>> a[1:2]
b'b'

This does not change behaviour on python 2.

diff -r b9834a28d200 -r f8ec9104d219 mercurial/store.py
--- a/mercurial/store.py	Tue Feb 28 15:19:08 2017 +0100
+++ b/mercurial/store.py	Wed Mar 08 00:40:15 2017 +0530
@@ -101,7 +101,7 @@
     e = '_'
     if pycompat.ispy3:
         xchr = lambda x: bytes([x])
-        asciistr = [bytes(a) for a in range(127)]
+        asciistr = [bytes([a]) for a in range(127)]
     else:
         xchr = chr
         asciistr = map(chr, xrange(127))
@@ -128,7 +128,7 @@
                     pass
             else:
                 raise KeyError
-    return (lambda s: ''.join([cmap[c] for c in s]),
+    return (lambda s: ''.join([cmap[s[c:c+1]] for c in xrange(len(s))]),
             lambda s: ''.join(list(decode(s))))
 
 _encodefname, _decodefname = _buildencodefun()


More information about the Mercurial-devel mailing list