Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1 | |
| 2 | :mod:`copy_reg` --- Register :mod:`pickle` support functions |
| 3 | ============================================================ |
| 4 | |
| 5 | .. module:: copy_reg |
| 6 | :synopsis: Register pickle support functions. |
| 7 | |
| 8 | |
| 9 | .. index:: |
| 10 | module: pickle |
| 11 | module: cPickle |
| 12 | module: copy |
| 13 | |
| 14 | The :mod:`copy_reg` module provides support for the :mod:`pickle` and |
| 15 | :mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the |
| 16 | future as well. It provides configuration information about object constructors |
| 17 | which are not classes. Such constructors may be factory functions or class |
| 18 | instances. |
| 19 | |
| 20 | |
| 21 | .. function:: constructor(object) |
| 22 | |
| 23 | Declares *object* to be a valid constructor. If *object* is not callable (and |
| 24 | hence not valid as a constructor), raises :exc:`TypeError`. |
| 25 | |
| 26 | |
| 27 | .. function:: pickle(type, function[, constructor]) |
| 28 | |
| 29 | Declares that *function* should be used as a "reduction" function for objects of |
| 30 | type *type*; *type* must not be a "classic" class object. (Classic classes are |
| 31 | handled differently; see the documentation for the :mod:`pickle` module for |
| 32 | details.) *function* should return either a string or a tuple containing two or |
| 33 | three elements. |
| 34 | |
| 35 | The optional *constructor* parameter, if provided, is a callable object which |
| 36 | can be used to reconstruct the object when called with the tuple of arguments |
| 37 | returned by *function* at pickling time. :exc:`TypeError` will be raised if |
| 38 | *object* is a class or *constructor* is not callable. |
| 39 | |
| 40 | See the :mod:`pickle` module for more details on the interface expected of |
| 41 | *function* and *constructor*. |
| 42 | |