comparison mercurial/utils/stringutil.py @ 37941:af83a0ed0afb

stringutil: make pprint() forward uninteresting object to b'%r' We appear to start using pprint() as a replacement for repr(), so it's probably safer to support any Python objects instead of complaining about that.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 10 May 2018 21:00:58 +0900
parents bf6bb710b40f
children 32bc3815efae
comparison
equal deleted inserted replaced
37940:31c37e703cee 37941:af83a0ed0afb
38 elif isinstance(o, dict): 38 elif isinstance(o, dict):
39 return '{%s}' % (b', '.join( 39 return '{%s}' % (b', '.join(
40 '%s: %s' % (pprint(k, bprefix=bprefix), 40 '%s: %s' % (pprint(k, bprefix=bprefix),
41 pprint(v, bprefix=bprefix)) 41 pprint(v, bprefix=bprefix))
42 for k, v in sorted(o.items()))) 42 for k, v in sorted(o.items())))
43 elif isinstance(o, bool):
44 return b'True' if o else b'False'
45 elif isinstance(o, int):
46 return '%d' % o
47 elif isinstance(o, float):
48 return '%f' % o
49 elif isinstance(o, tuple): 43 elif isinstance(o, tuple):
50 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) 44 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o))
51 elif o is None:
52 return b'None'
53 else: 45 else:
54 raise error.ProgrammingError('do not know how to format %r' % o) 46 return pycompat.byterepr(o)
55 47
56 def binary(s): 48 def binary(s):
57 """return true if a string is binary data""" 49 """return true if a string is binary data"""
58 return bool(s and '\0' in s) 50 return bool(s and '\0' in s)
59 51