Skip to content

Commit

Permalink
WIP: Python3-ify fstest.py
Browse files Browse the repository at this point in the history
Next: the hexify() function needs to handle bytestrings on Py3 and
regular strings on Py2.
  • Loading branch information
mgedmin committed Feb 19, 2013
1 parent c59b0ff commit 37c20b5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/ZODB/scripts/fstest.py
Expand Up @@ -44,18 +44,18 @@ class FormatError(ValueError):
"""There is a problem with the format of the FileStorage."""

class Status:
checkpoint = 'c'
undone = 'u'
checkpoint = b'c'
undone = b'u'

packed_version = 'FS21'
packed_version = b'FS21'

TREC_HDR_LEN = 23
DREC_HDR_LEN = 42

VERBOSE = 0

def hexify(s):
"""Format an 8-bite string as hex"""
"""Format an 8-bit string as hex"""
l = []
for c in s:
h = hex(ord(c))
Expand All @@ -64,7 +64,7 @@ def hexify(s):
if len(h) == 1:
l.append("0")
l.append(h)
return "0x" + string.join(l, '')
return "0x" + ''.join(l)

def chatter(msg, level=1):
if VERBOSE >= level:
Expand Down Expand Up @@ -130,7 +130,7 @@ def check_trec(path, file, pos, ltid, file_size):
if status == Status.checkpoint:
raise FormatError("%s checkpoint flag was not cleared at %s"
% (path, pos))
if status not in ' up':
if status not in b' up':
raise FormatError("%s has invalid status '%s' at %s" %
(path, status, pos))

Expand Down Expand Up @@ -199,8 +199,7 @@ def check_drec(path, file, pos, tpos, tid):
return pos, oid

def usage():
print(__doc__)
sys.exit(-1)
sys.exit(__doc__)

def main(args=None):
if args is None:
Expand All @@ -221,8 +220,7 @@ def main(args=None):
try:
check(args[0])
except FormatError as msg:
print(msg)
sys.exit(-1)
sys.exit(msg)

chatter("no errors detected")

Expand Down

0 comments on commit 37c20b5

Please sign in to comment.