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
b8b951f6
Commit
b8b951f6
authored
Sep 29, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added additional unpickling tests.
parent
c6b54b45
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
229 additions
and
37 deletions
+229
-37
Lib/test/pickletester.py
Lib/test/pickletester.py
+229
-37
No files found.
Lib/test/pickletester.py
View file @
b8b951f6
...
@@ -145,7 +145,7 @@ def create_dynamic_class(name, bases):
...
@@ -145,7 +145,7 @@ def create_dynamic_class(name, bases):
result
.
reduce_args
=
(
name
,
bases
)
result
.
reduce_args
=
(
name
,
bases
)
return
result
return
result
# DATA0 .. DATA
2
are the pickles we expect under the various protocols, for
# DATA0 .. DATA
4
are the pickles we expect under the various protocols, for
# the object returned by create_data().
# the object returned by create_data().
DATA0
=
(
DATA0
=
(
...
@@ -401,14 +401,164 @@ DATA2_DIS = """\
...
@@ -401,14 +401,164 @@ DATA2_DIS = """\
highest protocol among opcodes = 2
highest protocol among opcodes = 2
"""
"""
DATA3
=
(
b'
\
x80
\
x03
]q
\
x00
(K
\
x00
K
\
x01
G@
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
c'
b'builtins
\
n
complex
\
n
q
\
x01
G'
b'@
\
x08
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
G
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x86
q
\
x02
'
b'Rq
\
x03
K
\
x01
J
\
xff
\
xff
\
xff
\
xff
K
\
xff
J
\
x01
\
xff
\
xff
\
xff
J
\
x00
\
xff
'
b'
\
xff
\
xff
M
\
xff
\
xff
J
\
x01
\
x00
\
xff
\
xff
J
\
x00
\
x00
\
xff
\
xff
J
\
xff
\
xff
\
xff
\
x7f
'
b'J
\
x01
\
x00
\
x00
\
x80
J
\
x00
\
x00
\
x00
\
x80
(X
\
x03
\
x00
\
x00
\
x00
abcq'
b'
\
x04
h
\
x04
c__main__
\
n
C
\
n
q
\
x05
)
\
x81
q'
b'
\
x06
}q
\
x07
(X
\
x03
\
x00
\
x00
\
x00
barq
\
x08
K
\
x02
X
\
x03
\
x00
'
b'
\
x00
\
x00
fooq
\
t
K
\
x01
ubh
\
x06
tq
\
n
h
\
n
K
\
x05
'
b'e.'
)
# Disassembly of DATA3
DATA3_DIS
=
"""
\
0:
\
x80
PROTO 3
2: ] EMPTY_LIST
3: q BINPUT 0
5: ( MARK
6: K BININT1 0
8: K BININT1 1
10: G BINFLOAT 2.0
19: c GLOBAL 'builtins complex'
37: q BINPUT 1
39: G BINFLOAT 3.0
48: G BINFLOAT 0.0
57:
\
x86
TUPLE2
58: q BINPUT 2
60: R REDUCE
61: q BINPUT 3
63: K BININT1 1
65: J BININT -1
70: K BININT1 255
72: J BININT -255
77: J BININT -256
82: M BININT2 65535
85: J BININT -65535
90: J BININT -65536
95: J BININT 2147483647
100: J BININT -2147483647
105: J BININT -2147483648
110: ( MARK
111: X BINUNICODE 'abc'
119: q BINPUT 4
121: h BINGET 4
123: c GLOBAL '__main__ C'
135: q BINPUT 5
137: ) EMPTY_TUPLE
138:
\
x81
NEWOBJ
139: q BINPUT 6
141: } EMPTY_DICT
142: q BINPUT 7
144: ( MARK
145: X BINUNICODE 'bar'
153: q BINPUT 8
155: K BININT1 2
157: X BINUNICODE 'foo'
165: q BINPUT 9
167: K BININT1 1
169: u SETITEMS (MARK at 144)
170: b BUILD
171: h BINGET 6
173: t TUPLE (MARK at 110)
174: q BINPUT 10
176: h BINGET 10
178: K BININT1 5
180: e APPENDS (MARK at 5)
181: . STOP
highest protocol among opcodes = 2
"""
DATA4
=
(
b'
\
x80
\
x04
\
x95
\
xa8
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
]
\
x94
(K
\
x00
K
\
x01
G@'
b'
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x8c
\
x08
builtins
\
x94
\
x8c
\
x07
'
b'complex
\
x94
\
x93
\
x94
G@
\
x08
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
G'
b'
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
x86
\
x94
R
\
x94
K
\
x01
J
\
xff
\
xff
\
xff
\
xff
K'
b'
\
xff
J
\
x01
\
xff
\
xff
\
xff
J
\
x00
\
xff
\
xff
\
xff
M
\
xff
\
xff
J
\
x01
\
x00
\
xff
\
xff
J'
b'
\
x00
\
x00
\
xff
\
xff
J
\
xff
\
xff
\
xff
\
x7f
J
\
x01
\
x00
\
x00
\
x80
J
\
x00
\
x00
\
x00
\
x80
('
b'
\
x8c
\
x03
abc
\
x94
h
\
x06
\
x8c
\
x08
__main__
\
x94
\
x8c
'
b'
\
x01
C
\
x94
\
x93
\
x94
)
\
x81
\
x94
}
\
x94
(
\
x8c
\
x03
bar
\
x94
K
\
x02
\
x8c
'
b'
\
x03
foo
\
x94
K
\
x01
ubh
\
n
t
\
x94
h
\
x0e
K
\
x05
e.'
)
# Disassembly of DATA4
DATA4_DIS
=
"""
\
0:
\
x80
PROTO 4
2:
\
x95
FRAME 168
11: ] EMPTY_LIST
12:
\
x94
MEMOIZE
13: ( MARK
14: K BININT1 0
16: K BININT1 1
18: G BINFLOAT 2.0
27:
\
x8c
SHORT_BINUNICODE 'builtins'
37:
\
x94
MEMOIZE
38:
\
x8c
SHORT_BINUNICODE 'complex'
47:
\
x94
MEMOIZE
48:
\
x93
STACK_GLOBAL
49:
\
x94
MEMOIZE
50: G BINFLOAT 3.0
59: G BINFLOAT 0.0
68:
\
x86
TUPLE2
69:
\
x94
MEMOIZE
70: R REDUCE
71:
\
x94
MEMOIZE
72: K BININT1 1
74: J BININT -1
79: K BININT1 255
81: J BININT -255
86: J BININT -256
91: M BININT2 65535
94: J BININT -65535
99: J BININT -65536
104: J BININT 2147483647
109: J BININT -2147483647
114: J BININT -2147483648
119: ( MARK
120:
\
x8c
SHORT_BINUNICODE 'abc'
125:
\
x94
MEMOIZE
126: h BINGET 6
128:
\
x8c
SHORT_BINUNICODE '__main__'
138:
\
x94
MEMOIZE
139:
\
x8c
SHORT_BINUNICODE 'C'
142:
\
x94
MEMOIZE
143:
\
x93
STACK_GLOBAL
144:
\
x94
MEMOIZE
145: ) EMPTY_TUPLE
146:
\
x81
NEWOBJ
147:
\
x94
MEMOIZE
148: } EMPTY_DICT
149:
\
x94
MEMOIZE
150: ( MARK
151:
\
x8c
SHORT_BINUNICODE 'bar'
156:
\
x94
MEMOIZE
157: K BININT1 2
159:
\
x8c
SHORT_BINUNICODE 'foo'
164:
\
x94
MEMOIZE
165: K BININT1 1
167: u SETITEMS (MARK at 150)
168: b BUILD
169: h BINGET 10
171: t TUPLE (MARK at 119)
172:
\
x94
MEMOIZE
173: h BINGET 14
175: K BININT1 5
177: e APPENDS (MARK at 13)
178: . STOP
highest protocol among opcodes = 4
"""
# set([1,2]) pickled from 2.x with protocol 2
# set([1,2]) pickled from 2.x with protocol 2
DATA
3
=
b'
\
x80
\
x02
c__builtin__
\
n
set
\
n
q
\
x00
]q
\
x01
(K
\
x01
K
\
x02
e
\
x85
q
\
x02
Rq
\
x03
.'
DATA
_SET
=
b'
\
x80
\
x02
c__builtin__
\
n
set
\
n
q
\
x00
]q
\
x01
(K
\
x01
K
\
x02
e
\
x85
q
\
x02
Rq
\
x03
.'
# xrange(5) pickled from 2.x with protocol 2
# xrange(5) pickled from 2.x with protocol 2
DATA
4
=
b'
\
x80
\
x02
c__builtin__
\
n
xrange
\
n
q
\
x00
K
\
x00
K
\
x05
K
\
x01
\
x87
q
\
x01
Rq
\
x02
.'
DATA
_XRANGE
=
b'
\
x80
\
x02
c__builtin__
\
n
xrange
\
n
q
\
x00
K
\
x00
K
\
x05
K
\
x01
\
x87
q
\
x01
Rq
\
x02
.'
# a SimpleCookie() object pickled from 2.x with protocol 2
# a SimpleCookie() object pickled from 2.x with protocol 2
DATA
5
=
(
b'
\
x80
\
x02
cCookie
\
n
SimpleCookie
\
n
q
\
x00
)
\
x81
q
\
x01
U
\
x03
key'
DATA
_COOKIE
=
(
b'
\
x80
\
x02
cCookie
\
n
SimpleCookie
\
n
q
\
x00
)
\
x81
q
\
x01
U
\
x03
key'
b'q
\
x02
cCookie
\
n
Morsel
\
n
q
\
x03
)
\
x81
q
\
x04
(U
\
x07
commentq
\
x05
U'
b'q
\
x02
cCookie
\
n
Morsel
\
n
q
\
x03
)
\
x81
q
\
x04
(U
\
x07
commentq
\
x05
U'
b'
\
x00
q
\
x06
U
\
x06
domainq
\
x07
h
\
x06
U
\
x06
secureq
\
x08
h
\
x06
U
\
x07
'
b'
\
x00
q
\
x06
U
\
x06
domainq
\
x07
h
\
x06
U
\
x06
secureq
\
x08
h
\
x06
U
\
x07
'
b'expiresq
\
t
h
\
x06
U
\
x07
max-ageq
\
n
h
\
x06
U
\
x07
versionq
\
x0b
h
\
x06
U'
b'expiresq
\
t
h
\
x06
U
\
x07
max-ageq
\
n
h
\
x06
U
\
x07
versionq
\
x0b
h
\
x06
U'
...
@@ -416,7 +566,7 @@ DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key'
...
@@ -416,7 +566,7 @@ DATA5 = (b'\x80\x02cCookie\nSimpleCookie\nq\x00)\x81q\x01U\x03key'
b'coded_valueq
\
x0f
U
\
x05
valueq
\
x10
h
\
x10
h
\
x10
h
\
x02
h
\
x02
ubs}q
\
x11
b.'
)
b'coded_valueq
\
x0f
U
\
x05
valueq
\
x10
h
\
x10
h
\
x10
h
\
x02
h
\
x02
ubs}q
\
x11
b.'
)
# set([3]) pickled from 2.x with protocol 2
# set([3]) pickled from 2.x with protocol 2
DATA
6
=
b'
\
x80
\
x02
c__builtin__
\
n
set
\
n
q
\
x00
]q
\
x01
K
\
x03
a
\
x85
q
\
x02
Rq
\
x03
.'
DATA
_SET2
=
b'
\
x80
\
x02
c__builtin__
\
n
set
\
n
q
\
x00
]q
\
x01
K
\
x03
a
\
x85
q
\
x02
Rq
\
x03
.'
python2_exceptions_without_args
=
(
python2_exceptions_without_args
=
(
ArithmeticError
,
ArithmeticError
,
...
@@ -468,18 +618,8 @@ python2_exceptions_without_args = (
...
@@ -468,18 +618,8 @@ python2_exceptions_without_args = (
exception_pickle
=
b'
\
x80
\
x02
cexceptions
\
n
?
\
n
q
\
x00
)Rq
\
x01
.'
exception_pickle
=
b'
\
x80
\
x02
cexceptions
\
n
?
\
n
q
\
x00
)Rq
\
x01
.'
# Exception objects without arguments pickled from 2.x with protocol 2
DATA7
=
{
exception
:
exception_pickle
.
replace
(
b'?'
,
exception
.
__name__
.
encode
(
"ascii"
))
for
exception
in
python2_exceptions_without_args
}
# StandardError is mapped to Exception, test that separately
DATA8
=
exception_pickle
.
replace
(
b'?'
,
b'StandardError'
)
# UnicodeEncodeError object pickled from 2.x with protocol 2
# UnicodeEncodeError object pickled from 2.x with protocol 2
DATA
9
=
(
b'
\
x80
\
x02
cexceptions
\
n
UnicodeEncodeError
\
n
'
DATA
_UEERR
=
(
b'
\
x80
\
x02
cexceptions
\
n
UnicodeEncodeError
\
n
'
b'q
\
x00
(U
\
x05
asciiq
\
x01
X
\
x03
\
x00
\
x00
\
x00
fooq
\
x02
K
\
x00
K
\
x01
'
b'q
\
x00
(U
\
x05
asciiq
\
x01
X
\
x03
\
x00
\
x00
\
x00
fooq
\
x02
K
\
x00
K
\
x01
'
b'U
\
x03
badq
\
x03
tq
\
x04
Rq
\
x05
.'
)
b'U
\
x03
badq
\
x03
tq
\
x04
Rq
\
x05
.'
)
...
@@ -537,6 +677,12 @@ class AbstractUnpickleTests(unittest.TestCase):
...
@@ -537,6 +677,12 @@ class AbstractUnpickleTests(unittest.TestCase):
def
test_load_from_data2
(
self
):
def
test_load_from_data2
(
self
):
self
.
assert_is_copy
(
self
.
_testdata
,
self
.
loads
(
DATA2
))
self
.
assert_is_copy
(
self
.
_testdata
,
self
.
loads
(
DATA2
))
def
test_load_from_data3
(
self
):
self
.
assert_is_copy
(
self
.
_testdata
,
self
.
loads
(
DATA3
))
def
test_load_from_data4
(
self
):
self
.
assert_is_copy
(
self
.
_testdata
,
self
.
loads
(
DATA4
))
def
test_load_classic_instance
(
self
):
def
test_load_classic_instance
(
self
):
# See issue5180. Test loading 2.x pickles that
# See issue5180. Test loading 2.x pickles that
# contain an instance of old style class.
# contain an instance of old style class.
...
@@ -594,11 +740,6 @@ class AbstractUnpickleTests(unittest.TestCase):
...
@@ -594,11 +740,6 @@ class AbstractUnpickleTests(unittest.TestCase):
b'q
\
x00
oq
\
x01
}q
\
x02
b.'
).
replace
(
b'X'
,
xname
)
b'q
\
x00
oq
\
x01
}q
\
x02
b.'
).
replace
(
b'X'
,
xname
)
self
.
assert_is_copy
(
X
(
*
args
),
self
.
loads
(
pickle2
))
self
.
assert_is_copy
(
X
(
*
args
),
self
.
loads
(
pickle2
))
def
test_get
(
self
):
self
.
assertRaises
(
KeyError
,
self
.
loads
,
b'g0
\
n
p0'
)
self
.
assert_is_copy
([(
100
,),
(
100
,)],
self
.
loads
(
b'((Kdtp0
\
n
h
\
x00
l.))'
))
def
test_maxint64
(
self
):
def
test_maxint64
(
self
):
maxint64
=
(
1
<<
63
)
-
1
maxint64
=
(
1
<<
63
)
-
1
data
=
b'I'
+
str
(
maxint64
).
encode
(
"ascii"
)
+
b'
\
n
.'
data
=
b'I'
+
str
(
maxint64
).
encode
(
"ascii"
)
+
b'
\
n
.'
...
@@ -616,24 +757,27 @@ class AbstractUnpickleTests(unittest.TestCase):
...
@@ -616,24 +757,27 @@ class AbstractUnpickleTests(unittest.TestCase):
def
test_unpickle_from_2x
(
self
):
def
test_unpickle_from_2x
(
self
):
# Unpickle non-trivial data from Python 2.x.
# Unpickle non-trivial data from Python 2.x.
loaded
=
self
.
loads
(
DATA
3
)
loaded
=
self
.
loads
(
DATA
_SET
)
self
.
assertEqual
(
loaded
,
set
([
1
,
2
]))
self
.
assertEqual
(
loaded
,
set
([
1
,
2
]))
loaded
=
self
.
loads
(
DATA
4
)
loaded
=
self
.
loads
(
DATA
_XRANGE
)
self
.
assertEqual
(
type
(
loaded
),
type
(
range
(
0
)))
self
.
assertEqual
(
type
(
loaded
),
type
(
range
(
0
)))
self
.
assertEqual
(
list
(
loaded
),
list
(
range
(
5
)))
self
.
assertEqual
(
list
(
loaded
),
list
(
range
(
5
)))
loaded
=
self
.
loads
(
DATA
5
)
loaded
=
self
.
loads
(
DATA
_COOKIE
)
self
.
assertEqual
(
type
(
loaded
),
SimpleCookie
)
self
.
assertEqual
(
type
(
loaded
),
SimpleCookie
)
self
.
assertEqual
(
list
(
loaded
.
keys
()),
[
"key"
])
self
.
assertEqual
(
list
(
loaded
.
keys
()),
[
"key"
])
self
.
assertEqual
(
loaded
[
"key"
].
value
,
"value"
)
self
.
assertEqual
(
loaded
[
"key"
].
value
,
"value"
)
for
(
exc
,
data
)
in
DATA7
.
items
():
# Exception objects without arguments pickled from 2.x with protocol 2
for
exc
in
python2_exceptions_without_args
:
data
=
exception_pickle
.
replace
(
b'?'
,
exc
.
__name__
.
encode
(
"ascii"
))
loaded
=
self
.
loads
(
data
)
loaded
=
self
.
loads
(
data
)
self
.
assertIs
(
type
(
loaded
),
exc
)
self
.
assertIs
(
type
(
loaded
),
exc
)
loaded
=
self
.
loads
(
DATA8
)
# StandardError is mapped to Exception, test that separately
loaded
=
self
.
loads
(
exception_pickle
.
replace
(
b'?'
,
b'StandardError'
))
self
.
assertIs
(
type
(
loaded
),
Exception
)
self
.
assertIs
(
type
(
loaded
),
Exception
)
loaded
=
self
.
loads
(
DATA
9
)
loaded
=
self
.
loads
(
DATA
_UEERR
)
self
.
assertIs
(
type
(
loaded
),
UnicodeEncodeError
)
self
.
assertIs
(
type
(
loaded
),
UnicodeEncodeError
)
self
.
assertEqual
(
loaded
.
object
,
"foo"
)
self
.
assertEqual
(
loaded
.
object
,
"foo"
)
self
.
assertEqual
(
loaded
.
encoding
,
"ascii"
)
self
.
assertEqual
(
loaded
.
encoding
,
"ascii"
)
...
@@ -670,11 +814,26 @@ class AbstractUnpickleTests(unittest.TestCase):
...
@@ -670,11 +814,26 @@ class AbstractUnpickleTests(unittest.TestCase):
b'x'
*
300
+
pickle
.
STOP
,
b'x'
*
300
+
pickle
.
STOP
,
encoding
=
'bytes'
),
b'x'
*
300
)
encoding
=
'bytes'
),
b'x'
*
300
)
def
test_constants
(
self
):
self
.
assertIsNone
(
self
.
loads
(
b'N.'
))
self
.
assertIs
(
self
.
loads
(
b'
\
x88
.'
),
True
)
self
.
assertIs
(
self
.
loads
(
b'
\
x89
.'
),
False
)
self
.
assertIs
(
self
.
loads
(
b'I01
\
n
.'
),
True
)
self
.
assertIs
(
self
.
loads
(
b'I00
\
n
.'
),
False
)
def
test_empty_bytestring
(
self
):
def
test_empty_bytestring
(
self
):
# issue 11286
# issue 11286
empty
=
self
.
loads
(
b'
\
x80
\
x03
U
\
x00
q
\
x00
.'
,
encoding
=
'koi8-r'
)
empty
=
self
.
loads
(
b'
\
x80
\
x03
U
\
x00
q
\
x00
.'
,
encoding
=
'koi8-r'
)
self
.
assertEqual
(
empty
,
''
)
self
.
assertEqual
(
empty
,
''
)
def
test_short_binbytes
(
self
):
dumped
=
b'
\
x80
\
x03
C
\
x04
\
xe2
\
x82
\
xac
\
x00
.'
self
.
assertEqual
(
self
.
loads
(
dumped
),
b'
\
xe2
\
x82
\
xac
\
x00
'
)
def
test_binbytes
(
self
):
dumped
=
b'
\
x80
\
x03
B
\
x04
\
x00
\
x00
\
x00
\
xe2
\
x82
\
xac
\
x00
.'
self
.
assertEqual
(
self
.
loads
(
dumped
),
b'
\
xe2
\
x82
\
xac
\
x00
'
)
@
requires_32b
@
requires_32b
def
test_negative_32b_binbytes
(
self
):
def
test_negative_32b_binbytes
(
self
):
# On 32-bit builds, a BINBYTES of 2**31 or more is refused
# On 32-bit builds, a BINBYTES of 2**31 or more is refused
...
@@ -689,6 +848,39 @@ class AbstractUnpickleTests(unittest.TestCase):
...
@@ -689,6 +848,39 @@ class AbstractUnpickleTests(unittest.TestCase):
with
self
.
assertRaises
((
pickle
.
UnpicklingError
,
OverflowError
)):
with
self
.
assertRaises
((
pickle
.
UnpicklingError
,
OverflowError
)):
self
.
loads
(
dumped
)
self
.
loads
(
dumped
)
def
test_short_binunicode
(
self
):
dumped
=
b'
\
x80
\
x04
\
x8c
\
x04
\
xe2
\
x82
\
xac
\
x00
.'
self
.
assertEqual
(
self
.
loads
(
dumped
),
'
\
u20ac
\
x00
'
)
def
test_misc_get
(
self
):
self
.
assertRaises
(
KeyError
,
self
.
loads
,
b'g0
\
n
p0'
)
self
.
assert_is_copy
([(
100
,),
(
100
,)],
self
.
loads
(
b'((Kdtp0
\
n
h
\
x00
l.))'
))
def
test_get
(
self
):
pickled
=
b'((lp100000
\
n
g100000
\
n
t.'
unpickled
=
self
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
([],)
*
2
)
self
.
assertIs
(
unpickled
[
0
],
unpickled
[
1
])
def
test_binget
(
self
):
pickled
=
b'(]q
\
xff
h
\
xff
t.'
unpickled
=
self
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
([],)
*
2
)
self
.
assertIs
(
unpickled
[
0
],
unpickled
[
1
])
def
test_long_binget
(
self
):
pickled
=
b'(]r
\
x00
\
x00
\
x01
\
x00
j
\
x00
\
x00
\
x01
\
x00
t.'
unpickled
=
self
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
([],)
*
2
)
self
.
assertIs
(
unpickled
[
0
],
unpickled
[
1
])
def
test_dup
(
self
):
pickled
=
b'((l2t.'
unpickled
=
self
.
loads
(
pickled
)
self
.
assertEqual
(
unpickled
,
([],)
*
2
)
self
.
assertIs
(
unpickled
[
0
],
unpickled
[
1
])
def
test_negative_put
(
self
):
def
test_negative_put
(
self
):
# Issue #12847
# Issue #12847
dumped
=
b'Va
\
n
p-1
\
n
.'
dumped
=
b'Va
\
n
p-1
\
n
.'
...
@@ -1455,9 +1647,9 @@ class AbstractPickleTests(unittest.TestCase):
...
@@ -1455,9 +1647,9 @@ class AbstractPickleTests(unittest.TestCase):
# NOTE: this test is a bit too strong since we can produce different
# NOTE: this test is a bit too strong since we can produce different
# bytecode that 2.x will still understand.
# bytecode that 2.x will still understand.
dumped
=
self
.
dumps
(
range
(
5
),
2
)
dumped
=
self
.
dumps
(
range
(
5
),
2
)
self
.
assertEqual
(
dumped
,
DATA
4
)
self
.
assertEqual
(
dumped
,
DATA
_XRANGE
)
dumped
=
self
.
dumps
(
set
([
3
]),
2
)
dumped
=
self
.
dumps
(
set
([
3
]),
2
)
self
.
assertEqual
(
dumped
,
DATA
6
)
self
.
assertEqual
(
dumped
,
DATA
_SET2
)
def
test_large_pickles
(
self
):
def
test_large_pickles
(
self
):
# Test the correctness of internal buffering routines when handling
# Test the correctness of internal buffering routines when handling
...
@@ -2312,7 +2504,7 @@ if __name__ == "__main__":
...
@@ -2312,7 +2504,7 @@ if __name__ == "__main__":
# Print some stuff that can be used to rewrite DATA{0,1,2}
# Print some stuff that can be used to rewrite DATA{0,1,2}
from
pickletools
import
dis
from
pickletools
import
dis
x
=
create_data
()
x
=
create_data
()
for
i
in
range
(
3
):
for
i
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
p
=
pickle
.
dumps
(
x
,
i
)
p
=
pickle
.
dumps
(
x
,
i
)
print
(
"DATA{0} = ("
.
format
(
i
))
print
(
"DATA{0} = ("
.
format
(
i
))
for
j
in
range
(
0
,
len
(
p
),
20
):
for
j
in
range
(
0
,
len
(
p
),
20
):
...
...
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