blob: 3a3f815de85dc1bdf0e74137a7dae6988c1fc6ff [file] [log] [blame]
Georg Brandl6a0a3682008-05-12 10:05:39 +00001:mod:`copyreg` --- Register :mod:`pickle` support functions
2===========================================================
Georg Brandl8ec7f652007-08-15 14:28:01 +00003
4.. module:: copy_reg
Georg Brandl6a0a3682008-05-12 10:05:39 +00005 :synopsis: Old name for the copyreg module.
6
7.. module:: copyreg
Georg Brandl8ec7f652007-08-15 14:28:01 +00008 :synopsis: Register pickle support functions.
9
Alexandre Vassalotti25ad76c2008-05-11 09:01:51 +000010.. note::
Georg Brandl6a0a3682008-05-12 10:05:39 +000011 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 Brandl8ec7f652007-08-15 14:28:01 +000014
15.. index::
16 module: pickle
17 module: cPickle
18 module: copy
19
Georg Brandl6a0a3682008-05-12 10:05:39 +000020The :mod:`copyreg` module provides support for the :mod:`pickle` and
Georg Brandl8ec7f652007-08-15 14:28:01 +000021:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
22future as well. It provides configuration information about object constructors
23which are not classes. Such constructors may be factory functions or class
24instances.
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