Minor edits to the "Protocol versions" section.

This commit is contained in:
Tim Peters 2003-02-06 20:35:00 +00:00
parent 21a586e1b3
commit 17338a4481
1 changed files with 12 additions and 9 deletions

View File

@ -59,29 +59,32 @@ Motivation
Protocol versions Protocol versions
Previously, pickling (but not unpickling) has distinguished Previously, pickling (but not unpickling) distinguished between
between text mode and binary mode. By design, text mode is a text mode and binary mode. By design, binary mode is a
subset of binary mode, and unpicklers don't need to know in superset of text mode, and unpicklers don't need to know in
advance whether an incoming pickle uses text mode or binary mode. advance whether an incoming pickle uses text mode or binary mode.
The virtual machine used for unpickling is the same regardless of 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 Retroactively, text mode is now called protocol 0, and binary mode
called protocol 1. The new protocol is called protocol 2. In the protocol 1. The new protocol is called protocol 2. In the
tradition of pickling protocols, protocol 2 is a superset of tradition of pickling protocols, protocol 2 is a superset of
protocol 1. But just so that future pickling protocols aren't protocol 1. But just so that future pickling protocols aren't
required to be supersets of the oldest protocols, a new opcode is 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 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 Several functions, methods and constructors used for pickling used
to take a positional argument named 'bin' which was a flag, to take a positional argument named 'bin' which was a flag,
defaulting to 0, indicating binary mode. This argument is renamed 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 It so happens that passing 2 for the 'bin' argument in previous
Python versions had the same effect as passing 1. Nevertheless, a 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. highest protocol version supported by a particular implementation.
This works in previous Python versions, too. This works in previous Python versions, too.