summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-08 08:59:03 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-08 08:59:03 (GMT)
commitb1c0e3b22991b4efaa9e6be425ce6a12f741e37b (patch)
tree8ea11fbc9a0169a310ee08b297c56a8613abd0ba /Doc
parent26025d6385da0be1778c15ff99938e60be58c485 (diff)
downloadcpython-b1c0e3b22991b4efaa9e6be425ce6a12f741e37b.zip
cpython-b1c0e3b22991b4efaa9e6be425ce6a12f741e37b.tar.gz
cpython-b1c0e3b22991b4efaa9e6be425ce6a12f741e37b.tar.bz2
#11481: update copy_reg docs and add example.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/copy_reg.rst31
1 files changed, 26 insertions, 5 deletions
diff --git a/Doc/library/copy_reg.rst b/Doc/library/copy_reg.rst
index 80ccb4b..e145cd5 100644
--- a/Doc/library/copy_reg.rst
+++ b/Doc/library/copy_reg.rst
@@ -14,11 +14,11 @@
module: cPickle
module: copy
-The :mod:`copy_reg` module provides support for the :mod:`pickle` and
-:mod:`cPickle` modules. 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. Such constructors may be factory functions or class
-instances.
+The :mod:`copy_reg` module offers a way to define fuctions used while pickling
+specific objects. The :mod:`pickle`, :mod:`cPickle, 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.
.. function:: constructor(object)
@@ -43,3 +43,24 @@ instances.
See the :mod:`pickle` module for more details on the interface expected of
*function* and *constructor*.
+Example
+-------
+
+The example below would like to show how to register a pickle function and how
+it will be used:
+
+ >>> import copy_reg, 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,)
+ ...
+ >>> copy_reg.pickle(C, pickle_c)
+ >>> c = C(1)
+ >>> d = copy.copy(c)
+ pickling a C instance...
+ >>> p = pickle.dumps(c)
+ pickling a C instance...