blob: f6dbaaf7457bb15cc5ce522bb0910b698ff332da [file] [log] [blame]
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +00001:mod:`copyreg` --- Register :mod:`pickle` support functions
Georg Brandl71515ca2009-05-17 12:29:12 +00002===========================================================
Georg Brandl116aa622007-08-15 14:28:22 +00003
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +00004.. module:: copyreg
Georg Brandl116aa622007-08-15 14:28:22 +00005 :synopsis: Register pickle support functions.
6
7
8.. index::
9 module: pickle
10 module: cPickle
11 module: copy
12
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +000013The :mod:`copyreg` module provides support for the :mod:`pickle` and
Georg Brandl116aa622007-08-15 14:28:22 +000014:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
15future as well. It provides configuration information about object constructors
16which are not classes. Such constructors may be factory functions or class
17instances.
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 Brandlc2a4f4f2009-04-10 09:03:43 +000026.. function:: pickle(type, function, constructor=None)
Georg Brandl116aa622007-08-15 14:28:22 +000027
Georg Brandl23e8db52008-04-07 19:17:06 +000028 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 Brandl116aa622007-08-15 14:28:22 +000031
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