Show More
@@ -13,29 +13,9 b' from . import (' | |||||
13 | pycompat, |
|
13 | pycompat, | |
14 | util, |
|
14 | util, | |
15 | ) |
|
15 | ) | |
16 |
|
16 | from .utils import ( | ||
17 | def _formatsetrepr(r): |
|
17 | stringutil, | |
18 | """Format an optional printable representation of a set |
|
18 | ) | |
19 |
|
||||
20 | ======== ================================= |
|
|||
21 | type(r) example |
|
|||
22 | ======== ================================= |
|
|||
23 | tuple ('<not %r>', other) |
|
|||
24 | bytes '<branch closed>' |
|
|||
25 | callable lambda: '<branch %r>' % sorted(b) |
|
|||
26 | object other |
|
|||
27 | ======== ================================= |
|
|||
28 | """ |
|
|||
29 | if r is None: |
|
|||
30 | return '' |
|
|||
31 | elif isinstance(r, tuple): |
|
|||
32 | return r[0] % pycompat.rapply(pycompat.maybebytestr, r[1:]) |
|
|||
33 | elif isinstance(r, bytes): |
|
|||
34 | return r |
|
|||
35 | elif callable(r): |
|
|||
36 | return r() |
|
|||
37 | else: |
|
|||
38 | return pycompat.byterepr(r) |
|
|||
39 |
|
19 | |||
40 | def _typename(o): |
|
20 | def _typename(o): | |
41 | return pycompat.sysbytes(type(o).__name__).lstrip('_') |
|
21 | return pycompat.sysbytes(type(o).__name__).lstrip('_') | |
@@ -392,7 +372,7 b' class baseset(abstractsmartset):' | |||||
392 | @encoding.strmethod |
|
372 | @encoding.strmethod | |
393 | def __repr__(self): |
|
373 | def __repr__(self): | |
394 | d = {None: '', False: '-', True: '+'}[self._ascending] |
|
374 | d = {None: '', False: '-', True: '+'}[self._ascending] | |
395 |
s = |
|
375 | s = stringutil.buildrepr(self._datarepr) | |
396 | if not s: |
|
376 | if not s: | |
397 | l = self._list |
|
377 | l = self._list | |
398 | # if _list has been built from a set, it might have a different |
|
378 | # if _list has been built from a set, it might have a different | |
@@ -514,7 +494,7 b' class filteredset(abstractsmartset):' | |||||
514 | @encoding.strmethod |
|
494 | @encoding.strmethod | |
515 | def __repr__(self): |
|
495 | def __repr__(self): | |
516 | xs = [pycompat.byterepr(self._subset)] |
|
496 | xs = [pycompat.byterepr(self._subset)] | |
517 |
s = |
|
497 | s = stringutil.buildrepr(self._condrepr) | |
518 | if s: |
|
498 | if s: | |
519 | xs.append(s) |
|
499 | xs.append(s) | |
520 | return '<%s %s>' % (_typename(self), ', '.join(xs)) |
|
500 | return '<%s %s>' % (_typename(self), ', '.join(xs)) |
@@ -90,6 +90,29 b' def prettyrepr(o):' | |||||
90 | p0, p1 = q0, q1 |
|
90 | p0, p1 = q0, q1 | |
91 | return '\n'.join(' ' * l + s for l, s in lines) |
|
91 | return '\n'.join(' ' * l + s for l, s in lines) | |
92 |
|
92 | |||
|
93 | def buildrepr(r): | |||
|
94 | """Format an optional printable representation from unexpanded bits | |||
|
95 | ||||
|
96 | ======== ================================= | |||
|
97 | type(r) example | |||
|
98 | ======== ================================= | |||
|
99 | tuple ('<not %r>', other) | |||
|
100 | bytes '<branch closed>' | |||
|
101 | callable lambda: '<branch %r>' % sorted(b) | |||
|
102 | object other | |||
|
103 | ======== ================================= | |||
|
104 | """ | |||
|
105 | if r is None: | |||
|
106 | return '' | |||
|
107 | elif isinstance(r, tuple): | |||
|
108 | return r[0] % pycompat.rapply(pycompat.maybebytestr, r[1:]) | |||
|
109 | elif isinstance(r, bytes): | |||
|
110 | return r | |||
|
111 | elif callable(r): | |||
|
112 | return r() | |||
|
113 | else: | |||
|
114 | return pycompat.byterepr(r) | |||
|
115 | ||||
93 | def binary(s): |
|
116 | def binary(s): | |
94 | """return true if a string is binary data""" |
|
117 | """return true if a string is binary data""" | |
95 | return bool(s and '\0' in s) |
|
118 | return bool(s and '\0' in s) |
General Comments 0
You need to be logged in to leave comments.
Login now