mirror of
https://github.com/python/cpython.git
synced 2024-12-03 14:55:56 +08:00
22fff43633
svn+ssh://svn.python.org/python/branches/py3k ................ r74609 | senthil.kumaran | 2009-08-31 18:43:45 +0200 (Mo, 31 Aug 2009) | 3 lines Doc fix for issue2637. ................ r74627 | georg.brandl | 2009-09-02 22:31:26 +0200 (Mi, 02 Sep 2009) | 1 line #6819: fix typo. ................ r74634 | georg.brandl | 2009-09-03 14:34:10 +0200 (Do, 03 Sep 2009) | 9 lines Merged revisions 74633 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74633 | georg.brandl | 2009-09-03 14:31:39 +0200 (Do, 03 Sep 2009) | 1 line #6757: complete the list of types that marshal can serialize. ........ ................ r74645 | georg.brandl | 2009-09-04 10:07:32 +0200 (Fr, 04 Sep 2009) | 1 line #5221: fix related topics: SEQUENCEMETHODS[12] doesnt exist any more. ................ r74651 | georg.brandl | 2009-09-04 13:20:54 +0200 (Fr, 04 Sep 2009) | 9 lines Recorded merge of revisions 74650 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74650 | georg.brandl | 2009-09-04 13:19:34 +0200 (Fr, 04 Sep 2009) | 1 line #5101: add back tests to test_funcattrs that were lost during unittest conversion, and make some PEP8 cleanups. ........ ................ r74738 | georg.brandl | 2009-09-09 18:51:05 +0200 (Mi, 09 Sep 2009) | 9 lines Merged revisions 74737 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74737 | georg.brandl | 2009-09-09 18:49:13 +0200 (Mi, 09 Sep 2009) | 1 line Properly document copy and deepcopy as functions. ........ ................ r74840 | georg.brandl | 2009-09-16 18:40:45 +0200 (Mi, 16 Sep 2009) | 13 lines Merged revisions 74838-74839 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74838 | georg.brandl | 2009-09-16 18:22:12 +0200 (Mi, 16 Sep 2009) | 1 line Remove some more boilerplate from the actual tests in test_pdb. ........ r74839 | georg.brandl | 2009-09-16 18:36:39 +0200 (Mi, 16 Sep 2009) | 1 line Make the pdb displayhook compatible with the standard displayhook: do not print Nones. Add a test for that. ........ ................ r75016 | georg.brandl | 2009-09-22 15:53:14 +0200 (Di, 22 Sep 2009) | 1 line #6969: make it explicit that configparser writes/reads text files, and fix the example. ................ r75316 | georg.brandl | 2009-10-10 23:12:35 +0200 (Sa, 10 Okt 2009) | 9 lines Merged revisions 75313 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75313 | georg.brandl | 2009-10-10 23:07:35 +0200 (Sa, 10 Okt 2009) | 1 line Bring old demo up-to-date. ........ ................ r75317 | georg.brandl | 2009-10-10 23:13:21 +0200 (Sa, 10 Okt 2009) | 9 lines Merged revisions 75315 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75315 | georg.brandl | 2009-10-10 23:10:05 +0200 (Sa, 10 Okt 2009) | 1 line Remove unneeded "L" suffixes. ........ ................ r75323 | georg.brandl | 2009-10-10 23:48:05 +0200 (Sa, 10 Okt 2009) | 9 lines Recorded merge of revisions 75321 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75321 | georg.brandl | 2009-10-10 23:43:21 +0200 (Sa, 10 Okt 2009) | 1 line Remove outdated comment and fix a few style issues. ........ ................ r75324 | georg.brandl | 2009-10-10 23:49:24 +0200 (Sa, 10 Okt 2009) | 9 lines Merged revisions 75322 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75322 | georg.brandl | 2009-10-10 23:47:31 +0200 (Sa, 10 Okt 2009) | 1 line Show use of range() step argument nicely. ........ ................ r75326 | georg.brandl | 2009-10-10 23:57:03 +0200 (Sa, 10 Okt 2009) | 9 lines Merged revisions 75325 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75325 | georg.brandl | 2009-10-10 23:55:11 +0200 (Sa, 10 Okt 2009) | 1 line Modernize factorisation demo (mostly augassign.) ........ ................ r75328 | georg.brandl | 2009-10-11 00:05:26 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75327 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75327 | georg.brandl | 2009-10-11 00:03:43 +0200 (So, 11 Okt 2009) | 1 line Style fixes. ........ ................ r75330 | georg.brandl | 2009-10-11 00:32:28 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75329 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75329 | georg.brandl | 2009-10-11 00:26:45 +0200 (So, 11 Okt 2009) | 1 line Modernize all around (dont ask me how useful that script is nowadays...) ........ ................ r75338 | georg.brandl | 2009-10-11 10:31:41 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75337 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75337 | georg.brandl | 2009-10-11 10:18:44 +0200 (So, 11 Okt 2009) | 1 line Update morse script, avoid globals, use iterators. ........ ................ r75340 | georg.brandl | 2009-10-11 10:42:09 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75339 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75339 | georg.brandl | 2009-10-11 10:39:16 +0200 (So, 11 Okt 2009) | 1 line Update markov demo. ........ ................ r75341 | georg.brandl | 2009-10-11 10:43:08 +0200 (So, 11 Okt 2009) | 1 line Fix README description. ................ r75343 | georg.brandl | 2009-10-11 10:46:56 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75342 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75342 | georg.brandl | 2009-10-11 10:45:03 +0200 (So, 11 Okt 2009) | 1 line Remove useless script "mkrcs" and update README. ........ ................ r75352 | georg.brandl | 2009-10-11 14:04:10 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75350 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75350 | georg.brandl | 2009-10-11 14:00:18 +0200 (So, 11 Okt 2009) | 1 line Use getopt in script.py demo. ........ ................ r75353 | georg.brandl | 2009-10-11 14:04:40 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75351 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75351 | georg.brandl | 2009-10-11 14:03:01 +0200 (So, 11 Okt 2009) | 1 line Fix variable. ........ ................ r75355 | georg.brandl | 2009-10-11 16:27:51 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75354 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75354 | georg.brandl | 2009-10-11 16:23:49 +0200 (So, 11 Okt 2009) | 1 line Update lpwatch script. ........ ................ r75357 | georg.brandl | 2009-10-11 16:50:57 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75356 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75356 | georg.brandl | 2009-10-11 16:49:37 +0200 (So, 11 Okt 2009) | 1 line Remove ftpstats script, the daemon whose log files it reads is long gone. ........ ................ r75359 | georg.brandl | 2009-10-11 17:56:06 +0200 (So, 11 Okt 2009) | 9 lines Merged revisions 75358 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75358 | georg.brandl | 2009-10-11 17:06:44 +0200 (So, 11 Okt 2009) | 1 line Overhaul of Demo/xml. ........ ................
117 lines
4.8 KiB
ReStructuredText
117 lines
4.8 KiB
ReStructuredText
:mod:`marshal` --- Internal Python object serialization
|
|
=======================================================
|
|
|
|
.. module:: marshal
|
|
:synopsis: Convert Python objects to streams of bytes and back (with different
|
|
constraints).
|
|
|
|
|
|
This module contains functions that can read and write Python values in a binary
|
|
format. The format is specific to Python, but independent of machine
|
|
architecture issues (e.g., you can write a Python value to a file on a PC,
|
|
transport the file to a Sun, and read it back there). Details of the format are
|
|
undocumented on purpose; it may change between Python versions (although it
|
|
rarely does). [#]_
|
|
|
|
.. index::
|
|
module: pickle
|
|
module: shelve
|
|
object: code
|
|
|
|
This is not a general "persistence" module. For general persistence and
|
|
transfer of Python objects through RPC calls, see the modules :mod:`pickle` and
|
|
:mod:`shelve`. The :mod:`marshal` module exists mainly to support reading and
|
|
writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files.
|
|
Therefore, the Python maintainers reserve the right to modify the marshal format
|
|
in backward incompatible ways should the need arise. If you're serializing and
|
|
de-serializing Python objects, use the :mod:`pickle` module instead -- the
|
|
performance is comparable, version independence is guaranteed, and pickle
|
|
supports a substantially wider range of objects than marshal.
|
|
|
|
.. warning::
|
|
|
|
The :mod:`marshal` module is not intended to be secure against erroneous or
|
|
maliciously constructed data. Never unmarshal data received from an
|
|
untrusted or unauthenticated source.
|
|
|
|
Not all Python object types are supported; in general, only objects whose value
|
|
is independent from a particular invocation of Python can be written and read by
|
|
this module. The following types are supported: booleans, integers, floating
|
|
point numbers, complex numbers, strings, bytes, bytearrays, tuples, lists, sets,
|
|
frozensets, dictionaries, and code objects, where it should be understood that
|
|
tuples, lists, sets, frozensets and dictionaries are only supported as long as
|
|
the values contained therein are themselves supported; and recursive lists, sets
|
|
and dictionaries should not be written (they will cause infinite loops). The
|
|
singletons :const:`None`, :const:`Ellipsis` and :exc:`StopIteration` can also be
|
|
marshalled and unmarshalled.
|
|
|
|
There are functions that read/write files as well as functions operating on
|
|
strings.
|
|
|
|
The module defines these functions:
|
|
|
|
|
|
.. function:: dump(value, file[, version])
|
|
|
|
Write the value on the open file. The value must be a supported type. The
|
|
file must be an open file object such as ``sys.stdout`` or returned by
|
|
:func:`open` or :func:`os.popen`. It must be opened in binary mode (``'wb'``
|
|
or ``'w+b'``).
|
|
|
|
If the value has (or contains an object that has) an unsupported type, a
|
|
:exc:`ValueError` exception is raised --- but garbage data will also be written
|
|
to the file. The object will not be properly read back by :func:`load`.
|
|
|
|
The *version* argument indicates the data format that ``dump`` should use
|
|
(see below).
|
|
|
|
|
|
.. function:: load(file)
|
|
|
|
Read one value from the open file and return it. If no valid value is read
|
|
(e.g. because the data has a different Python version's incompatible marshal
|
|
format), raise :exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. The
|
|
file must be an open file object opened in binary mode (``'rb'`` or
|
|
``'r+b'``).
|
|
|
|
.. note::
|
|
|
|
If an object containing an unsupported type was marshalled with :func:`dump`,
|
|
:func:`load` will substitute ``None`` for the unmarshallable type.
|
|
|
|
|
|
.. function:: dumps(value[, version])
|
|
|
|
Return the string that would be written to a file by ``dump(value, file)``. The
|
|
value must be a supported type. Raise a :exc:`ValueError` exception if value
|
|
has (or contains an object that has) an unsupported type.
|
|
|
|
The *version* argument indicates the data format that ``dumps`` should use
|
|
(see below).
|
|
|
|
|
|
.. function:: loads(string)
|
|
|
|
Convert the string to a value. If no valid value is found, raise
|
|
:exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. Extra characters in the
|
|
string are ignored.
|
|
|
|
|
|
In addition, the following constants are defined:
|
|
|
|
.. data:: version
|
|
|
|
Indicates the format that the module uses. Version 0 is the historical
|
|
format, version 1 shares interned strings and version 2 uses a binary format
|
|
for floating point numbers. The current version is 2.
|
|
|
|
|
|
.. rubric:: Footnotes
|
|
|
|
.. [#] The name of this module stems from a bit of terminology used by the designers of
|
|
Modula-3 (amongst others), who use the term "marshalling" for shipping of data
|
|
around in a self-contained form. Strictly speaking, "to marshal" means to
|
|
convert some data from internal to external form (in an RPC buffer for instance)
|
|
and "unmarshalling" for the reverse process.
|
|
|