Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: copyreg.py
"""Helper to provide extensibility for pickle.
[0] Fix | Delete
[1] Fix | Delete
This is only useful to add pickle support for extension types defined in
[2] Fix | Delete
C, not for instances of user-defined classes.
[3] Fix | Delete
"""
[4] Fix | Delete
[5] Fix | Delete
__all__ = ["pickle", "constructor",
[6] Fix | Delete
"add_extension", "remove_extension", "clear_extension_cache"]
[7] Fix | Delete
[8] Fix | Delete
dispatch_table = {}
[9] Fix | Delete
[10] Fix | Delete
def pickle(ob_type, pickle_function, constructor_ob=None):
[11] Fix | Delete
if not callable(pickle_function):
[12] Fix | Delete
raise TypeError("reduction functions must be callable")
[13] Fix | Delete
dispatch_table[ob_type] = pickle_function
[14] Fix | Delete
[15] Fix | Delete
# The constructor_ob function is a vestige of safe for unpickling.
[16] Fix | Delete
# There is no reason for the caller to pass it anymore.
[17] Fix | Delete
if constructor_ob is not None:
[18] Fix | Delete
constructor(constructor_ob)
[19] Fix | Delete
[20] Fix | Delete
def constructor(object):
[21] Fix | Delete
if not callable(object):
[22] Fix | Delete
raise TypeError("constructors must be callable")
[23] Fix | Delete
[24] Fix | Delete
# Example: provide pickling support for complex numbers.
[25] Fix | Delete
[26] Fix | Delete
try:
[27] Fix | Delete
complex
[28] Fix | Delete
except NameError:
[29] Fix | Delete
pass
[30] Fix | Delete
else:
[31] Fix | Delete
[32] Fix | Delete
def pickle_complex(c):
[33] Fix | Delete
return complex, (c.real, c.imag)
[34] Fix | Delete
[35] Fix | Delete
pickle(complex, pickle_complex, complex)
[36] Fix | Delete
[37] Fix | Delete
# Support for pickling new-style objects
[38] Fix | Delete
[39] Fix | Delete
def _reconstructor(cls, base, state):
[40] Fix | Delete
if base is object:
[41] Fix | Delete
obj = object.__new__(cls)
[42] Fix | Delete
else:
[43] Fix | Delete
obj = base.__new__(cls, state)
[44] Fix | Delete
if base.__init__ != object.__init__:
[45] Fix | Delete
base.__init__(obj, state)
[46] Fix | Delete
return obj
[47] Fix | Delete
[48] Fix | Delete
_HEAPTYPE = 1<<9
[49] Fix | Delete
[50] Fix | Delete
# Python code for object.__reduce_ex__ for protocols 0 and 1
[51] Fix | Delete
[52] Fix | Delete
def _reduce_ex(self, proto):
[53] Fix | Delete
assert proto < 2
[54] Fix | Delete
for base in self.__class__.__mro__:
[55] Fix | Delete
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
[56] Fix | Delete
break
[57] Fix | Delete
else:
[58] Fix | Delete
base = object # not really reachable
[59] Fix | Delete
if base is object:
[60] Fix | Delete
state = None
[61] Fix | Delete
else:
[62] Fix | Delete
if base is self.__class__:
[63] Fix | Delete
raise TypeError("can't pickle %s objects" % base.__name__)
[64] Fix | Delete
state = base(self)
[65] Fix | Delete
args = (self.__class__, base, state)
[66] Fix | Delete
try:
[67] Fix | Delete
getstate = self.__getstate__
[68] Fix | Delete
except AttributeError:
[69] Fix | Delete
if getattr(self, "__slots__", None):
[70] Fix | Delete
raise TypeError("a class that defines __slots__ without "
[71] Fix | Delete
"defining __getstate__ cannot be pickled")
[72] Fix | Delete
try:
[73] Fix | Delete
dict = self.__dict__
[74] Fix | Delete
except AttributeError:
[75] Fix | Delete
dict = None
[76] Fix | Delete
else:
[77] Fix | Delete
dict = getstate()
[78] Fix | Delete
if dict:
[79] Fix | Delete
return _reconstructor, args, dict
[80] Fix | Delete
else:
[81] Fix | Delete
return _reconstructor, args
[82] Fix | Delete
[83] Fix | Delete
# Helper for __reduce_ex__ protocol 2
[84] Fix | Delete
[85] Fix | Delete
def __newobj__(cls, *args):
[86] Fix | Delete
return cls.__new__(cls, *args)
[87] Fix | Delete
[88] Fix | Delete
def __newobj_ex__(cls, args, kwargs):
[89] Fix | Delete
"""Used by pickle protocol 4, instead of __newobj__ to allow classes with
[90] Fix | Delete
keyword-only arguments to be pickled correctly.
[91] Fix | Delete
"""
[92] Fix | Delete
return cls.__new__(cls, *args, **kwargs)
[93] Fix | Delete
[94] Fix | Delete
def _slotnames(cls):
[95] Fix | Delete
"""Return a list of slot names for a given class.
[96] Fix | Delete
[97] Fix | Delete
This needs to find slots defined by the class and its bases, so we
[98] Fix | Delete
can't simply return the __slots__ attribute. We must walk down
[99] Fix | Delete
the Method Resolution Order and concatenate the __slots__ of each
[100] Fix | Delete
class found there. (This assumes classes don't modify their
[101] Fix | Delete
__slots__ attribute to misrepresent their slots after the class is
[102] Fix | Delete
defined.)
[103] Fix | Delete
"""
[104] Fix | Delete
[105] Fix | Delete
# Get the value from a cache in the class if possible
[106] Fix | Delete
names = cls.__dict__.get("__slotnames__")
[107] Fix | Delete
if names is not None:
[108] Fix | Delete
return names
[109] Fix | Delete
[110] Fix | Delete
# Not cached -- calculate the value
[111] Fix | Delete
names = []
[112] Fix | Delete
if not hasattr(cls, "__slots__"):
[113] Fix | Delete
# This class has no slots
[114] Fix | Delete
pass
[115] Fix | Delete
else:
[116] Fix | Delete
# Slots found -- gather slot names from all base classes
[117] Fix | Delete
for c in cls.__mro__:
[118] Fix | Delete
if "__slots__" in c.__dict__:
[119] Fix | Delete
slots = c.__dict__['__slots__']
[120] Fix | Delete
# if class has a single slot, it can be given as a string
[121] Fix | Delete
if isinstance(slots, str):
[122] Fix | Delete
slots = (slots,)
[123] Fix | Delete
for name in slots:
[124] Fix | Delete
# special descriptors
[125] Fix | Delete
if name in ("__dict__", "__weakref__"):
[126] Fix | Delete
continue
[127] Fix | Delete
# mangled names
[128] Fix | Delete
elif name.startswith('__') and not name.endswith('__'):
[129] Fix | Delete
stripped = c.__name__.lstrip('_')
[130] Fix | Delete
if stripped:
[131] Fix | Delete
names.append('_%s%s' % (stripped, name))
[132] Fix | Delete
else:
[133] Fix | Delete
names.append(name)
[134] Fix | Delete
else:
[135] Fix | Delete
names.append(name)
[136] Fix | Delete
[137] Fix | Delete
# Cache the outcome in the class if at all possible
[138] Fix | Delete
try:
[139] Fix | Delete
cls.__slotnames__ = names
[140] Fix | Delete
except:
[141] Fix | Delete
pass # But don't die if we can't
[142] Fix | Delete
[143] Fix | Delete
return names
[144] Fix | Delete
[145] Fix | Delete
# A registry of extension codes. This is an ad-hoc compression
[146] Fix | Delete
# mechanism. Whenever a global reference to <module>, <name> is about
[147] Fix | Delete
# to be pickled, the (<module>, <name>) tuple is looked up here to see
[148] Fix | Delete
# if it is a registered extension code for it. Extension codes are
[149] Fix | Delete
# universal, so that the meaning of a pickle does not depend on
[150] Fix | Delete
# context. (There are also some codes reserved for local use that
[151] Fix | Delete
# don't have this restriction.) Codes are positive ints; 0 is
[152] Fix | Delete
# reserved.
[153] Fix | Delete
[154] Fix | Delete
_extension_registry = {} # key -> code
[155] Fix | Delete
_inverted_registry = {} # code -> key
[156] Fix | Delete
_extension_cache = {} # code -> object
[157] Fix | Delete
# Don't ever rebind those names: pickling grabs a reference to them when
[158] Fix | Delete
# it's initialized, and won't see a rebinding.
[159] Fix | Delete
[160] Fix | Delete
def add_extension(module, name, code):
[161] Fix | Delete
"""Register an extension code."""
[162] Fix | Delete
code = int(code)
[163] Fix | Delete
if not 1 <= code <= 0x7fffffff:
[164] Fix | Delete
raise ValueError("code out of range")
[165] Fix | Delete
key = (module, name)
[166] Fix | Delete
if (_extension_registry.get(key) == code and
[167] Fix | Delete
_inverted_registry.get(code) == key):
[168] Fix | Delete
return # Redundant registrations are benign
[169] Fix | Delete
if key in _extension_registry:
[170] Fix | Delete
raise ValueError("key %s is already registered with code %s" %
[171] Fix | Delete
(key, _extension_registry[key]))
[172] Fix | Delete
if code in _inverted_registry:
[173] Fix | Delete
raise ValueError("code %s is already in use for key %s" %
[174] Fix | Delete
(code, _inverted_registry[code]))
[175] Fix | Delete
_extension_registry[key] = code
[176] Fix | Delete
_inverted_registry[code] = key
[177] Fix | Delete
[178] Fix | Delete
def remove_extension(module, name, code):
[179] Fix | Delete
"""Unregister an extension code. For testing only."""
[180] Fix | Delete
key = (module, name)
[181] Fix | Delete
if (_extension_registry.get(key) != code or
[182] Fix | Delete
_inverted_registry.get(code) != key):
[183] Fix | Delete
raise ValueError("key %s is not registered with code %s" %
[184] Fix | Delete
(key, code))
[185] Fix | Delete
del _extension_registry[key]
[186] Fix | Delete
del _inverted_registry[code]
[187] Fix | Delete
if code in _extension_cache:
[188] Fix | Delete
del _extension_cache[code]
[189] Fix | Delete
[190] Fix | Delete
def clear_extension_cache():
[191] Fix | Delete
_extension_cache.clear()
[192] Fix | Delete
[193] Fix | Delete
# Standard extension code assignments
[194] Fix | Delete
[195] Fix | Delete
# Reserved ranges
[196] Fix | Delete
[197] Fix | Delete
# First Last Count Purpose
[198] Fix | Delete
# 1 127 127 Reserved for Python standard library
[199] Fix | Delete
# 128 191 64 Reserved for Zope
[200] Fix | Delete
# 192 239 48 Reserved for 3rd parties
[201] Fix | Delete
# 240 255 16 Reserved for private use (will never be assigned)
[202] Fix | Delete
# 256 Inf Inf Reserved for future assignment
[203] Fix | Delete
[204] Fix | Delete
# Extension codes are assigned by the Python Software Foundation.
[205] Fix | Delete
[206] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function