Minor edits to the "Protocol versions" section.
This commit is contained in:
parent
21a586e1b3
commit
17338a4481
21
pep-0307.txt
21
pep-0307.txt
|
@ -59,29 +59,32 @@ Motivation
|
|||
|
||||
Protocol versions
|
||||
|
||||
Previously, pickling (but not unpickling) has distinguished
|
||||
between text mode and binary mode. By design, text mode is a
|
||||
subset of binary mode, and unpicklers don't need to know in
|
||||
Previously, pickling (but not unpickling) distinguished between
|
||||
text mode and binary mode. By design, binary mode is a
|
||||
superset of text mode, and unpicklers don't need to know in
|
||||
advance whether an incoming pickle uses text mode or binary mode.
|
||||
The virtual machine used for unpickling is the same regardless of
|
||||
the mode; certain opcode simply aren't used in text mode.
|
||||
the mode; certain opcodes simply aren't used in text mode.
|
||||
|
||||
Retroactively, text mode is called protocol 0, and binary mode is
|
||||
called protocol 1. The new protocol is called protocol 2. In the
|
||||
Retroactively, text mode is now called protocol 0, and binary mode
|
||||
protocol 1. The new protocol is called protocol 2. In the
|
||||
tradition of pickling protocols, protocol 2 is a superset of
|
||||
protocol 1. But just so that future pickling protocols aren't
|
||||
required to be supersets of the oldest protocols, a new opcode is
|
||||
inserted at the start of a protocol 2 pickle indicating that it is
|
||||
using protocol 2.
|
||||
using protocol 2. To date, each release of Python has been able to
|
||||
read pickles written by all previous releases. Of course pickles
|
||||
written under protocol N can't be read by versions of Python
|
||||
earlier than the one that introduced protocol N.
|
||||
|
||||
Several functions, methods and constructors used for pickling used
|
||||
to take a positional argument named 'bin' which was a flag,
|
||||
defaulting to 0, indicating binary mode. This argument is renamed
|
||||
to 'proto' and now gives the protocol number, defaulting to 0.
|
||||
to 'proto' and now gives the protocol number, still defaulting to 0.
|
||||
|
||||
It so happens that passing 2 for the 'bin' argument in previous
|
||||
Python versions had the same effect as passing 1. Nevertheless, a
|
||||
special case is added here: passing a negative number selects the
|
||||
special case is added here: passing a negative number selects the
|
||||
highest protocol version supported by a particular implementation.
|
||||
This works in previous Python versions, too.
|
||||
|
||||
|
|
Loading…
Reference in New Issue