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