Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: reprlib.py
"""Redo the builtin repr() (representation) but with limits on most sizes."""
[0] Fix | Delete
[1] Fix | Delete
__all__ = ["Repr", "repr", "recursive_repr"]
[2] Fix | Delete
[3] Fix | Delete
import builtins
[4] Fix | Delete
from itertools import islice
[5] Fix | Delete
try:
[6] Fix | Delete
from _thread import get_ident
[7] Fix | Delete
except ImportError:
[8] Fix | Delete
from _dummy_thread import get_ident
[9] Fix | Delete
[10] Fix | Delete
def recursive_repr(fillvalue='...'):
[11] Fix | Delete
'Decorator to make a repr function return fillvalue for a recursive call'
[12] Fix | Delete
[13] Fix | Delete
def decorating_function(user_function):
[14] Fix | Delete
repr_running = set()
[15] Fix | Delete
[16] Fix | Delete
def wrapper(self):
[17] Fix | Delete
key = id(self), get_ident()
[18] Fix | Delete
if key in repr_running:
[19] Fix | Delete
return fillvalue
[20] Fix | Delete
repr_running.add(key)
[21] Fix | Delete
try:
[22] Fix | Delete
result = user_function(self)
[23] Fix | Delete
finally:
[24] Fix | Delete
repr_running.discard(key)
[25] Fix | Delete
return result
[26] Fix | Delete
[27] Fix | Delete
# Can't use functools.wraps() here because of bootstrap issues
[28] Fix | Delete
wrapper.__module__ = getattr(user_function, '__module__')
[29] Fix | Delete
wrapper.__doc__ = getattr(user_function, '__doc__')
[30] Fix | Delete
wrapper.__name__ = getattr(user_function, '__name__')
[31] Fix | Delete
wrapper.__qualname__ = getattr(user_function, '__qualname__')
[32] Fix | Delete
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
[33] Fix | Delete
return wrapper
[34] Fix | Delete
[35] Fix | Delete
return decorating_function
[36] Fix | Delete
[37] Fix | Delete
class Repr:
[38] Fix | Delete
[39] Fix | Delete
def __init__(self):
[40] Fix | Delete
self.maxlevel = 6
[41] Fix | Delete
self.maxtuple = 6
[42] Fix | Delete
self.maxlist = 6
[43] Fix | Delete
self.maxarray = 5
[44] Fix | Delete
self.maxdict = 4
[45] Fix | Delete
self.maxset = 6
[46] Fix | Delete
self.maxfrozenset = 6
[47] Fix | Delete
self.maxdeque = 6
[48] Fix | Delete
self.maxstring = 30
[49] Fix | Delete
self.maxlong = 40
[50] Fix | Delete
self.maxother = 30
[51] Fix | Delete
[52] Fix | Delete
def repr(self, x):
[53] Fix | Delete
return self.repr1(x, self.maxlevel)
[54] Fix | Delete
[55] Fix | Delete
def repr1(self, x, level):
[56] Fix | Delete
typename = type(x).__name__
[57] Fix | Delete
if ' ' in typename:
[58] Fix | Delete
parts = typename.split()
[59] Fix | Delete
typename = '_'.join(parts)
[60] Fix | Delete
if hasattr(self, 'repr_' + typename):
[61] Fix | Delete
return getattr(self, 'repr_' + typename)(x, level)
[62] Fix | Delete
else:
[63] Fix | Delete
return self.repr_instance(x, level)
[64] Fix | Delete
[65] Fix | Delete
def _repr_iterable(self, x, level, left, right, maxiter, trail=''):
[66] Fix | Delete
n = len(x)
[67] Fix | Delete
if level <= 0 and n:
[68] Fix | Delete
s = '...'
[69] Fix | Delete
else:
[70] Fix | Delete
newlevel = level - 1
[71] Fix | Delete
repr1 = self.repr1
[72] Fix | Delete
pieces = [repr1(elem, newlevel) for elem in islice(x, maxiter)]
[73] Fix | Delete
if n > maxiter: pieces.append('...')
[74] Fix | Delete
s = ', '.join(pieces)
[75] Fix | Delete
if n == 1 and trail: right = trail + right
[76] Fix | Delete
return '%s%s%s' % (left, s, right)
[77] Fix | Delete
[78] Fix | Delete
def repr_tuple(self, x, level):
[79] Fix | Delete
return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',')
[80] Fix | Delete
[81] Fix | Delete
def repr_list(self, x, level):
[82] Fix | Delete
return self._repr_iterable(x, level, '[', ']', self.maxlist)
[83] Fix | Delete
[84] Fix | Delete
def repr_array(self, x, level):
[85] Fix | Delete
if not x:
[86] Fix | Delete
return "array('%s')" % x.typecode
[87] Fix | Delete
header = "array('%s', [" % x.typecode
[88] Fix | Delete
return self._repr_iterable(x, level, header, '])', self.maxarray)
[89] Fix | Delete
[90] Fix | Delete
def repr_set(self, x, level):
[91] Fix | Delete
if not x:
[92] Fix | Delete
return 'set()'
[93] Fix | Delete
x = _possibly_sorted(x)
[94] Fix | Delete
return self._repr_iterable(x, level, '{', '}', self.maxset)
[95] Fix | Delete
[96] Fix | Delete
def repr_frozenset(self, x, level):
[97] Fix | Delete
if not x:
[98] Fix | Delete
return 'frozenset()'
[99] Fix | Delete
x = _possibly_sorted(x)
[100] Fix | Delete
return self._repr_iterable(x, level, 'frozenset({', '})',
[101] Fix | Delete
self.maxfrozenset)
[102] Fix | Delete
[103] Fix | Delete
def repr_deque(self, x, level):
[104] Fix | Delete
return self._repr_iterable(x, level, 'deque([', '])', self.maxdeque)
[105] Fix | Delete
[106] Fix | Delete
def repr_dict(self, x, level):
[107] Fix | Delete
n = len(x)
[108] Fix | Delete
if n == 0: return '{}'
[109] Fix | Delete
if level <= 0: return '{...}'
[110] Fix | Delete
newlevel = level - 1
[111] Fix | Delete
repr1 = self.repr1
[112] Fix | Delete
pieces = []
[113] Fix | Delete
for key in islice(_possibly_sorted(x), self.maxdict):
[114] Fix | Delete
keyrepr = repr1(key, newlevel)
[115] Fix | Delete
valrepr = repr1(x[key], newlevel)
[116] Fix | Delete
pieces.append('%s: %s' % (keyrepr, valrepr))
[117] Fix | Delete
if n > self.maxdict: pieces.append('...')
[118] Fix | Delete
s = ', '.join(pieces)
[119] Fix | Delete
return '{%s}' % (s,)
[120] Fix | Delete
[121] Fix | Delete
def repr_str(self, x, level):
[122] Fix | Delete
s = builtins.repr(x[:self.maxstring])
[123] Fix | Delete
if len(s) > self.maxstring:
[124] Fix | Delete
i = max(0, (self.maxstring-3)//2)
[125] Fix | Delete
j = max(0, self.maxstring-3-i)
[126] Fix | Delete
s = builtins.repr(x[:i] + x[len(x)-j:])
[127] Fix | Delete
s = s[:i] + '...' + s[len(s)-j:]
[128] Fix | Delete
return s
[129] Fix | Delete
[130] Fix | Delete
def repr_int(self, x, level):
[131] Fix | Delete
s = builtins.repr(x) # XXX Hope this isn't too slow...
[132] Fix | Delete
if len(s) > self.maxlong:
[133] Fix | Delete
i = max(0, (self.maxlong-3)//2)
[134] Fix | Delete
j = max(0, self.maxlong-3-i)
[135] Fix | Delete
s = s[:i] + '...' + s[len(s)-j:]
[136] Fix | Delete
return s
[137] Fix | Delete
[138] Fix | Delete
def repr_instance(self, x, level):
[139] Fix | Delete
try:
[140] Fix | Delete
s = builtins.repr(x)
[141] Fix | Delete
# Bugs in x.__repr__() can cause arbitrary
[142] Fix | Delete
# exceptions -- then make up something
[143] Fix | Delete
except Exception:
[144] Fix | Delete
return '<%s instance at %#x>' % (x.__class__.__name__, id(x))
[145] Fix | Delete
if len(s) > self.maxother:
[146] Fix | Delete
i = max(0, (self.maxother-3)//2)
[147] Fix | Delete
j = max(0, self.maxother-3-i)
[148] Fix | Delete
s = s[:i] + '...' + s[len(s)-j:]
[149] Fix | Delete
return s
[150] Fix | Delete
[151] Fix | Delete
[152] Fix | Delete
def _possibly_sorted(x):
[153] Fix | Delete
# Since not all sequences of items can be sorted and comparison
[154] Fix | Delete
# functions may raise arbitrary exceptions, return an unsorted
[155] Fix | Delete
# sequence in that case.
[156] Fix | Delete
try:
[157] Fix | Delete
return sorted(x)
[158] Fix | Delete
except Exception:
[159] Fix | Delete
return list(x)
[160] Fix | Delete
[161] Fix | Delete
aRepr = Repr()
[162] Fix | Delete
repr = aRepr.repr
[163] Fix | Delete
[164] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function