blob: 60df3d0e896e5b74bb2e65d502a04ed025a9b0e6 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +00002:mod:`copyreg` --- Register :mod:`pickle` support functions
Georg Brandl116aa622007-08-15 14:28:22 +00003============================================================
4
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +00005.. module:: copyreg
Georg Brandl116aa622007-08-15 14:28:22 +00006 :synopsis: Register pickle support functions.
7
8
9.. index::
10 module: pickle
11 module: cPickle
12 module: copy
13
Alexandre Vassalottif7fa63d2008-05-11 08:55:36 +000014The :mod:`copyreg` module provides support for the :mod:`pickle` and
Georg Brandl116aa622007-08-15 14:28:22 +000015:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
16future as well. It provides configuration information about object constructors
17which are not classes. Such constructors may be factory functions or class
18instances.
19
20
21.. function:: constructor(object)
22
23 Declares *object* to be a valid constructor. If *object* is not callable (and
24 hence not valid as a constructor), raises :exc:`TypeError`.
25
26
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000027.. function:: pickle(type, function, constructor=None)
Georg Brandl116aa622007-08-15 14:28:22 +000028
Georg Brandl23e8db52008-04-07 19:17:06 +000029 Declares that *function* should be used as a "reduction" function for objects
30 of type *type*. *function* should return either a string or a tuple
31 containing two or three elements.
Georg Brandl116aa622007-08-15 14:28:22 +000032
33 The optional *constructor* parameter, if provided, is a callable object which
34 can be used to reconstruct the object when called with the tuple of arguments
35 returned by *function* at pickling time. :exc:`TypeError` will be raised if
36 *object* is a class or *constructor* is not callable.
37
38 See the :mod:`pickle` module for more details on the interface expected of
39 *function* and *constructor*.
40