Mercurial > hg
comparison mercurial/store.py @ 34131:0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Our code transformer can't rewrite string literals in docstrings, and I
don't want to make the transformer more complex.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 Sep 2017 14:32:11 +0900 |
parents | a42369e04aee |
children | 414a3513c2bd |
comparison
equal
deleted
inserted
replaced
34130:ada8a19672ab | 34131:0fa781320203 |
---|---|
25 | 25 |
26 # This avoids a collision between a file named foo and a dir named | 26 # This avoids a collision between a file named foo and a dir named |
27 # foo.i or foo.d | 27 # foo.i or foo.d |
28 def _encodedir(path): | 28 def _encodedir(path): |
29 ''' | 29 ''' |
30 >>> _encodedir('data/foo.i') | 30 >>> _encodedir(b'data/foo.i') |
31 'data/foo.i' | 31 'data/foo.i' |
32 >>> _encodedir('data/foo.i/bla.i') | 32 >>> _encodedir(b'data/foo.i/bla.i') |
33 'data/foo.i.hg/bla.i' | 33 'data/foo.i.hg/bla.i' |
34 >>> _encodedir('data/foo.i.hg/bla.i') | 34 >>> _encodedir(b'data/foo.i.hg/bla.i') |
35 'data/foo.i.hg.hg/bla.i' | 35 'data/foo.i.hg.hg/bla.i' |
36 >>> _encodedir('data/foo.i\\ndata/foo.i/bla.i\\ndata/foo.i.hg/bla.i\\n') | 36 >>> _encodedir(b'data/foo.i\\ndata/foo.i/bla.i\\ndata/foo.i.hg/bla.i\\n') |
37 'data/foo.i\\ndata/foo.i.hg/bla.i\\ndata/foo.i.hg.hg/bla.i\\n' | 37 'data/foo.i\\ndata/foo.i.hg/bla.i\\ndata/foo.i.hg.hg/bla.i\\n' |
38 ''' | 38 ''' |
39 return (path | 39 return (path |
40 .replace(".hg/", ".hg.hg/") | 40 .replace(".hg/", ".hg.hg/") |
41 .replace(".i/", ".i.hg/") | 41 .replace(".i/", ".i.hg/") |
43 | 43 |
44 encodedir = getattr(parsers, 'encodedir', _encodedir) | 44 encodedir = getattr(parsers, 'encodedir', _encodedir) |
45 | 45 |
46 def decodedir(path): | 46 def decodedir(path): |
47 ''' | 47 ''' |
48 >>> decodedir('data/foo.i') | 48 >>> decodedir(b'data/foo.i') |
49 'data/foo.i' | 49 'data/foo.i' |
50 >>> decodedir('data/foo.i.hg/bla.i') | 50 >>> decodedir(b'data/foo.i.hg/bla.i') |
51 'data/foo.i/bla.i' | 51 'data/foo.i/bla.i' |
52 >>> decodedir('data/foo.i.hg.hg/bla.i') | 52 >>> decodedir(b'data/foo.i.hg.hg/bla.i') |
53 'data/foo.i.hg/bla.i' | 53 'data/foo.i.hg/bla.i' |
54 ''' | 54 ''' |
55 if ".hg/" not in path: | 55 if ".hg/" not in path: |
56 return path | 56 return path |
57 return (path | 57 return (path |
78 | 78 |
79 def _buildencodefun(): | 79 def _buildencodefun(): |
80 ''' | 80 ''' |
81 >>> enc, dec = _buildencodefun() | 81 >>> enc, dec = _buildencodefun() |
82 | 82 |
83 >>> enc('nothing/special.txt') | 83 >>> enc(b'nothing/special.txt') |
84 'nothing/special.txt' | 84 'nothing/special.txt' |
85 >>> dec('nothing/special.txt') | 85 >>> dec(b'nothing/special.txt') |
86 'nothing/special.txt' | 86 'nothing/special.txt' |
87 | 87 |
88 >>> enc('HELLO') | 88 >>> enc(b'HELLO') |
89 '_h_e_l_l_o' | 89 '_h_e_l_l_o' |
90 >>> dec('_h_e_l_l_o') | 90 >>> dec(b'_h_e_l_l_o') |
91 'HELLO' | 91 'HELLO' |
92 | 92 |
93 >>> enc('hello:world?') | 93 >>> enc(b'hello:world?') |
94 'hello~3aworld~3f' | 94 'hello~3aworld~3f' |
95 >>> dec('hello~3aworld~3f') | 95 >>> dec(b'hello~3aworld~3f') |
96 'hello:world?' | 96 'hello:world?' |
97 | 97 |
98 >>> enc('the\x07quick\xADshot') | 98 >>> enc(b'the\x07quick\xADshot') |
99 'the~07quick~adshot' | 99 'the~07quick~adshot' |
100 >>> dec('the~07quick~adshot') | 100 >>> dec(b'the~07quick~adshot') |
101 'the\\x07quick\\xadshot' | 101 'the\\x07quick\\xadshot' |
102 ''' | 102 ''' |
103 e = '_' | 103 e = '_' |
104 xchr = pycompat.bytechr | 104 xchr = pycompat.bytechr |
105 asciistr = list(map(xchr, range(127))) | 105 asciistr = list(map(xchr, range(127))) |
131 | 131 |
132 _encodefname, _decodefname = _buildencodefun() | 132 _encodefname, _decodefname = _buildencodefun() |
133 | 133 |
134 def encodefilename(s): | 134 def encodefilename(s): |
135 ''' | 135 ''' |
136 >>> encodefilename('foo.i/bar.d/bla.hg/hi:world?/HELLO') | 136 >>> encodefilename(b'foo.i/bar.d/bla.hg/hi:world?/HELLO') |
137 'foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o' | 137 'foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o' |
138 ''' | 138 ''' |
139 return _encodefname(encodedir(s)) | 139 return _encodefname(encodedir(s)) |
140 | 140 |
141 def decodefilename(s): | 141 def decodefilename(s): |
142 ''' | 142 ''' |
143 >>> decodefilename('foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o') | 143 >>> decodefilename(b'foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o') |
144 'foo.i/bar.d/bla.hg/hi:world?/HELLO' | 144 'foo.i/bar.d/bla.hg/hi:world?/HELLO' |
145 ''' | 145 ''' |
146 return decodedir(_decodefname(s)) | 146 return decodedir(_decodefname(s)) |
147 | 147 |
148 def _buildlowerencodefun(): | 148 def _buildlowerencodefun(): |
149 ''' | 149 ''' |
150 >>> f = _buildlowerencodefun() | 150 >>> f = _buildlowerencodefun() |
151 >>> f('nothing/special.txt') | 151 >>> f(b'nothing/special.txt') |
152 'nothing/special.txt' | 152 'nothing/special.txt' |
153 >>> f('HELLO') | 153 >>> f(b'HELLO') |
154 'hello' | 154 'hello' |
155 >>> f('hello:world?') | 155 >>> f(b'hello:world?') |
156 'hello~3aworld~3f' | 156 'hello~3aworld~3f' |
157 >>> f('the\x07quick\xADshot') | 157 >>> f(b'the\x07quick\xADshot') |
158 'the~07quick~adshot' | 158 'the~07quick~adshot' |
159 ''' | 159 ''' |
160 cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) | 160 cmap = dict([(chr(x), chr(x)) for x in xrange(127)]) |
161 for x in _reserved(): | 161 for x in _reserved(): |
162 cmap[chr(x)] = "~%02x" % x | 162 cmap[chr(x)] = "~%02x" % x |
178 True. Parameter path is assumed to be all lowercase. | 178 True. Parameter path is assumed to be all lowercase. |
179 A segment only needs encoding if a reserved name appears as a | 179 A segment only needs encoding if a reserved name appears as a |
180 basename (e.g. "aux", "aux.foo"). A directory or file named "foo.aux" | 180 basename (e.g. "aux", "aux.foo"). A directory or file named "foo.aux" |
181 doesn't need encoding. | 181 doesn't need encoding. |
182 | 182 |
183 >>> s = '.foo/aux.txt/txt.aux/con/prn/nul/foo.' | 183 >>> s = b'.foo/aux.txt/txt.aux/con/prn/nul/foo.' |
184 >>> _auxencode(s.split('/'), True) | 184 >>> _auxencode(s.split(b'/'), True) |
185 ['~2efoo', 'au~78.txt', 'txt.aux', 'co~6e', 'pr~6e', 'nu~6c', 'foo~2e'] | 185 ['~2efoo', 'au~78.txt', 'txt.aux', 'co~6e', 'pr~6e', 'nu~6c', 'foo~2e'] |
186 >>> s = '.com1com2/lpt9.lpt4.lpt1/conprn/com0/lpt0/foo.' | 186 >>> s = b'.com1com2/lpt9.lpt4.lpt1/conprn/com0/lpt0/foo.' |
187 >>> _auxencode(s.split('/'), False) | 187 >>> _auxencode(s.split(b'/'), False) |
188 ['.com1com2', 'lp~749.lpt4.lpt1', 'conprn', 'com0', 'lpt0', 'foo~2e'] | 188 ['.com1com2', 'lp~749.lpt4.lpt1', 'conprn', 'com0', 'lpt0', 'foo~2e'] |
189 >>> _auxencode(['foo. '], True) | 189 >>> _auxencode([b'foo. '], True) |
190 ['foo.~20'] | 190 ['foo.~20'] |
191 >>> _auxencode([' .foo'], True) | 191 >>> _auxencode([b' .foo'], True) |
192 ['~20.foo'] | 192 ['~20.foo'] |
193 ''' | 193 ''' |
194 for i, n in enumerate(path): | 194 for i, n in enumerate(path): |
195 if not n: | 195 if not n: |
196 continue | 196 continue |