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