/Doc/library/copy_reg.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 45 lines · 32 code · 13 blank · 0 comment · 0 complexity · 281c56b62f059d2729eb45dd8f7fde9f MD5 · raw file

  1. :mod:`copy_reg` --- Register :mod:`pickle` support functions
  2. ============================================================
  3. .. module:: copy_reg
  4. :synopsis: Register pickle support functions.
  5. .. note::
  6. The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3.0.
  7. The :term:`2to3` tool will automatically adapt imports when converting your
  8. sources to 3.0.
  9. .. index::
  10. module: pickle
  11. module: cPickle
  12. module: copy
  13. The :mod:`copy_reg` module provides support for the :mod:`pickle` and
  14. :mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
  15. future as well. It provides configuration information about object constructors
  16. which are not classes. Such constructors may be factory functions or class
  17. instances.
  18. .. function:: constructor(object)
  19. Declares *object* to be a valid constructor. If *object* is not callable (and
  20. hence not valid as a constructor), raises :exc:`TypeError`.
  21. .. function:: pickle(type, function[, constructor])
  22. Declares that *function* should be used as a "reduction" function for objects of
  23. type *type*; *type* must not be a "classic" class object. (Classic classes are
  24. handled differently; see the documentation for the :mod:`pickle` module for
  25. details.) *function* should return either a string or a tuple containing two or
  26. three elements.
  27. The optional *constructor* parameter, if provided, is a callable object which
  28. can be used to reconstruct the object when called with the tuple of arguments
  29. returned by *function* at pickling time. :exc:`TypeError` will be raised if
  30. *object* is a class or *constructor* is not callable.
  31. See the :mod:`pickle` module for more details on the interface expected of
  32. *function* and *constructor*.