Staging
v0.5.0
https://github.com/python/cpython
Raw File
Tip revision: fa38b3ee749388386914a6584b4c7d97aa474abe authored by cvs2svn on 22 December 1998, 21:43:35 UTC
This commit was manufactured by cvs2svn to create tag 'r152b1'.
Tip revision: fa38b3e
copy_reg.py
# Helper to provide extensibility for pickle/cPickle.

dispatch_table = {}
safe_constructors = {}

def pickle(ob_type, pickle_function, constructor_ob = None):
    dispatch_table[ob_type] = pickle_function

    if constructor_ob is not None:
        constructor(constructor_ob)

def constructor(object):
    safe_constructors[object] = 1

# Example: provide pickling support for complex numbers.

def pickle_complex(c):
    return complex, (c.real, c.imag)

pickle(type(1j), pickle_complex, complex)

back to top