Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/parser.py @ 39087:0a2ce5b43574
parser: replace bespoke _brepr with stringutil.pprint
Differential Revision: https://phab.mercurial-scm.org/D4242
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 10 Aug 2018 00:12:55 -0400 |
parents | f0b6fbea00cf |
children | 29798c9ba5c9 |
comparison
equal
deleted
inserted
replaced
39086:b53ec524420b | 39087:0a2ce5b43574 |
---|---|
18 | 18 |
19 from __future__ import absolute_import, print_function | 19 from __future__ import absolute_import, print_function |
20 | 20 |
21 from .i18n import _ | 21 from .i18n import _ |
22 from . import ( | 22 from . import ( |
23 encoding, | |
24 error, | 23 error, |
25 pycompat, | 24 pycompat, |
26 util, | 25 util, |
27 ) | 26 ) |
28 from .utils import ( | 27 from .utils import ( |
196 return stringutil.unescapestr(s) | 195 return stringutil.unescapestr(s) |
197 except ValueError as e: | 196 except ValueError as e: |
198 # mangle Python's exception into our format | 197 # mangle Python's exception into our format |
199 raise error.ParseError(pycompat.bytestr(e).lower()) | 198 raise error.ParseError(pycompat.bytestr(e).lower()) |
200 | 199 |
201 def _brepr(obj): | |
202 if isinstance(obj, bytes): | |
203 return b"'%s'" % stringutil.escapestr(obj) | |
204 return encoding.strtolocal(repr(obj)) | |
205 | |
206 def _prettyformat(tree, leafnodes, level, lines): | 200 def _prettyformat(tree, leafnodes, level, lines): |
207 if not isinstance(tree, tuple): | 201 if not isinstance(tree, tuple): |
208 lines.append((level, _brepr(tree))) | 202 lines.append((level, stringutil.pprint(tree))) |
209 elif tree[0] in leafnodes: | 203 elif tree[0] in leafnodes: |
210 rs = map(_brepr, tree[1:]) | 204 rs = map(stringutil.pprint, tree[1:]) |
211 lines.append((level, '(%s %s)' % (tree[0], ' '.join(rs)))) | 205 lines.append((level, '(%s %s)' % (tree[0], ' '.join(rs)))) |
212 else: | 206 else: |
213 lines.append((level, '(%s' % tree[0])) | 207 lines.append((level, '(%s' % tree[0])) |
214 for s in tree[1:]: | 208 for s in tree[1:]: |
215 _prettyformat(s, leafnodes, level + 1, lines) | 209 _prettyformat(s, leafnodes, level + 1, lines) |