Mercurial > cpython-lru_cache-weakref
annotate Lib/copy_reg.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | ef3ba8b99da2 |
| children | e34991022571 |
| rev | line source |
|---|---|
|
5558
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
1 # Helper to provide extensibility for pickle/cPickle. |
|
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
2 |
| 5282 | 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 | |
|
5558
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
9 if constructor_ob is not None: |
| 5282 | 10 constructor(constructor_ob) |
| 11 | |
| 12 def constructor(object): | |
| 13 safe_constructors[object] = 1 | |
| 14 | |
|
5558
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
15 # Example: provide pickling support for complex numbers. |
| 5282 | 16 |
|
5558
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
17 def pickle_complex(c): |
|
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
18 return complex, (c.real, c.imag) |
| 5282 | 19 |
|
5558
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
20 pickle(type(1j), pickle_complex, complex) |
|
ef3ba8b99da2
Added some minimal comments and tweaked lay-out a bit.
Guido van Rossum <guido@python.org>
parents:
5282
diff
changeset
|
21 |
