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