Mercurial > hg
comparison mercurial/store.py @ 30077:8f42d8c412c8
py3: make encodefun in store.py compatible with py3k
This ensures that the filename encoding functions always map bytestrings
to bytestrings regardless of python version.
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Sat, 08 Oct 2016 08:54:05 -0700 |
parents | 400dfded8a29 |
children | e1e7190457cf |
comparison
equal
deleted
inserted
replaced
30076:400dfded8a29 | 30077:8f42d8c412c8 |
---|---|
14 | 14 |
15 from .i18n import _ | 15 from .i18n import _ |
16 from . import ( | 16 from . import ( |
17 error, | 17 error, |
18 parsers, | 18 parsers, |
19 pycompat, | |
19 scmutil, | 20 scmutil, |
20 util, | 21 util, |
21 ) | 22 ) |
22 | 23 |
23 # This avoids a collision between a file named foo and a dir named | 24 # This avoids a collision between a file named foo and a dir named |
96 'the~07quick~adshot' | 97 'the~07quick~adshot' |
97 >>> dec('the~07quick~adshot') | 98 >>> dec('the~07quick~adshot') |
98 'the\\x07quick\\xadshot' | 99 'the\\x07quick\\xadshot' |
99 ''' | 100 ''' |
100 e = '_' | 101 e = '_' |
101 cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) | 102 if pycompat.ispy3: |
103 xchr = lambda x: bytes([x]) | |
104 asciistr = bytes(xrange(127)) | |
105 else: | |
106 xchr = chr | |
107 asciistr = map(chr, xrange(127)) | |
108 capitals = list(range(ord("A"), ord("Z") + 1)) | |
109 | |
110 cmap = {x:x for x in asciistr} | |
102 for x in _reserved(): | 111 for x in _reserved(): |
103 cmap[chr(x)] = "~%02x" % x | 112 cmap[xchr(x)] = "~%02x" % x |
104 for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]: | 113 for x in capitals + [ord(e)]: |
105 cmap[chr(x)] = e + chr(x).lower() | 114 cmap[xchr(x)] = e + xchr(x).lower() |
115 | |
106 dmap = {} | 116 dmap = {} |
107 for k, v in cmap.iteritems(): | 117 for k, v in cmap.iteritems(): |
108 dmap[v] = k | 118 dmap[v] = k |
109 def decode(s): | 119 def decode(s): |
110 i = 0 | 120 i = 0 |