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
5e36ad39
Commit
5e36ad39
authored
Jan 29, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pickle: Comment repair.
pickletools: Import decode_long from pickle instead of duplicating it.
parent
213608df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
27 deletions
+11
-27
Lib/pickle.py
Lib/pickle.py
+9
-4
Lib/pickletools.py
Lib/pickletools.py
+2
-23
No files found.
Lib/pickle.py
View file @
5e36ad39
...
...
@@ -37,7 +37,7 @@ import warnings
__all__
=
[
"PickleError"
,
"PicklingError"
,
"UnpicklingError"
,
"Pickler"
,
"Unpickler"
,
"dump"
,
"dumps"
,
"load"
,
"loads"
]
# These are purely informational; no code us
ues these
# These are purely informational; no code us
es these.
format_version
=
"2.0"
# File format version we write
compatible_formats
=
[
"1.0"
,
# Original protocol 0
"1.1"
,
# Protocol 0 with INST added
...
...
@@ -47,7 +47,7 @@ compatible_formats = ["1.0", # Original protocol 0
]
# Old format versions we can read
# Why use struct.pack() for pickling but marshal.loads() for
# unpickling? struct.pack() is 40% faster than marshal.
load
s(), but
# unpickling? struct.pack() is 40% faster than marshal.
dump
s(), but
# marshal.loads() is twice as fast as struct.unpack()!
mloads
=
marshal
.
loads
...
...
@@ -73,6 +73,8 @@ class UnpicklingError(PickleError):
"""
pass
# An instance of _Stop is raised by Unpickler.load_stop() in response to
# the STOP opcode, passing the object that is the result of unpickling.
class
_Stop
(
Exception
):
def
__init__
(
self
,
value
):
self
.
value
=
value
...
...
@@ -138,7 +140,7 @@ BINFLOAT = 'G' # push float; arg is 8-byte float encoding
TRUE
=
'I01
\
n
'
# not an opcode; see INT docs in pickletools.py
FALSE
=
'I00
\
n
'
# not an opcode; see INT docs in pickletools.py
# Protocol 2 (not yet implemented).
# Protocol 2 (
XXX
not yet implemented).
PROTO
=
'
\
x80
'
# identify pickle protocol
NEWOBJ
=
'
\
x81
'
# build object by applying cls.__new__ to argtuple
...
...
@@ -772,6 +774,9 @@ def _keep_alive(x, memo):
memo
[
id
(
memo
)]
=
[
x
]
# A cache for whichmodule(), mapping a function object to the name of
# the module in which the function was found.
classmap
=
{}
# called classmap for backwards compatibility
def
whichmodule
(
func
,
funcname
):
...
...
@@ -780,7 +785,7 @@ def whichmodule(func, funcname):
Search sys.modules for the module.
Cache in classmap.
Return a module name.
If the function cannot be found, return
__main__
.
If the function cannot be found, return
"__main__"
.
"""
if
func
in
classmap
:
return
classmap
[
func
]
...
...
Lib/pickletools.py
View file @
5e36ad39
...
...
@@ -603,29 +603,7 @@ float8 = ArgumentDescriptor(
# Protocol 2 formats
def
decode_long
(
data
):
r"""Decode a long from a two's complement little-endian binary string.
>>> decode_long("\xff\x00")
255L
>>> decode_long("\xff\x7f")
32767L
>>> decode_long("\x00\xff")
-256L
>>> decode_long("\x00\x80")
-32768L
>>> decode_long("\x80")
-128L
>>> decode_long("\x7f")
127L
"""
x
=
0L
i
=
0L
for
c
in
data
:
x
|=
long
(
ord
(
c
))
<<
i
i
+=
8L
if
data
and
ord
(
c
)
>=
0x80
:
x
-=
1L
<<
i
return
x
from
pickle
import
decode_long
def
read_long1
(
f
):
r"""
...
...
@@ -1793,6 +1771,7 @@ def assure_pickle_consistency(verbose=False):
raise
ValueError
(
"
\
n
"
.
join
(
msg
))
assure_pickle_consistency
()
del
assure_pickle_consistency
##############################################################################
# A pickle opcode generator.
...
...
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