##// END OF EJS Templates
stringutil: move _formatsetrepr() from smartset...
Yuya Nishihara -
r38595:a3130208 default
parent child Browse files
Show More
@@ -13,29 +13,9 b' from . import ('
13 13 pycompat,
14 14 util,
15 15 )
16
17 def _formatsetrepr(r):
18 """Format an optional printable representation of a set
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)
16 from .utils import (
17 stringutil,
18 )
39 19
40 20 def _typename(o):
41 21 return pycompat.sysbytes(type(o).__name__).lstrip('_')
@@ -392,7 +372,7 b' class baseset(abstractsmartset):'
392 372 @encoding.strmethod
393 373 def __repr__(self):
394 374 d = {None: '', False: '-', True: '+'}[self._ascending]
395 s = _formatsetrepr(self._datarepr)
375 s = stringutil.buildrepr(self._datarepr)
396 376 if not s:
397 377 l = self._list
398 378 # if _list has been built from a set, it might have a different
@@ -514,7 +494,7 b' class filteredset(abstractsmartset):'
514 494 @encoding.strmethod
515 495 def __repr__(self):
516 496 xs = [pycompat.byterepr(self._subset)]
517 s = _formatsetrepr(self._condrepr)
497 s = stringutil.buildrepr(self._condrepr)
518 498 if s:
519 499 xs.append(s)
520 500 return '<%s %s>' % (_typename(self), ', '.join(xs))
@@ -90,6 +90,29 b' def prettyrepr(o):'
90 90 p0, p1 = q0, q1
91 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 116 def binary(s):
94 117 """return true if a string is binary data"""
95 118 return bool(s and '\0' in s)
General Comments 0
You need to be logged in to leave comments. Login now