blob: a2d316e95229cdcde980ab45d94aa16ed584a6af [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
Georg Brandl116aa622007-08-15 14:28:22 +000010 module: copy
11
Benjamin Petersonb5314c62009-12-13 21:04:16 +000012The :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
14configuration information about object constructors which are not classes.
15Such constructors may be factory functions or class instances.
Georg Brandl116aa622007-08-15 14:28:22 +000016
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 Brandlc2a4f4f2009-04-10 09:03:43 +000024.. function:: pickle(type, function, constructor=None)
Georg Brandl116aa622007-08-15 14:28:22 +000025
Georg Brandl23e8db52008-04-07 19:17:06 +000026 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 Brandl116aa622007-08-15 14:28:22 +000029
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