summaryrefslogtreecommitdiffstats
path: root/Doc/library/copyreg.rst
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-08 09:06:01 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-08 09:06:01 (GMT)
commitb77dc4ec5f5901f3de106de8a7369df2cf46940e (patch)
treef47cff8df7b7ffe7e2e330bad26f79ea3a550458 /Doc/library/copyreg.rst
parent60e22b9c5d83781470d5a1ab26cb482b53a3e9d7 (diff)
parent78b18d4b4c82c90c3c45f0ea77c78bbfb3358218 (diff)
downloadcpython-b77dc4ec5f5901f3de106de8a7369df2cf46940e.zip
cpython-b77dc4ec5f5901f3de106de8a7369df2cf46940e.tar.gz
cpython-b77dc4ec5f5901f3de106de8a7369df2cf46940e.tar.bz2
#11481: merge with 3.2.
Diffstat (limited to 'Doc/library/copyreg.rst')
-rw-r--r--Doc/library/copyreg.rst29
1 files changed, 26 insertions, 3 deletions
diff --git a/Doc/library/copyreg.rst b/Doc/library/copyreg.rst
index 41061e5..50d5879 100644
--- a/Doc/library/copyreg.rst
+++ b/Doc/library/copyreg.rst
@@ -9,9 +9,10 @@
module: pickle
module: copy
-The :mod:`copyreg` module provides support for the :mod:`pickle` module. The
-:mod:`copy` module is likely to use this in the future as well. It provides
-configuration information about object constructors which are not classes.
+The :mod:`copyreg` module offers a way to define fuctions used while pickling
+specific objects. The :mod:`pickle` and :mod:`copy` modules use those functions
+when pickling/copying those objects. The module provides configuration
+information about object constructors which are not classes.
Such constructors may be factory functions or class instances.
@@ -37,3 +38,25 @@ Such constructors may be factory functions or class instances.
:attr:`~pickle.Pickler.dispatch_table` attribute of a pickler
object or subclass of :class:`pickle.Pickler` can also be used for
declaring reduction functions.
+
+Example
+-------
+
+The example below would like to show how to register a pickle function and how
+it will be used:
+
+ >>> import copyreg, copy, pickle
+ >>> class C(object):
+ ... def __init__(self, a):
+ ... self.a = a
+ ...
+ >>> def pickle_c(c):
+ ... print("pickling a C instance...")
+ ... return C, (c.a,)
+ ...
+ >>> copyreg.pickle(C, pickle_c)
+ >>> c = C(1)
+ >>> d = copy.copy(c)
+ pickling a C instance...
+ >>> p = pickle.dumps(c)
+ pickling a C instance...