]> granicus.if.org Git - python/commitdiff
#11481: merge with 3.2.
authorEzio Melotti <ezio.melotti@gmail.com>
Thu, 8 Nov 2012 09:06:01 +0000 (11:06 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Thu, 8 Nov 2012 09:06:01 +0000 (11:06 +0200)
1  2 
Doc/library/copyreg.rst

index 41061e515a32c3c94ad887eb0e2454c6ee6610d1,f3721d1929664315de34d802188e64e33e92c8cd..50d5879ae529bc81b16c52580a933fb96c014651
@@@ -32,8 -33,28 +33,30 @@@ Such constructors may be factory functi
     returned by *function* at pickling time.  :exc:`TypeError` will be raised if
     *object* is a class or *constructor* is not callable.
  
 -   See the :mod:`pickle` module for more details on the interface expected of
 -   *function* and *constructor*.
 -
 +   See the :mod:`pickle` module for more details on the interface
 +   expected of *function* and *constructor*.  Note that the
 +   :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...