home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Lib / copy_reg.py < prev    next >
Text File  |  1997-05-20  |  501b  |  22 lines

  1. # Helper to provide extensibility for pickle/cPickle.
  2.  
  3. dispatch_table = {}
  4. safe_constructors = {}
  5.  
  6. def pickle(ob_type, pickle_function, constructor_ob = None):
  7.     dispatch_table[ob_type] = pickle_function
  8.  
  9.     if constructor_ob is not None:
  10.         constructor(constructor_ob)
  11.  
  12. def constructor(object):
  13.     safe_constructors[object] = 1
  14.  
  15. # Example: provide pickling support for complex numbers.
  16.  
  17. def pickle_complex(c):
  18.     return complex, (c.real, c.imag)
  19.  
  20. pickle(type(1j), pickle_complex, complex)
  21.  
  22.