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
14d535c3
Commit
14d535c3
authored
Aug 07, 2004
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bug #984952] Include some material from PEP 307
parent
2b3feec5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
4 deletions
+35
-4
Doc/lib/libpickle.tex
Doc/lib/libpickle.tex
+35
-4
No files found.
Doc/lib/libpickle.tex
View file @
14d535c3
...
...
@@ -515,8 +515,8 @@ time \method{__reduce__()} will be called with no arguments, and it
must return either a string or a tuple.
If a string is returned, it names a global variable whose contents are
pickled as normal. When a tuple is returned, it must be
of length
two
or three
, with the following semantics:
pickled as normal. When a tuple is returned, it must be
between
two
and five elements long
, with the following semantics:
\begin{itemize}
...
...
@@ -530,7 +530,6 @@ or three, with the following semantics:
\item
A tuple of arguments for the callable object, or
\code
{
None
}
.
\deprecated
{
2.3
}{
Use the tuple of arguments instead
}
\item
Optionally, the object's state, which will be passed to
the object's
\method
{__
setstate
__
()
}
method as described in
section~
\ref
{
pickle-inst
}
. If the object has no
...
...
@@ -538,6 +537,23 @@ or three, with the following semantics:
be a dictionary and it will be added to the object's
\member
{__
dict
__}
.
\item
Optionally, an iterator (and not a sequence) yielding successive
list items. These list items will be pickled, and appended to the
object using either
\code
{
obj.append(
\var
{
item
}
)
}
or
\code
{
obj.extend(
\var
{
list
_
of
_
items
}
)
}
. This is primarily used for
list subclasses, but may be used by other classes as long as they have
\method
{
append()
}
and
\method
{
extend()
}
methods with the appropriate
signature. (Whether
\method
{
append()
}
or
\method
{
extend()
}
is used
depends on which pickle protocol version is used as well as the number
of items to append, so both must be supported.)
\item
Optionally, an iterator (not a sequence)
yielding successive dictionary items, which should be tuples of the
form
\code
{
(
\var
{
key
}
,
\var
{
value
}
)
}
. These items will be pickled
and stored to the object using
\code
{
obj[
\var
{
key
}
] =
\var
{
value
}}
.
This is primarily used for dictionary subclasses, but may be used by
other classes as long as they implement
\method
{__
setitem
__}
.
\end{itemize}
Upon unpickling, the callable will be called (provided that it meets
...
...
@@ -559,7 +575,22 @@ interface as the \method{__reduce__()} method described above, except
that they are called with a single argument, the object to be pickled.
The registered constructor is deemed a ``safe constructor'' for purposes
of unpickling as described above.
It is sometimes useful to know the protocol version when implementing
\method
{__
reduce
__}
. This can be done by implementing a method named
\method
{__
reduce
_
ex
__}
instead of
\method
{__
reduce
__}
.
\method
{__
reduce
_
ex
__}
, when it exists, is called in preference over
\method
{__
reduce
__}
(you may still provide
\method
{__
reduce
__}
for
backwards compatibility). The
\method
{__
reduce
_
ex
__}
method will be
called with a single integer argument, the protocol version.
The
\class
{
object
}
class implements both
\method
{__
reduce
__}
and
\method
{__
reduce
_
ex
__}
; however, if a subclass overrides
\method
{__
reduce
__}
but not
\method
{__
reduce
_
ex
__}
, the
\method
{__
reduce
_
ex
__}
implementation detects this and calls
\method
{__
reduce
__}
.
\subsubsection
{
Pickling and unpickling external objects
}
...
...
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