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
Kirill Smelkov
ZODB
Commits
1b1025ca
Commit
1b1025ca
authored
6 years ago
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p64 and p64 are faster and create more informative exceptions.
Fixes #216.
parent
6abde06a
y/poskeyerror-on-noobj
master
x/loadBefore-no-serial_next
x/zobjtrace
y/ZODB5-protocol1
y/demo-delete
y/loadAt
y/loadAt.1
y/loadAt.2
y/loadAt.3
y/loadAt.4
y/loadAt.5
y/loadAt.6
y/loadAt.7
y/loadAt.8
y/loadAt.9
5.6.0
5.5.1
5.5.0
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
13 deletions
+51
-13
CHANGES.rst
CHANGES.rst
+9
-4
src/ZODB/tests/testUtils.py
src/ZODB/tests/testUtils.py
+26
-4
src/ZODB/utils.py
src/ZODB/utils.py
+16
-5
No files found.
CHANGES.rst
View file @
1b1025ca
...
...
@@ -17,6 +17,11 @@
- Add support for Python 3.7.
- Make the internal support functions for dealing with OIDs (``p64``
and ``u64``) somewhat faster and raise more informative
exceptions on certain types of bad input. See `issue 216
<https://github.com/zopefoundation/ZODB/issues/216>`_.
5.4.0 (2018-03-26)
==================
...
...
This diff is collapsed.
Click to expand it.
src/ZODB/tests/testUtils.py
View file @
1b1025ca
...
...
@@ -128,12 +128,34 @@ class TestUtils(unittest.TestCase):
self.assertEqual(get_pickle_metadata(pickle),
(__name__, ExampleClass.__name__))
def test_p64_bad_object(self):
with self.assertRaises(ValueError) as exc:
p64(2 ** 65)
e = exc.exception
# The args will be whatever the struct.error args were,
# which vary from version to version and across implementations,
# followed by the bad value
self.assertEqual(e.args[-1], 2 ** 65)
def test_u64_bad_object(self):
with self.assertRaises(ValueError) as exc:
u64(b'123456789')
e = exc.exception
# The args will be whatever the struct.error args were,
# which vary from version to version and across implementations,
# followed by the bad value
self.assertEqual(e.args[-1], b'123456789')
class ExampleClass(object):
pass
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestUtils),
doctest.DocFileSuite('../utils.txt', checker=checker),
))
suite = unittest.defaultTestLoader.loadTestsFromName(__name__)
suite.addTest(
doctest.DocFileSuite('../utils.txt', checker=checker)
)
return suite
This diff is collapsed.
Click to expand it.
src/ZODB/utils.py
View file @
1b1025ca
...
...
@@ -18,10 +18,10 @@ import sys
import
time
import
threading
from
binascii
import
hexlify
,
unhexlify
from
struct
import
pack
,
unpack
from
tempfile
import
mkstemp
from
persistent.
TimeS
tamp
import
TimeStamp
from
persistent.
times
tamp
import
TimeStamp
from
ZODB._compat
import
Unpickler
from
ZODB._compat
import
BytesIO
...
...
@@ -84,13 +84,24 @@ assert sys.hexversion >= 0x02030000
# The distinction between ints and longs is blurred in Python 2.2,
# so u64() are U64() really the same.
_OID_STRUCT
=
struct
.
Struct
(
'>Q'
)
_OID_PACK
=
_OID_STRUCT
.
pack
_OID_UNPACK
=
_OID_STRUCT
.
unpack
def
p64
(
v
):
"""Pack an integer or long into a 8-byte string"""
return
pack
(
">Q"
,
v
)
"""Pack an integer or long into a 8-byte string."""
try
:
return
_OID_PACK
(
v
)
except
struct
.
error
as
e
:
raise
ValueError
(
*
(
e
.
args
+
(
v
,)))
def
u64
(
v
):
"""Unpack an 8-byte string into a 64-bit long integer."""
return
unpack
(
">Q"
,
v
)[
0
]
try
:
return
_OID_UNPACK
(
v
)[
0
]
except
struct
.
error
as
e
:
raise
ValueError
(
*
(
e
.
args
+
(
v
,)))
U64
=
u64
...
...
This diff is collapsed.
Click to expand it.
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