Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/copy_reg.rst

    r2 r391  
    66
    77.. note::
    8    The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3.0.
     8   The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3.
    99   The :term:`2to3` tool will automatically adapt imports when converting your
    10    sources to 3.0.
     10   sources to Python 3.
    1111
    1212.. index::
     
    1515   module: copy
    1616
    17 The :mod:`copy_reg` module provides support for the :mod:`pickle` and
    18 :mod:`cPickle` modules.  The :mod:`copy` module is likely to use this in the
    19 future as well.  It provides configuration information about object constructors
    20 which are not classes.  Such constructors may be factory functions or class
    21 instances.
     17The :mod:`copy_reg` module offers a way to define fuctions used while pickling
     18specific objects.  The :mod:`pickle`, :mod:`cPickle`, and :mod:`copy` modules
     19use those functions when pickling/copying those objects.  The module provides
     20configuration information about object constructors which are not classes.
     21Such constructors may be factory functions or class instances.
    2222
    2323
     
    4444   *function* and *constructor*.
    4545
     46Example
     47-------
     48
     49The example below would like to show how to register a pickle function and how
     50it will be used:
     51
     52   >>> import copy_reg, copy, pickle
     53   >>> class C(object):
     54   ...     def __init__(self, a):
     55   ...         self.a = a
     56   ...
     57   >>> def pickle_c(c):
     58   ...     print("pickling a C instance...")
     59   ...     return C, (c.a,)
     60   ...
     61   >>> copy_reg.pickle(C, pickle_c)
     62   >>> c = C(1)
     63   >>> d = copy.copy(c)
     64   pickling a C instance...
     65   >>> p = pickle.dumps(c)
     66   pickling a C instance...
Note: See TracChangeset for help on using the changeset viewer.