Mercurial > public > mercurial-scm > hg
comparison mercurial/changelog.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 | bfb38c5cebf4 |
children | 264872544362 |
comparison
equal
deleted
inserted
replaced
34130:ada8a19672ab | 34131:0fa781320203 |
---|---|
25 | 25 |
26 _defaultextra = {'branch': 'default'} | 26 _defaultextra = {'branch': 'default'} |
27 | 27 |
28 def _string_escape(text): | 28 def _string_escape(text): |
29 """ | 29 """ |
30 >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} | 30 >>> d = {b'nl': chr(10), b'bs': chr(92), b'cr': chr(13), b'nul': chr(0)} |
31 >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d | 31 >>> s = b"ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
32 >>> s | 32 >>> s |
33 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' | 33 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
34 >>> res = _string_escape(s) | 34 >>> res = _string_escape(s) |
35 >>> s == util.unescapestr(res) | 35 >>> s == util.unescapestr(res) |
36 True | 36 True |
39 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') | 39 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
40 return text.replace('\0', '\\0') | 40 return text.replace('\0', '\\0') |
41 | 41 |
42 def decodeextra(text): | 42 def decodeextra(text): |
43 """ | 43 """ |
44 >>> sorted(decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'}) | 44 >>> sorted(decodeextra(encodeextra({b'foo': b'bar', b'baz': chr(0) + b'2'}) |
45 ... ).iteritems()) | 45 ... ).iteritems()) |
46 [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')] | 46 [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')] |
47 >>> sorted(decodeextra(encodeextra({'foo': 'bar', | 47 >>> sorted(decodeextra(encodeextra({b'foo': b'bar', |
48 ... 'baz': chr(92) + chr(0) + '2'}) | 48 ... b'baz': chr(92) + chr(0) + b'2'}) |
49 ... ).iteritems()) | 49 ... ).iteritems()) |
50 [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')] | 50 [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')] |
51 """ | 51 """ |
52 extra = _defaultextra.copy() | 52 extra = _defaultextra.copy() |
53 for l in text.split('\0'): | 53 for l in text.split('\0'): |