Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3489cad3
Commit
3489cad3
authored
Dec 05, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed the deprecated bin parameter from the pickle module.
parent
4ebe3642
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
45 deletions
+18
-45
Doc/lib/libpickle.tex
Doc/lib/libpickle.tex
+11
-34
Lib/pickle.py
Lib/pickle.py
+5
-11
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/lib/libpickle.tex
View file @
3489cad3
...
...
@@ -144,14 +144,10 @@ If \var{protocol} is specified as a negative value
or
\constant
{
HIGHEST
_
PROTOCOL
}
,
the highest protocol version available will be used.
\versionchanged
[The
\var
{
bin
}
parameter is deprecated and only provided
for backwards compatibility. You should use the
\var
{
protocol
}
parameter instead]
{
2.3
}
\versionchanged
[Introduced the \var{protocol} parameter]
{
2.3
}
A binary format, which is slightly more efficient, can be chosen by
specifying a true value for the
\var
{
bin
}
argument to the
\class
{
Pickler
}
constructor or the
\function
{
dump()
}
and
\function
{
dumps()
}
functions. A
\var
{
protocol
}
version >= 1 implies use of a binary format.
specifying a
\var
{
protocol
}
version >= 1.
\subsection
{
Usage
}
...
...
@@ -170,24 +166,17 @@ as a \var{protocol} value.
The
\module
{
pickle
}
module provides the
following functions to make this process more convenient:
\begin{funcdesc}
{
dump
}{
obj, file
\optional
{
, protocol
\optional
{
, bin
}
}}
\begin{funcdesc}
{
dump
}{
obj, file
\optional
{
, protocol
}}
Write a pickled representation of
\var
{
obj
}
to the open file object
\var
{
file
}
. This is equivalent to
\code
{
Pickler(
\var
{
file
}
,
\var
{
protocol
}
,
\var
{
bin
}
).dump(
\var
{
obj
}
)
}
.
\code
{
Pickler(
\var
{
file
}
,
\var
{
protocol
}
).dump(
\var
{
obj
}
)
}
.
If the
\var
{
protocol
}
parameter is omitted, protocol 0 is used.
If
\var
{
protocol
}
is specified as a negative value
or
\constant
{
HIGHEST
_
PROTOCOL
}
,
the highest protocol version will be used.
\versionchanged
[The
\var
{
protocol
}
parameter was added.
The
\var
{
bin
}
parameter is deprecated and only provided
for backwards compatibility. You should use the
\var
{
protocol
}
parameter instead]
{
2.3
}
If the optional
\var
{
bin
}
argument is true, the binary pickle format
is used; otherwise the (less efficient) text pickle format is used
(for backwards compatibility, this is the default).
\versionchanged
[Introduced the \var{protocol} parameter]
{
2.3
}
\var
{
file
}
must have a
\method
{
write()
}
method that accepts a single
string argument. It can thus be a file object opened for writing, a
...
...
@@ -211,7 +200,7 @@ This function automatically determines whether the data stream was
written in binary mode or not.
\end{funcdesc}
\begin{funcdesc}
{
dumps
}{
obj
\optional
{
, protocol
\optional
{
, bin
}
}}
\begin{funcdesc}
{
dumps
}{
obj
\optional
{
, protocol
}}
Return the pickled representation of the object as a string, instead
of writing it to a file.
...
...
@@ -220,14 +209,8 @@ If \var{protocol} is specified as a negative value
or
\constant
{
HIGHEST
_
PROTOCOL
}
,
the highest protocol version will be used.
\versionchanged
[The
\var
{
protocol
}
parameter was added.
The
\var
{
bin
}
parameter is deprecated and only provided
for backwards compatibility. You should use the
\var
{
protocol
}
parameter instead]
{
2.3
}
\versionchanged
[The \var{protocol} parameter was added]
{
2.3
}
If the optional
\var
{
bin
}
argument is
true, the binary pickle format is used; otherwise the (less efficient)
text pickle format is used (this is the default).
\end{funcdesc}
\begin{funcdesc}
{
loads
}{
string
}
...
...
@@ -262,7 +245,7 @@ subclassed. One common reason to subclass is to control what
objects can actually be unpickled. See section~
\ref
{
pickle-sub
}
for
more details.
}
,
\class
{
Pickler
}
and
\class
{
Unpickler
}
:
\begin{classdesc}
{
Pickler
}{
file
\optional
{
, protocol
\optional
{
, bin
}
}}
\begin{classdesc}
{
Pickler
}{
file
\optional
{
, protocol
}}
This takes a file-like object to which it will write a pickle data
stream.
...
...
@@ -270,13 +253,7 @@ If the \var{protocol} parameter is omitted, protocol 0 is used.
If
\var
{
protocol
}
is specified as a negative value,
the highest protocol version will be used.
\versionchanged
[The
\var
{
bin
}
parameter is deprecated and only provided
for backwards compatibility. You should use the
\var
{
protocol
}
parameter instead]
{
2.3
}
Optional
\var
{
bin
}
if true, tells the pickler to use the more
efficient binary pickle format, otherwise the
\ASCII
{}
format is used
(this is the default).
\versionchanged
[Introduced the \var{protocol} parameter]
{
2.3
}
\var
{
file
}
must have a
\method
{
write()
}
method that accepts a single
string argument. It can thus be an open file object, a
...
...
@@ -289,7 +266,7 @@ object that meets this interface.
\begin{methoddesc}
[Pickler]
{
dump
}{
obj
}
Write a pickled representation of
\var
{
obj
}
to the open file object
given in the constructor. Either the binary or
\ASCII
{}
format will
be used, depending on the value of the
\var
{
bin
}
flag
passed to the
be used, depending on the value of the
\var
{
protocol
}
argument
passed to the
constructor.
\end{methoddesc}
...
...
@@ -451,7 +428,7 @@ method is normally \emph{not} invoked. If it is desirable that the
\method
{__
init
__
()
}
method be called on unpickling, an old-style class
can define a method
\method
{__
getinitargs
__
()
}
, which should return a
\emph
{
tuple
}
containing the arguments to be passed to the class
constructor (
i.e.
\method
{__
init
__
()
}
). The
constructor (
\method
{__
init
__
()
}
for example
). The
\method
{__
getinitargs
__
()
}
method is called at
pickle time; the tuple it returns is incorporated in the pickle for
the instance.
...
...
Lib/pickle.py
View file @
3489cad3
...
...
@@ -171,7 +171,7 @@ del x
class
Pickler
:
def
__init__
(
self
,
file
,
protocol
=
None
,
bin
=
None
):
def
__init__
(
self
,
file
,
protocol
=
None
):
"""This takes a file-like object for writing a pickle data stream.
The optional protocol argument tells the pickler to use the
...
...
@@ -195,12 +195,6 @@ class Pickler:
object, or any other custom object that meets this interface.
"""
if
protocol
is
not
None
and
bin
is
not
None
:
raise
ValueError
,
"can't specify both 'protocol' and 'bin'"
if
bin
is
not
None
:
warnings
.
warn
(
"The 'bin' argument to Pickler() is deprecated"
,
DeprecationWarning
)
protocol
=
bin
if
protocol
is
None
:
protocol
=
0
if
protocol
<
0
:
...
...
@@ -1378,12 +1372,12 @@ try:
except
ImportError
:
from
StringIO
import
StringIO
def
dump
(
obj
,
file
,
protocol
=
None
,
bin
=
None
):
Pickler
(
file
,
protocol
,
bin
).
dump
(
obj
)
def
dump
(
obj
,
file
,
protocol
=
None
):
Pickler
(
file
,
protocol
).
dump
(
obj
)
def
dumps
(
obj
,
protocol
=
None
,
bin
=
None
):
def
dumps
(
obj
,
protocol
=
None
):
file
=
StringIO
()
Pickler
(
file
,
protocol
,
bin
).
dump
(
obj
)
Pickler
(
file
,
protocol
).
dump
(
obj
)
return
file
.
getvalue
()
def
load
(
file
):
...
...
Misc/NEWS
View file @
3489cad3
...
...
@@ -21,6 +21,8 @@ Extension Modules
Library
-------
- the pickle module no longer uses the deprecated bin parameter.
- the depecated statcache module was removed.
- the shelve module no longer uses the deprecated binary parameter.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment