home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / copy_reg.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  2.5 KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. from types import ClassType as _ClassType
  5. __all__ = [
  6.     'pickle',
  7.     'constructor']
  8. dispatch_table = { }
  9. safe_constructors = { }
  10.  
  11. def pickle(ob_type, pickle_function, constructor_ob = None):
  12.     if type(ob_type) is _ClassType:
  13.         raise TypeError('copy_reg is not intended for use with classes')
  14.     
  15.     if not callable(pickle_function):
  16.         raise TypeError('reduction functions must be callable')
  17.     
  18.     dispatch_table[ob_type] = pickle_function
  19.     if constructor_ob is not None:
  20.         constructor(constructor_ob)
  21.     
  22.  
  23.  
  24. def constructor(object):
  25.     if not callable(object):
  26.         raise TypeError('constructors must be callable')
  27.     
  28.     safe_constructors[object] = 1
  29.  
  30.  
  31. def pickle_complex(c):
  32.     return (complex, (c.real, c.imag))
  33.  
  34. pickle(type((0.0+1.0j)), pickle_complex, complex)
  35.  
  36. def _reconstructor(cls, base, state):
  37.     obj = base.__new__(cls, state)
  38.     base.__init__(obj, state)
  39.     return obj
  40.  
  41. _reconstructor.__safe_for_unpickling__ = 1
  42. _HEAPTYPE = 1 << 9
  43.  
  44. def _reduce(self):
  45.     for base in self.__class__.__mro__:
  46.         if hasattr(base, '__flags__') and not (base.__flags__ & _HEAPTYPE):
  47.             break
  48.         
  49.     else:
  50.         base = object
  51.     if base is object:
  52.         state = None
  53.     elif base is self.__class__:
  54.         raise TypeError, "can't pickle %s objects" % base.__name__
  55.     
  56.     state = base(self)
  57.     args = (self.__class__, base, state)
  58.     
  59.     try:
  60.         getstate = self.__getstate__
  61.     except AttributeError:
  62.         
  63.         try:
  64.             dict = self.__dict__
  65.         except AttributeError:
  66.             dict = None
  67.  
  68.  
  69.     dict = getstate()
  70.     if dict:
  71.         return (_reconstructor, args, dict)
  72.     else:
  73.         return (_reconstructor, args)
  74.  
  75.