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