home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / copy_reg.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  4.0 KB  |  151 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. from types import ClassType as _ClassType
  5. __all__ = [
  6.     'pickle',
  7.     'constructor',
  8.     'add_extension',
  9.     'remove_extension',
  10.     'clear_extension_cache']
  11. dispatch_table = { }
  12.  
  13. def pickle(ob_type, pickle_function, constructor_ob = None):
  14.     if type(ob_type) is _ClassType:
  15.         raise TypeError('copy_reg is not intended for use with classes')
  16.     if not hasattr(pickle_function, '__call__'):
  17.         raise TypeError('reduction functions must be callable')
  18.     dispatch_table[ob_type] = pickle_function
  19.     if constructor_ob is not None:
  20.         constructor(constructor_ob)
  21.  
  22.  
  23. def constructor(object):
  24.     if not hasattr(object, '__call__'):
  25.         raise TypeError('constructors must be callable')
  26.  
  27.  
  28. try:
  29.     complex
  30. except NameError:
  31.     pass
  32.  
  33.  
  34. def pickle_complex(c):
  35.     return (complex, (c.real, c.imag))
  36.  
  37. pickle(complex, pickle_complex, complex)
  38.  
  39. def _reconstructor(cls, base, state):
  40.     if base is object:
  41.         obj = object.__new__(cls)
  42.     else:
  43.         obj = base.__new__(cls, state)
  44.         if base.__init__ != object.__init__:
  45.             base.__init__(obj, state)
  46.     return obj
  47.  
  48. _HEAPTYPE = 512
  49.  
  50. def _reduce_ex(self, proto):
  51.     for base in self.__class__.__mro__:
  52.         if hasattr(base, '__flags__') and not (base.__flags__ & _HEAPTYPE):
  53.             break
  54.             continue
  55.         base = object
  56.         if base is object:
  57.             state = None
  58.         elif base is self.__class__:
  59.             raise TypeError, "can't pickle %s objects" % base.__name__
  60.         state = base(self)
  61.         args = (self.__class__, base, state)
  62.         
  63.         try:
  64.             getstate = self.__getstate__
  65.         except AttributeError:
  66.             if getattr(self, '__slots__', None):
  67.                 raise TypeError('a class that defines __slots__ without defining __getstate__ cannot be pickled')
  68.             
  69.             try:
  70.                 dict = self.__dict__
  71.             except AttributeError:
  72.                 dict = None
  73.             
  74.  
  75.  
  76.         dict = getstate()
  77.         if dict:
  78.             return (_reconstructor, args, dict)
  79.         return (None, args)
  80.         return None
  81.  
  82.  
  83. def __newobj__(cls, *args):
  84.     return cls.__new__(cls, *args)
  85.  
  86.  
  87. def _slotnames(cls):
  88.     names = cls.__dict__.get('__slotnames__')
  89.     if names is not None:
  90.         return names
  91.     names = None
  92.     if not hasattr(cls, '__slots__'):
  93.         pass
  94.     else:
  95.         for c in cls.__mro__:
  96.             if '__slots__' in c.__dict__:
  97.                 slots = c.__dict__['__slots__']
  98.                 if isinstance(slots, basestring):
  99.                     slots = (slots,)
  100.                 for name in slots:
  101.                     if name in ('__dict__', '__weakref__'):
  102.                         continue
  103.                         continue
  104.                     if name.startswith('__') and not name.endswith('__'):
  105.                         names.append('_%s%s' % (c.__name__, name))
  106.                         continue
  107.                     names.append(name)
  108.                 
  109.     
  110.     try:
  111.         cls.__slotnames__ = names
  112.     except:
  113.         pass
  114.  
  115.     return names
  116.  
  117. _extension_registry = { }
  118. _inverted_registry = { }
  119. _extension_cache = { }
  120.  
  121. def add_extension(module, name, code):
  122.     code = int(code)
  123.     if code <= code:
  124.         pass
  125.     elif not code <= 2147483647:
  126.         raise ValueError, 'code out of range'
  127.     key = (module, name)
  128.     if _extension_registry.get(key) == code and _inverted_registry.get(code) == key:
  129.         return None
  130.     if code <= 2147483647 in _extension_registry:
  131.         raise ValueError('key %s is already registered with code %s' % (key, _extension_registry[key]))
  132.     if code in _inverted_registry:
  133.         raise ValueError('code %s is already in use for key %s' % (code, _inverted_registry[code]))
  134.     _extension_registry[key] = code
  135.     _inverted_registry[code] = key
  136.  
  137.  
  138. def remove_extension(module, name, code):
  139.     key = (module, name)
  140.     if _extension_registry.get(key) != code or _inverted_registry.get(code) != key:
  141.         raise ValueError('key %s is not registered with code %s' % (key, code))
  142.     del _extension_registry[key]
  143.     del _inverted_registry[code]
  144.     if code in _extension_cache:
  145.         del _extension_cache[code]
  146.  
  147.  
  148. def clear_extension_cache():
  149.     _extension_cache.clear()
  150.  
  151.