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