changeset 31229:f8e06821c118

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 08 Mar 2017 00:40:15 +0530
parents 4cc3797aa59c
children 37596c980662
files mercurial/store.py
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/store.py	Thu Mar 02 13:27:42 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()