Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
9717e6c8
Commit
9717e6c8
authored
Dec 10, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work with OIDs as bytes.
parent
2706c14a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
BTrees/tests/test_utils.py
BTrees/tests/test_utils.py
+4
-4
BTrees/utils.py
BTrees/utils.py
+10
-6
No files found.
BTrees/tests/test_utils.py
View file @
9717e6c8
...
...
@@ -72,16 +72,16 @@ class Test_oid_repr(unittest.TestCase):
self
.
assertEqual
(
self
.
_callFUT
(
faux
),
repr
(
faux
))
def
test_w_zero
(
self
):
self
.
assertEqual
(
self
.
_callFUT
(
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
),
'0x00'
)
self
.
assertEqual
(
self
.
_callFUT
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
'
),
b
'0x00'
)
def
test_w_one
(
self
):
self
.
assertEqual
(
self
.
_callFUT
(
'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
1
'
),
'0x01'
)
self
.
assertEqual
(
self
.
_callFUT
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
1
'
),
b
'0x01'
)
def
test_w_even_length
(
self
):
self
.
assertEqual
(
self
.
_callFUT
(
'
\
0
\
0
\
0
\
0
\
0
\
0
\
xAB
\
xC4
'
),
'0xabc4'
)
self
.
assertEqual
(
self
.
_callFUT
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
xAB
\
xC4
'
),
b
'0xabc4'
)
def
test_w_odd_length
(
self
):
self
.
assertEqual
(
self
.
_callFUT
(
'
\
0
\
0
\
0
\
0
\
0
\
0
\
x0D
\
xEF
'
),
'0x0def'
)
self
.
assertEqual
(
self
.
_callFUT
(
b'
\
0
\
0
\
0
\
0
\
0
\
0
\
x0D
\
xEF
'
),
b
'0x0def'
)
def
test_suite
():
...
...
BTrees/utils.py
View file @
9717e6c8
...
...
@@ -15,6 +15,8 @@
from
binascii
import
hexlify
from
._compat
import
_bytes
def
non_negative
(
int_val
):
if
int_val
<
0
:
# Coerce to non-negative.
...
...
@@ -28,14 +30,16 @@ def positive_id(obj): #pragma NO COVER
def
oid_repr
(
oid
):
if
isinstance
(
oid
,
str
)
and
len
(
oid
)
==
8
:
if
isinstance
(
oid
,
_bytes
)
and
len
(
oid
)
==
8
:
# Convert to hex and strip leading zeroes.
as_hex
=
hexlify
(
oid
).
lstrip
(
'0'
)
as_hex
=
hexlify
(
oid
).
lstrip
(
b
'0'
)
# Ensure two characters per input byte.
chunks
=
[
b'0x'
]
if
len
(
as_hex
)
&
1
:
as_hex
=
'0'
+
as_hex
elif
as_hex
==
''
:
as_hex
=
'00'
return
'0x'
+
as_hex
chunks
.
append
(
b'0'
)
elif
as_hex
==
b''
:
as_hex
=
b'00'
chunks
.
append
(
as_hex
)
return
b''
.
join
(
chunks
)
else
:
return
repr
(
oid
)
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