Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: pprint.py
# Author: Fred L. Drake, Jr.
[0] Fix | Delete
# fdrake@acm.org
[1] Fix | Delete
#
[2] Fix | Delete
# This is a simple little module I wrote to make life easier. I didn't
[3] Fix | Delete
# see anything quite like it in the library, though I may have overlooked
[4] Fix | Delete
# something. I wrote this when I was trying to read some heavily nested
[5] Fix | Delete
# tuples with fairly non-descriptive content. This is modeled very much
[6] Fix | Delete
# after Lisp/Scheme - style pretty-printing of lists. If you find it
[7] Fix | Delete
# useful, thank small children who sleep at night.
[8] Fix | Delete
[9] Fix | Delete
"""Support to pretty-print lists, tuples, & dictionaries recursively.
[10] Fix | Delete
[11] Fix | Delete
Very simple, but useful, especially in debugging data structures.
[12] Fix | Delete
[13] Fix | Delete
Classes
[14] Fix | Delete
-------
[15] Fix | Delete
[16] Fix | Delete
PrettyPrinter()
[17] Fix | Delete
Handle pretty-printing operations onto a stream using a configured
[18] Fix | Delete
set of formatting parameters.
[19] Fix | Delete
[20] Fix | Delete
Functions
[21] Fix | Delete
---------
[22] Fix | Delete
[23] Fix | Delete
pformat()
[24] Fix | Delete
Format a Python object into a pretty-printed representation.
[25] Fix | Delete
[26] Fix | Delete
pprint()
[27] Fix | Delete
Pretty-print a Python object to a stream [default is sys.stdout].
[28] Fix | Delete
[29] Fix | Delete
saferepr()
[30] Fix | Delete
Generate a 'standard' repr()-like value, but protect against recursive
[31] Fix | Delete
data structures.
[32] Fix | Delete
[33] Fix | Delete
"""
[34] Fix | Delete
[35] Fix | Delete
import collections as _collections
[36] Fix | Delete
import re
[37] Fix | Delete
import sys as _sys
[38] Fix | Delete
import types as _types
[39] Fix | Delete
from io import StringIO as _StringIO
[40] Fix | Delete
[41] Fix | Delete
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
[42] Fix | Delete
"PrettyPrinter"]
[43] Fix | Delete
[44] Fix | Delete
[45] Fix | Delete
def pprint(object, stream=None, indent=1, width=80, depth=None, *,
[46] Fix | Delete
compact=False):
[47] Fix | Delete
"""Pretty-print a Python object to a stream [default is sys.stdout]."""
[48] Fix | Delete
printer = PrettyPrinter(
[49] Fix | Delete
stream=stream, indent=indent, width=width, depth=depth,
[50] Fix | Delete
compact=compact)
[51] Fix | Delete
printer.pprint(object)
[52] Fix | Delete
[53] Fix | Delete
def pformat(object, indent=1, width=80, depth=None, *, compact=False):
[54] Fix | Delete
"""Format a Python object into a pretty-printed representation."""
[55] Fix | Delete
return PrettyPrinter(indent=indent, width=width, depth=depth,
[56] Fix | Delete
compact=compact).pformat(object)
[57] Fix | Delete
[58] Fix | Delete
def saferepr(object):
[59] Fix | Delete
"""Version of repr() which can handle recursive data structures."""
[60] Fix | Delete
return _safe_repr(object, {}, None, 0)[0]
[61] Fix | Delete
[62] Fix | Delete
def isreadable(object):
[63] Fix | Delete
"""Determine if saferepr(object) is readable by eval()."""
[64] Fix | Delete
return _safe_repr(object, {}, None, 0)[1]
[65] Fix | Delete
[66] Fix | Delete
def isrecursive(object):
[67] Fix | Delete
"""Determine if object requires a recursive representation."""
[68] Fix | Delete
return _safe_repr(object, {}, None, 0)[2]
[69] Fix | Delete
[70] Fix | Delete
class _safe_key:
[71] Fix | Delete
"""Helper function for key functions when sorting unorderable objects.
[72] Fix | Delete
[73] Fix | Delete
The wrapped-object will fallback to a Py2.x style comparison for
[74] Fix | Delete
unorderable types (sorting first comparing the type name and then by
[75] Fix | Delete
the obj ids). Does not work recursively, so dict.items() must have
[76] Fix | Delete
_safe_key applied to both the key and the value.
[77] Fix | Delete
[78] Fix | Delete
"""
[79] Fix | Delete
[80] Fix | Delete
__slots__ = ['obj']
[81] Fix | Delete
[82] Fix | Delete
def __init__(self, obj):
[83] Fix | Delete
self.obj = obj
[84] Fix | Delete
[85] Fix | Delete
def __lt__(self, other):
[86] Fix | Delete
try:
[87] Fix | Delete
return self.obj < other.obj
[88] Fix | Delete
except TypeError:
[89] Fix | Delete
return ((str(type(self.obj)), id(self.obj)) < \
[90] Fix | Delete
(str(type(other.obj)), id(other.obj)))
[91] Fix | Delete
[92] Fix | Delete
def _safe_tuple(t):
[93] Fix | Delete
"Helper function for comparing 2-tuples"
[94] Fix | Delete
return _safe_key(t[0]), _safe_key(t[1])
[95] Fix | Delete
[96] Fix | Delete
class PrettyPrinter:
[97] Fix | Delete
def __init__(self, indent=1, width=80, depth=None, stream=None, *,
[98] Fix | Delete
compact=False):
[99] Fix | Delete
"""Handle pretty printing operations onto a stream using a set of
[100] Fix | Delete
configured parameters.
[101] Fix | Delete
[102] Fix | Delete
indent
[103] Fix | Delete
Number of spaces to indent for each level of nesting.
[104] Fix | Delete
[105] Fix | Delete
width
[106] Fix | Delete
Attempted maximum number of columns in the output.
[107] Fix | Delete
[108] Fix | Delete
depth
[109] Fix | Delete
The maximum depth to print out nested structures.
[110] Fix | Delete
[111] Fix | Delete
stream
[112] Fix | Delete
The desired output stream. If omitted (or false), the standard
[113] Fix | Delete
output stream available at construction will be used.
[114] Fix | Delete
[115] Fix | Delete
compact
[116] Fix | Delete
If true, several items will be combined in one line.
[117] Fix | Delete
[118] Fix | Delete
"""
[119] Fix | Delete
indent = int(indent)
[120] Fix | Delete
width = int(width)
[121] Fix | Delete
if indent < 0:
[122] Fix | Delete
raise ValueError('indent must be >= 0')
[123] Fix | Delete
if depth is not None and depth <= 0:
[124] Fix | Delete
raise ValueError('depth must be > 0')
[125] Fix | Delete
if not width:
[126] Fix | Delete
raise ValueError('width must be != 0')
[127] Fix | Delete
self._depth = depth
[128] Fix | Delete
self._indent_per_level = indent
[129] Fix | Delete
self._width = width
[130] Fix | Delete
if stream is not None:
[131] Fix | Delete
self._stream = stream
[132] Fix | Delete
else:
[133] Fix | Delete
self._stream = _sys.stdout
[134] Fix | Delete
self._compact = bool(compact)
[135] Fix | Delete
[136] Fix | Delete
def pprint(self, object):
[137] Fix | Delete
self._format(object, self._stream, 0, 0, {}, 0)
[138] Fix | Delete
self._stream.write("\n")
[139] Fix | Delete
[140] Fix | Delete
def pformat(self, object):
[141] Fix | Delete
sio = _StringIO()
[142] Fix | Delete
self._format(object, sio, 0, 0, {}, 0)
[143] Fix | Delete
return sio.getvalue()
[144] Fix | Delete
[145] Fix | Delete
def isrecursive(self, object):
[146] Fix | Delete
return self.format(object, {}, 0, 0)[2]
[147] Fix | Delete
[148] Fix | Delete
def isreadable(self, object):
[149] Fix | Delete
s, readable, recursive = self.format(object, {}, 0, 0)
[150] Fix | Delete
return readable and not recursive
[151] Fix | Delete
[152] Fix | Delete
def _format(self, object, stream, indent, allowance, context, level):
[153] Fix | Delete
objid = id(object)
[154] Fix | Delete
if objid in context:
[155] Fix | Delete
stream.write(_recursion(object))
[156] Fix | Delete
self._recursive = True
[157] Fix | Delete
self._readable = False
[158] Fix | Delete
return
[159] Fix | Delete
rep = self._repr(object, context, level)
[160] Fix | Delete
max_width = self._width - indent - allowance
[161] Fix | Delete
if len(rep) > max_width:
[162] Fix | Delete
p = self._dispatch.get(type(object).__repr__, None)
[163] Fix | Delete
if p is not None:
[164] Fix | Delete
context[objid] = 1
[165] Fix | Delete
p(self, object, stream, indent, allowance, context, level + 1)
[166] Fix | Delete
del context[objid]
[167] Fix | Delete
return
[168] Fix | Delete
elif isinstance(object, dict):
[169] Fix | Delete
context[objid] = 1
[170] Fix | Delete
self._pprint_dict(object, stream, indent, allowance,
[171] Fix | Delete
context, level + 1)
[172] Fix | Delete
del context[objid]
[173] Fix | Delete
return
[174] Fix | Delete
stream.write(rep)
[175] Fix | Delete
[176] Fix | Delete
_dispatch = {}
[177] Fix | Delete
[178] Fix | Delete
def _pprint_dict(self, object, stream, indent, allowance, context, level):
[179] Fix | Delete
write = stream.write
[180] Fix | Delete
write('{')
[181] Fix | Delete
if self._indent_per_level > 1:
[182] Fix | Delete
write((self._indent_per_level - 1) * ' ')
[183] Fix | Delete
length = len(object)
[184] Fix | Delete
if length:
[185] Fix | Delete
items = sorted(object.items(), key=_safe_tuple)
[186] Fix | Delete
self._format_dict_items(items, stream, indent, allowance + 1,
[187] Fix | Delete
context, level)
[188] Fix | Delete
write('}')
[189] Fix | Delete
[190] Fix | Delete
_dispatch[dict.__repr__] = _pprint_dict
[191] Fix | Delete
[192] Fix | Delete
def _pprint_ordered_dict(self, object, stream, indent, allowance, context, level):
[193] Fix | Delete
if not len(object):
[194] Fix | Delete
stream.write(repr(object))
[195] Fix | Delete
return
[196] Fix | Delete
cls = object.__class__
[197] Fix | Delete
stream.write(cls.__name__ + '(')
[198] Fix | Delete
self._format(list(object.items()), stream,
[199] Fix | Delete
indent + len(cls.__name__) + 1, allowance + 1,
[200] Fix | Delete
context, level)
[201] Fix | Delete
stream.write(')')
[202] Fix | Delete
[203] Fix | Delete
_dispatch[_collections.OrderedDict.__repr__] = _pprint_ordered_dict
[204] Fix | Delete
[205] Fix | Delete
def _pprint_list(self, object, stream, indent, allowance, context, level):
[206] Fix | Delete
stream.write('[')
[207] Fix | Delete
self._format_items(object, stream, indent, allowance + 1,
[208] Fix | Delete
context, level)
[209] Fix | Delete
stream.write(']')
[210] Fix | Delete
[211] Fix | Delete
_dispatch[list.__repr__] = _pprint_list
[212] Fix | Delete
[213] Fix | Delete
def _pprint_tuple(self, object, stream, indent, allowance, context, level):
[214] Fix | Delete
stream.write('(')
[215] Fix | Delete
endchar = ',)' if len(object) == 1 else ')'
[216] Fix | Delete
self._format_items(object, stream, indent, allowance + len(endchar),
[217] Fix | Delete
context, level)
[218] Fix | Delete
stream.write(endchar)
[219] Fix | Delete
[220] Fix | Delete
_dispatch[tuple.__repr__] = _pprint_tuple
[221] Fix | Delete
[222] Fix | Delete
def _pprint_set(self, object, stream, indent, allowance, context, level):
[223] Fix | Delete
if not len(object):
[224] Fix | Delete
stream.write(repr(object))
[225] Fix | Delete
return
[226] Fix | Delete
typ = object.__class__
[227] Fix | Delete
if typ is set:
[228] Fix | Delete
stream.write('{')
[229] Fix | Delete
endchar = '}'
[230] Fix | Delete
else:
[231] Fix | Delete
stream.write(typ.__name__ + '({')
[232] Fix | Delete
endchar = '})'
[233] Fix | Delete
indent += len(typ.__name__) + 1
[234] Fix | Delete
object = sorted(object, key=_safe_key)
[235] Fix | Delete
self._format_items(object, stream, indent, allowance + len(endchar),
[236] Fix | Delete
context, level)
[237] Fix | Delete
stream.write(endchar)
[238] Fix | Delete
[239] Fix | Delete
_dispatch[set.__repr__] = _pprint_set
[240] Fix | Delete
_dispatch[frozenset.__repr__] = _pprint_set
[241] Fix | Delete
[242] Fix | Delete
def _pprint_str(self, object, stream, indent, allowance, context, level):
[243] Fix | Delete
write = stream.write
[244] Fix | Delete
if not len(object):
[245] Fix | Delete
write(repr(object))
[246] Fix | Delete
return
[247] Fix | Delete
chunks = []
[248] Fix | Delete
lines = object.splitlines(True)
[249] Fix | Delete
if level == 1:
[250] Fix | Delete
indent += 1
[251] Fix | Delete
allowance += 1
[252] Fix | Delete
max_width1 = max_width = self._width - indent
[253] Fix | Delete
for i, line in enumerate(lines):
[254] Fix | Delete
rep = repr(line)
[255] Fix | Delete
if i == len(lines) - 1:
[256] Fix | Delete
max_width1 -= allowance
[257] Fix | Delete
if len(rep) <= max_width1:
[258] Fix | Delete
chunks.append(rep)
[259] Fix | Delete
else:
[260] Fix | Delete
# A list of alternating (non-space, space) strings
[261] Fix | Delete
parts = re.findall(r'\S*\s*', line)
[262] Fix | Delete
assert parts
[263] Fix | Delete
assert not parts[-1]
[264] Fix | Delete
parts.pop() # drop empty last part
[265] Fix | Delete
max_width2 = max_width
[266] Fix | Delete
current = ''
[267] Fix | Delete
for j, part in enumerate(parts):
[268] Fix | Delete
candidate = current + part
[269] Fix | Delete
if j == len(parts) - 1 and i == len(lines) - 1:
[270] Fix | Delete
max_width2 -= allowance
[271] Fix | Delete
if len(repr(candidate)) > max_width2:
[272] Fix | Delete
if current:
[273] Fix | Delete
chunks.append(repr(current))
[274] Fix | Delete
current = part
[275] Fix | Delete
else:
[276] Fix | Delete
current = candidate
[277] Fix | Delete
if current:
[278] Fix | Delete
chunks.append(repr(current))
[279] Fix | Delete
if len(chunks) == 1:
[280] Fix | Delete
write(rep)
[281] Fix | Delete
return
[282] Fix | Delete
if level == 1:
[283] Fix | Delete
write('(')
[284] Fix | Delete
for i, rep in enumerate(chunks):
[285] Fix | Delete
if i > 0:
[286] Fix | Delete
write('\n' + ' '*indent)
[287] Fix | Delete
write(rep)
[288] Fix | Delete
if level == 1:
[289] Fix | Delete
write(')')
[290] Fix | Delete
[291] Fix | Delete
_dispatch[str.__repr__] = _pprint_str
[292] Fix | Delete
[293] Fix | Delete
def _pprint_bytes(self, object, stream, indent, allowance, context, level):
[294] Fix | Delete
write = stream.write
[295] Fix | Delete
if len(object) <= 4:
[296] Fix | Delete
write(repr(object))
[297] Fix | Delete
return
[298] Fix | Delete
parens = level == 1
[299] Fix | Delete
if parens:
[300] Fix | Delete
indent += 1
[301] Fix | Delete
allowance += 1
[302] Fix | Delete
write('(')
[303] Fix | Delete
delim = ''
[304] Fix | Delete
for rep in _wrap_bytes_repr(object, self._width - indent, allowance):
[305] Fix | Delete
write(delim)
[306] Fix | Delete
write(rep)
[307] Fix | Delete
if not delim:
[308] Fix | Delete
delim = '\n' + ' '*indent
[309] Fix | Delete
if parens:
[310] Fix | Delete
write(')')
[311] Fix | Delete
[312] Fix | Delete
_dispatch[bytes.__repr__] = _pprint_bytes
[313] Fix | Delete
[314] Fix | Delete
def _pprint_bytearray(self, object, stream, indent, allowance, context, level):
[315] Fix | Delete
write = stream.write
[316] Fix | Delete
write('bytearray(')
[317] Fix | Delete
self._pprint_bytes(bytes(object), stream, indent + 10,
[318] Fix | Delete
allowance + 1, context, level + 1)
[319] Fix | Delete
write(')')
[320] Fix | Delete
[321] Fix | Delete
_dispatch[bytearray.__repr__] = _pprint_bytearray
[322] Fix | Delete
[323] Fix | Delete
def _pprint_mappingproxy(self, object, stream, indent, allowance, context, level):
[324] Fix | Delete
stream.write('mappingproxy(')
[325] Fix | Delete
self._format(object.copy(), stream, indent + 13, allowance + 1,
[326] Fix | Delete
context, level)
[327] Fix | Delete
stream.write(')')
[328] Fix | Delete
[329] Fix | Delete
_dispatch[_types.MappingProxyType.__repr__] = _pprint_mappingproxy
[330] Fix | Delete
[331] Fix | Delete
def _format_dict_items(self, items, stream, indent, allowance, context,
[332] Fix | Delete
level):
[333] Fix | Delete
write = stream.write
[334] Fix | Delete
indent += self._indent_per_level
[335] Fix | Delete
delimnl = ',\n' + ' ' * indent
[336] Fix | Delete
last_index = len(items) - 1
[337] Fix | Delete
for i, (key, ent) in enumerate(items):
[338] Fix | Delete
last = i == last_index
[339] Fix | Delete
rep = self._repr(key, context, level)
[340] Fix | Delete
write(rep)
[341] Fix | Delete
write(': ')
[342] Fix | Delete
self._format(ent, stream, indent + len(rep) + 2,
[343] Fix | Delete
allowance if last else 1,
[344] Fix | Delete
context, level)
[345] Fix | Delete
if not last:
[346] Fix | Delete
write(delimnl)
[347] Fix | Delete
[348] Fix | Delete
def _format_items(self, items, stream, indent, allowance, context, level):
[349] Fix | Delete
write = stream.write
[350] Fix | Delete
indent += self._indent_per_level
[351] Fix | Delete
if self._indent_per_level > 1:
[352] Fix | Delete
write((self._indent_per_level - 1) * ' ')
[353] Fix | Delete
delimnl = ',\n' + ' ' * indent
[354] Fix | Delete
delim = ''
[355] Fix | Delete
width = max_width = self._width - indent + 1
[356] Fix | Delete
it = iter(items)
[357] Fix | Delete
try:
[358] Fix | Delete
next_ent = next(it)
[359] Fix | Delete
except StopIteration:
[360] Fix | Delete
return
[361] Fix | Delete
last = False
[362] Fix | Delete
while not last:
[363] Fix | Delete
ent = next_ent
[364] Fix | Delete
try:
[365] Fix | Delete
next_ent = next(it)
[366] Fix | Delete
except StopIteration:
[367] Fix | Delete
last = True
[368] Fix | Delete
max_width -= allowance
[369] Fix | Delete
width -= allowance
[370] Fix | Delete
if self._compact:
[371] Fix | Delete
rep = self._repr(ent, context, level)
[372] Fix | Delete
w = len(rep) + 2
[373] Fix | Delete
if width < w:
[374] Fix | Delete
width = max_width
[375] Fix | Delete
if delim:
[376] Fix | Delete
delim = delimnl
[377] Fix | Delete
if width >= w:
[378] Fix | Delete
width -= w
[379] Fix | Delete
write(delim)
[380] Fix | Delete
delim = ', '
[381] Fix | Delete
write(rep)
[382] Fix | Delete
continue
[383] Fix | Delete
write(delim)
[384] Fix | Delete
delim = delimnl
[385] Fix | Delete
self._format(ent, stream, indent,
[386] Fix | Delete
allowance if last else 1,
[387] Fix | Delete
context, level)
[388] Fix | Delete
[389] Fix | Delete
def _repr(self, object, context, level):
[390] Fix | Delete
repr, readable, recursive = self.format(object, context.copy(),
[391] Fix | Delete
self._depth, level)
[392] Fix | Delete
if not readable:
[393] Fix | Delete
self._readable = False
[394] Fix | Delete
if recursive:
[395] Fix | Delete
self._recursive = True
[396] Fix | Delete
return repr
[397] Fix | Delete
[398] Fix | Delete
def format(self, object, context, maxlevels, level):
[399] Fix | Delete
"""Format object for a specific context, returning a string
[400] Fix | Delete
and flags indicating whether the representation is 'readable'
[401] Fix | Delete
and whether the object represents a recursive construct.
[402] Fix | Delete
"""
[403] Fix | Delete
return _safe_repr(object, context, maxlevels, level)
[404] Fix | Delete
[405] Fix | Delete
def _pprint_default_dict(self, object, stream, indent, allowance, context, level):
[406] Fix | Delete
if not len(object):
[407] Fix | Delete
stream.write(repr(object))
[408] Fix | Delete
return
[409] Fix | Delete
rdf = self._repr(object.default_factory, context, level)
[410] Fix | Delete
cls = object.__class__
[411] Fix | Delete
indent += len(cls.__name__) + 1
[412] Fix | Delete
stream.write('%s(%s,\n%s' % (cls.__name__, rdf, ' ' * indent))
[413] Fix | Delete
self._pprint_dict(object, stream, indent, allowance + 1, context, level)
[414] Fix | Delete
stream.write(')')
[415] Fix | Delete
[416] Fix | Delete
_dispatch[_collections.defaultdict.__repr__] = _pprint_default_dict
[417] Fix | Delete
[418] Fix | Delete
def _pprint_counter(self, object, stream, indent, allowance, context, level):
[419] Fix | Delete
if not len(object):
[420] Fix | Delete
stream.write(repr(object))
[421] Fix | Delete
return
[422] Fix | Delete
cls = object.__class__
[423] Fix | Delete
stream.write(cls.__name__ + '({')
[424] Fix | Delete
if self._indent_per_level > 1:
[425] Fix | Delete
stream.write((self._indent_per_level - 1) * ' ')
[426] Fix | Delete
items = object.most_common()
[427] Fix | Delete
self._format_dict_items(items, stream,
[428] Fix | Delete
indent + len(cls.__name__) + 1, allowance + 2,
[429] Fix | Delete
context, level)
[430] Fix | Delete
stream.write('})')
[431] Fix | Delete
[432] Fix | Delete
_dispatch[_collections.Counter.__repr__] = _pprint_counter
[433] Fix | Delete
[434] Fix | Delete
def _pprint_chain_map(self, object, stream, indent, allowance, context, level):
[435] Fix | Delete
if not len(object.maps):
[436] Fix | Delete
stream.write(repr(object))
[437] Fix | Delete
return
[438] Fix | Delete
cls = object.__class__
[439] Fix | Delete
stream.write(cls.__name__ + '(')
[440] Fix | Delete
indent += len(cls.__name__) + 1
[441] Fix | Delete
for i, m in enumerate(object.maps):
[442] Fix | Delete
if i == len(object.maps) - 1:
[443] Fix | Delete
self._format(m, stream, indent, allowance + 1, context, level)
[444] Fix | Delete
stream.write(')')
[445] Fix | Delete
else:
[446] Fix | Delete
self._format(m, stream, indent, 1, context, level)
[447] Fix | Delete
stream.write(',\n' + ' ' * indent)
[448] Fix | Delete
[449] Fix | Delete
_dispatch[_collections.ChainMap.__repr__] = _pprint_chain_map
[450] Fix | Delete
[451] Fix | Delete
def _pprint_deque(self, object, stream, indent, allowance, context, level):
[452] Fix | Delete
if not len(object):
[453] Fix | Delete
stream.write(repr(object))
[454] Fix | Delete
return
[455] Fix | Delete
cls = object.__class__
[456] Fix | Delete
stream.write(cls.__name__ + '(')
[457] Fix | Delete
indent += len(cls.__name__) + 1
[458] Fix | Delete
stream.write('[')
[459] Fix | Delete
if object.maxlen is None:
[460] Fix | Delete
self._format_items(object, stream, indent, allowance + 2,
[461] Fix | Delete
context, level)
[462] Fix | Delete
stream.write('])')
[463] Fix | Delete
else:
[464] Fix | Delete
self._format_items(object, stream, indent, 2,
[465] Fix | Delete
context, level)
[466] Fix | Delete
rml = self._repr(object.maxlen, context, level)
[467] Fix | Delete
stream.write('],\n%smaxlen=%s)' % (' ' * indent, rml))
[468] Fix | Delete
[469] Fix | Delete
_dispatch[_collections.deque.__repr__] = _pprint_deque
[470] Fix | Delete
[471] Fix | Delete
def _pprint_user_dict(self, object, stream, indent, allowance, context, level):
[472] Fix | Delete
self._format(object.data, stream, indent, allowance, context, level - 1)
[473] Fix | Delete
[474] Fix | Delete
_dispatch[_collections.UserDict.__repr__] = _pprint_user_dict
[475] Fix | Delete
[476] Fix | Delete
def _pprint_user_list(self, object, stream, indent, allowance, context, level):
[477] Fix | Delete
self._format(object.data, stream, indent, allowance, context, level - 1)
[478] Fix | Delete
[479] Fix | Delete
_dispatch[_collections.UserList.__repr__] = _pprint_user_list
[480] Fix | Delete
[481] Fix | Delete
def _pprint_user_string(self, object, stream, indent, allowance, context, level):
[482] Fix | Delete
self._format(object.data, stream, indent, allowance, context, level - 1)
[483] Fix | Delete
[484] Fix | Delete
_dispatch[_collections.UserString.__repr__] = _pprint_user_string
[485] Fix | Delete
[486] Fix | Delete
# Return triple (repr_string, isreadable, isrecursive).
[487] Fix | Delete
[488] Fix | Delete
def _safe_repr(object, context, maxlevels, level):
[489] Fix | Delete
typ = type(object)
[490] Fix | Delete
if typ in _builtin_scalars:
[491] Fix | Delete
return repr(object), True, False
[492] Fix | Delete
[493] Fix | Delete
r = getattr(typ, "__repr__", None)
[494] Fix | Delete
if issubclass(typ, dict) and r is dict.__repr__:
[495] Fix | Delete
if not object:
[496] Fix | Delete
return "{}", True, False
[497] Fix | Delete
objid = id(object)
[498] Fix | Delete
if maxlevels and level >= maxlevels:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function