Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
ee4df920
Commit
ee4df920
authored
Jun 07, 2013
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip protocol header from pickles where protocol > 1.
parent
95426303
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
src/ZODB/tests/testUtils.py
src/ZODB/tests/testUtils.py
+39
-8
src/ZODB/utils.py
src/ZODB/utils.py
+3
-0
No files found.
src/ZODB/tests/testUtils.py
View file @
ee4df920
...
...
@@ -41,7 +41,7 @@ class TestUtils(unittest.TestCase):
for i in range(NUM)]
all = small + large
def
check
LongToStringToLong(self):
def
test_
LongToStringToLong(self):
for num in self.all:
s = p64(num)
n = U64(s)
...
...
@@ -49,7 +49,7 @@ class TestUtils(unittest.TestCase):
n2 = u64(s)
self.assertEqual(num, n2, "
u64
()
failed
")
def
check
KnownConstants(self):
def
test_
KnownConstants(self):
self.assertEqual(b"
\
000
\
000
\
000
\
000
\
000
\
000
\
000
\
001
", p64(1))
self.assertEqual(b"
\
000
\
000
\
000
\
001
\
000
\
000
\
000
\
000
", p64(1<<32))
self.assertEqual(u64(b"
\
000
\
000
\
000
\
000
\
000
\
000
\
000
\
001
"), 1)
...
...
@@ -57,7 +57,7 @@ class TestUtils(unittest.TestCase):
self.assertEqual(u64(b"
\
000
\
000
\
000
\
001
\
000
\
000
\
000
\
000
"), 1<<32)
self.assertEqual(U64(b"
\
000
\
000
\
000
\
001
\
000
\
000
\
000
\
000
"), 1<<32)
def
check
PersistentIdHandlesDescriptor(self):
def
test_
PersistentIdHandlesDescriptor(self):
from ZODB.serialize import ObjectWriter
class P(Persistent):
pass
...
...
@@ -70,7 +70,7 @@ class TestUtils(unittest.TestCase):
# deduce the class path from a pickle, instead of actually loading
# the pickle (and so also trying to import application module and
# class objects, which isn't a good idea on a ZEO server when avoidable).
def
check
ConflictErrorDoesntImport(self):
def
test_
ConflictErrorDoesntImport(self):
from ZODB.serialize import ObjectWriter
from ZODB.POSException import ConflictError
from ZODB.tests.MinPO import MinPO
...
...
@@ -98,9 +98,40 @@ class TestUtils(unittest.TestCase):
else:
self.fail("
expected
ConflictError
,
but
no
exception
raised
")
def test_get_pickle_metadata_w_protocol_0_class_pickle(self):
from ZODB.utils import get_pickle_metadata
from ZODB._compat import dumps
pickle = dumps(ExampleClass, protocol=0)
self.assertEqual(get_pickle_metadata(pickle),
(__name__, ExampleClass.__name__))
def test_get_pickle_metadata_w_protocol_1_class_pickle(self):
from ZODB.utils import get_pickle_metadata
from ZODB._compat import dumps
pickle = dumps(ExampleClass, protocol=1)
self.assertEqual(get_pickle_metadata(pickle),
(__name__, ExampleClass.__name__))
def test_get_pickle_metadata_w_protocol_2_class_pickle(self):
from ZODB.utils import get_pickle_metadata
from ZODB._compat import dumps
pickle = dumps(ExampleClass, protocol=2)
self.assertEqual(get_pickle_metadata(pickle),
(__name__, ExampleClass.__name__))
def test_get_pickle_metadata_w_protocol_3_class_pickle(self):
from ZODB.utils import get_pickle_metadata
from ZODB._compat import dumps
pickle = dumps(ExampleClass, protocol=3)
self.assertEqual(get_pickle_metadata(pickle),
(__name__, ExampleClass.__name__))
class ExampleClass(object):
pass
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestUtils, 'check'))
suite.addTest(doctest.DocFileSuite('../utils.txt', checker=checker))
return suite
return unittest.TestSuite((
unittest.makeSuite(TestUtils),
doctest.DocFileSuite('../utils.txt', checker=checker),
))
src/ZODB/utils.py
View file @
ee4df920
...
...
@@ -217,6 +217,9 @@ def get_pickle_metadata(data):
# ZODB's data records contain two pickles. The first is the class
# of the object, the second is the object. We're only trying to
# pick apart the first here, to extract the module and class names.
if
data
[
0
]
==
0x80
:
# protocol marker, protocol > 1
protocol
=
data
[
1
]
data
=
data
[
2
:]
if
data
.
startswith
(
b'(c'
):
# pickle MARK GLOBAL opcode sequence
global_prefix
=
2
elif
data
.
startswith
(
b'c'
):
# pickle GLOBAL opcode
...
...
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