Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/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 _pprint_simplenamespace(self, object, stream, indent, allowance, context, level):
[344] Fix | Delete
if type(object) is _types.SimpleNamespace:
[345] Fix | Delete
# The SimpleNamespace repr is "namespace" instead of the class
[346] Fix | Delete
# name, so we do the same here. For subclasses; use the class name.
[347] Fix | Delete
cls_name = 'namespace'
[348] Fix | Delete
else:
[349] Fix | Delete
cls_name = object.__class__.__name__
[350] Fix | Delete
indent += len(cls_name) + 1
[351] Fix | Delete
delimnl = ',\n' + ' ' * indent
[352] Fix | Delete
items = object.__dict__.items()
[353] Fix | Delete
last_index = len(items) - 1
[354] Fix | Delete
[355] Fix | Delete
stream.write(cls_name + '(')
[356] Fix | Delete
for i, (key, ent) in enumerate(items):
[357] Fix | Delete
stream.write(key)
[358] Fix | Delete
stream.write('=')
[359] Fix | Delete
[360] Fix | Delete
last = i == last_index
[361] Fix | Delete
self._format(ent, stream, indent + len(key) + 1,
[362] Fix | Delete
allowance if last else 1,
[363] Fix | Delete
context, level)
[364] Fix | Delete
if not last:
[365] Fix | Delete
stream.write(delimnl)
[366] Fix | Delete
stream.write(')')
[367] Fix | Delete
[368] Fix | Delete
_dispatch[_types.SimpleNamespace.__repr__] = _pprint_simplenamespace
[369] Fix | Delete
[370] Fix | Delete
def _format_dict_items(self, items, stream, indent, allowance, context,
[371] Fix | Delete
level):
[372] Fix | Delete
write = stream.write
[373] Fix | Delete
indent += self._indent_per_level
[374] Fix | Delete
delimnl = ',\n' + ' ' * indent
[375] Fix | Delete
last_index = len(items) - 1
[376] Fix | Delete
for i, (key, ent) in enumerate(items):
[377] Fix | Delete
last = i == last_index
[378] Fix | Delete
rep = self._repr(key, context, level)
[379] Fix | Delete
write(rep)
[380] Fix | Delete
write(': ')
[381] Fix | Delete
self._format(ent, stream, indent + len(rep) + 2,
[382] Fix | Delete
allowance if last else 1,
[383] Fix | Delete
context, level)
[384] Fix | Delete
if not last:
[385] Fix | Delete
write(delimnl)
[386] Fix | Delete
[387] Fix | Delete
def _format_items(self, items, stream, indent, allowance, context, level):
[388] Fix | Delete
write = stream.write
[389] Fix | Delete
indent += self._indent_per_level
[390] Fix | Delete
if self._indent_per_level > 1:
[391] Fix | Delete
write((self._indent_per_level - 1) * ' ')
[392] Fix | Delete
delimnl = ',\n' + ' ' * indent
[393] Fix | Delete
delim = ''
[394] Fix | Delete
width = max_width = self._width - indent + 1
[395] Fix | Delete
it = iter(items)
[396] Fix | Delete
try:
[397] Fix | Delete
next_ent = next(it)
[398] Fix | Delete
except StopIteration:
[399] Fix | Delete
return
[400] Fix | Delete
last = False
[401] Fix | Delete
while not last:
[402] Fix | Delete
ent = next_ent
[403] Fix | Delete
try:
[404] Fix | Delete
next_ent = next(it)
[405] Fix | Delete
except StopIteration:
[406] Fix | Delete
last = True
[407] Fix | Delete
max_width -= allowance
[408] Fix | Delete
width -= allowance
[409] Fix | Delete
if self._compact:
[410] Fix | Delete
rep = self._repr(ent, context, level)
[411] Fix | Delete
w = len(rep) + 2
[412] Fix | Delete
if width < w:
[413] Fix | Delete
width = max_width
[414] Fix | Delete
if delim:
[415] Fix | Delete
delim = delimnl
[416] Fix | Delete
if width >= w:
[417] Fix | Delete
width -= w
[418] Fix | Delete
write(delim)
[419] Fix | Delete
delim = ', '
[420] Fix | Delete
write(rep)
[421] Fix | Delete
continue
[422] Fix | Delete
write(delim)
[423] Fix | Delete
delim = delimnl
[424] Fix | Delete
self._format(ent, stream, indent,
[425] Fix | Delete
allowance if last else 1,
[426] Fix | Delete
context, level)
[427] Fix | Delete
[428] Fix | Delete
def _repr(self, object, context, level):
[429] Fix | Delete
repr, readable, recursive = self.format(object, context.copy(),
[430] Fix | Delete
self._depth, level)
[431] Fix | Delete
if not readable:
[432] Fix | Delete
self._readable = False
[433] Fix | Delete
if recursive:
[434] Fix | Delete
self._recursive = True
[435] Fix | Delete
return repr
[436] Fix | Delete
[437] Fix | Delete
def format(self, object, context, maxlevels, level):
[438] Fix | Delete
"""Format object for a specific context, returning a string
[439] Fix | Delete
and flags indicating whether the representation is 'readable'
[440] Fix | Delete
and whether the object represents a recursive construct.
[441] Fix | Delete
"""
[442] Fix | Delete
return _safe_repr(object, context, maxlevels, level, self._sort_dicts)
[443] Fix | Delete
[444] Fix | Delete
def _pprint_default_dict(self, object, stream, indent, allowance, context, level):
[445] Fix | Delete
if not len(object):
[446] Fix | Delete
stream.write(repr(object))
[447] Fix | Delete
return
[448] Fix | Delete
rdf = self._repr(object.default_factory, context, level)
[449] Fix | Delete
cls = object.__class__
[450] Fix | Delete
indent += len(cls.__name__) + 1
[451] Fix | Delete
stream.write('%s(%s,\n%s' % (cls.__name__, rdf, ' ' * indent))
[452] Fix | Delete
self._pprint_dict(object, stream, indent, allowance + 1, context, level)
[453] Fix | Delete
stream.write(')')
[454] Fix | Delete
[455] Fix | Delete
_dispatch[_collections.defaultdict.__repr__] = _pprint_default_dict
[456] Fix | Delete
[457] Fix | Delete
def _pprint_counter(self, object, stream, indent, allowance, context, level):
[458] Fix | Delete
if not len(object):
[459] Fix | Delete
stream.write(repr(object))
[460] Fix | Delete
return
[461] Fix | Delete
cls = object.__class__
[462] Fix | Delete
stream.write(cls.__name__ + '({')
[463] Fix | Delete
if self._indent_per_level > 1:
[464] Fix | Delete
stream.write((self._indent_per_level - 1) * ' ')
[465] Fix | Delete
items = object.most_common()
[466] Fix | Delete
self._format_dict_items(items, stream,
[467] Fix | Delete
indent + len(cls.__name__) + 1, allowance + 2,
[468] Fix | Delete
context, level)
[469] Fix | Delete
stream.write('})')
[470] Fix | Delete
[471] Fix | Delete
_dispatch[_collections.Counter.__repr__] = _pprint_counter
[472] Fix | Delete
[473] Fix | Delete
def _pprint_chain_map(self, object, stream, indent, allowance, context, level):
[474] Fix | Delete
if not len(object.maps):
[475] Fix | Delete
stream.write(repr(object))
[476] Fix | Delete
return
[477] Fix | Delete
cls = object.__class__
[478] Fix | Delete
stream.write(cls.__name__ + '(')
[479] Fix | Delete
indent += len(cls.__name__) + 1
[480] Fix | Delete
for i, m in enumerate(object.maps):
[481] Fix | Delete
if i == len(object.maps) - 1:
[482] Fix | Delete
self._format(m, stream, indent, allowance + 1, context, level)
[483] Fix | Delete
stream.write(')')
[484] Fix | Delete
else:
[485] Fix | Delete
self._format(m, stream, indent, 1, context, level)
[486] Fix | Delete
stream.write(',\n' + ' ' * indent)
[487] Fix | Delete
[488] Fix | Delete
_dispatch[_collections.ChainMap.__repr__] = _pprint_chain_map
[489] Fix | Delete
[490] Fix | Delete
def _pprint_deque(self, object, stream, indent, allowance, context, level):
[491] Fix | Delete
if not len(object):
[492] Fix | Delete
stream.write(repr(object))
[493] Fix | Delete
return
[494] Fix | Delete
cls = object.__class__
[495] Fix | Delete
stream.write(cls.__name__ + '(')
[496] Fix | Delete
indent += len(cls.__name__) + 1
[497] Fix | Delete
stream.write('[')
[498] Fix | Delete
if object.maxlen is None:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function