home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / iria107a.lzh / script / copy_reg.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-11-17  |  1.5 KB  |  37 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.0)
  3.  
  4. '''Helper to provide extensibility for pickle/cPickle.
  5.  
  6. This is only useful to add pickle support for extension types defined in
  7. C, not for instances of user-defined classes.
  8. '''
  9. from types import ClassType as _ClassType
  10. dispatch_table = { }
  11. safe_constructors = { }
  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.     
  17.     if not callable(pickle_function):
  18.         raise TypeError('reduction functions must be callable')
  19.     
  20.     dispatch_table[ob_type] = pickle_function
  21.     if constructor_ob is not None:
  22.         constructor(constructor_ob)
  23.     
  24.  
  25.  
  26. def constructor(object):
  27.     if not callable(object):
  28.         raise TypeError('constructors must be callable')
  29.     
  30.     safe_constructors[object] = 1
  31.  
  32.  
  33. def pickle_complex(c):
  34.     return (complex, (c.real, c.imag))
  35.  
  36. pickle(type((0.0+1.0j)), pickle_complex, complex)
  37.