Skip to content

Commit

Permalink
Whack dem moles.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Mar 3, 2013
1 parent 257fed3 commit 78619a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/ZODB/_compat.py
Expand Up @@ -80,3 +80,13 @@ def py2_hasattr(obj, name):
# Py3
long = int


try:
TEXT = unicode
except NameError: #pragma NO COVER Py3k
TEXT = str

def ascii_bytes(x):
if isinstance(x, TEXT):
x = x.encode('ascii')
return x
7 changes: 5 additions & 2 deletions src/ZODB/blob.py
Expand Up @@ -31,7 +31,10 @@
from ZODB.interfaces import BlobError
from ZODB import utils
from ZODB.POSException import POSKeyError
from ZODB._compat import BytesIO, Unpickler, decodebytes
from ZODB._compat import BytesIO
from ZODB._compat import Unpickler
from ZODB._compat import decodebytes
from ZODB._compat import ascii_bytes


if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -557,7 +560,7 @@ def oid_to_path(self, oid):
def path_to_oid(self, path):
if self.blob_path_pattern.match(path) is None:
raise ValueError("Not a valid OID path: `%s`" % path)
path = [bytes(x, 'ascii') for x in path.split(os.path.sep)]
path = [ascii_bytes(x) for x in path.split(os.path.sep)]
# Each path segment stores a byte in hex representation. Turn it into
# an int and then get the character for our byte string.
oid = b''.join(binascii.unhexlify(byte[2:]) for byte in path)
Expand Down
7 changes: 4 additions & 3 deletions src/ZODB/utils.py
Expand Up @@ -22,7 +22,9 @@

from persistent.TimeStamp import TimeStamp

from ZODB._compat import Unpickler, BytesIO
from ZODB._compat import Unpickler
from ZODB._compat import BytesIO
from ZODB._compat import ascii_bytes


__all__ = ['z64',
Expand Down Expand Up @@ -164,8 +166,7 @@ def oid_repr(oid):
return repr(oid)

def repr_to_oid(repr):
if not isinstance(repr, bytes):
repr = bytes(repr, 'ascii')
repr = ascii_bytes(repr)
if repr.startswith(b"0x"):
repr = repr[2:]
as_bin = unhexlify(repr)
Expand Down

0 comments on commit 78619a3

Please sign in to comment.