comparison mercurial/store.py @ 29071:2f58975eb2cb

store: treat range as a generator instead of a list for py3 compat
author timeless <timeless@mozdev.org>
date Sun, 10 Apr 2016 07:28:26 +0000
parents fb92927f9775
children 81c38cb9c1a1
comparison
equal deleted inserted replaced
29070:29a7d591ff42 29071:2f58975eb2cb
55 return (path 55 return (path
56 .replace(".d.hg/", ".d/") 56 .replace(".d.hg/", ".d/")
57 .replace(".i.hg/", ".i/") 57 .replace(".i.hg/", ".i/")
58 .replace(".hg.hg/", ".hg/")) 58 .replace(".hg.hg/", ".hg/"))
59 59
60 def _reserved():
61 ''' characters that are problematic for filesystems
62
63 * ascii escapes (0..31)
64 * ascii hi (126..255)
65 * windows specials
66
67 these characters will be escaped by encodefunctions
68 '''
69 winreserved = [ord(x) for x in '\\:*?"<>|']
70 for x in range(32):
71 yield x
72 for x in range(126, 256):
73 yield x
74 for x in winreserved:
75 yield x
76
60 def _buildencodefun(): 77 def _buildencodefun():
61 ''' 78 '''
62 >>> enc, dec = _buildencodefun() 79 >>> enc, dec = _buildencodefun()
63 80
64 >>> enc('nothing/special.txt') 81 >>> enc('nothing/special.txt')
80 'the~07quick~adshot' 97 'the~07quick~adshot'
81 >>> dec('the~07quick~adshot') 98 >>> dec('the~07quick~adshot')
82 'the\\x07quick\\xadshot' 99 'the\\x07quick\\xadshot'
83 ''' 100 '''
84 e = '_' 101 e = '_'
85 winreserved = [ord(x) for x in '\\:*?"<>|']
86 cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) 102 cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
87 for x in (range(32) + range(126, 256) + winreserved): 103 for x in _reserved():
88 cmap[chr(x)] = "~%02x" % x 104 cmap[chr(x)] = "~%02x" % x
89 for x in range(ord("A"), ord("Z") + 1) + [ord(e)]: 105 for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
90 cmap[chr(x)] = e + chr(x).lower() 106 cmap[chr(x)] = e + chr(x).lower()
91 dmap = {} 107 dmap = {}
92 for k, v in cmap.iteritems(): 108 for k, v in cmap.iteritems():
93 dmap[v] = k 109 dmap[v] = k
94 def decode(s): 110 def decode(s):
132 >>> f('hello:world?') 148 >>> f('hello:world?')
133 'hello~3aworld~3f' 149 'hello~3aworld~3f'
134 >>> f('the\x07quick\xADshot') 150 >>> f('the\x07quick\xADshot')
135 'the~07quick~adshot' 151 'the~07quick~adshot'
136 ''' 152 '''
137 winreserved = [ord(x) for x in '\\:*?"<>|']
138 cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) 153 cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
139 for x in (range(32) + range(126, 256) + winreserved): 154 for x in _reserved():
140 cmap[chr(x)] = "~%02x" % x 155 cmap[chr(x)] = "~%02x" % x
141 for x in range(ord("A"), ord("Z") + 1): 156 for x in range(ord("A"), ord("Z") + 1):
142 cmap[chr(x)] = chr(x).lower() 157 cmap[chr(x)] = chr(x).lower()
143 return lambda s: "".join([cmap[c] for c in s]) 158 return lambda s: "".join([cmap[c] for c in s])
144 159