Commit 37c20b52 authored by Marius Gedminas's avatar Marius Gedminas

WIP: Python3-ify fstest.py

Next: the hexify() function needs to handle bytestrings on Py3 and
regular strings on Py2.
parent c59b0ffc
...@@ -44,10 +44,10 @@ class FormatError(ValueError): ...@@ -44,10 +44,10 @@ class FormatError(ValueError):
"""There is a problem with the format of the FileStorage.""" """There is a problem with the format of the FileStorage."""
class Status: class Status:
checkpoint = 'c' checkpoint = b'c'
undone = 'u' undone = b'u'
packed_version = 'FS21' packed_version = b'FS21'
TREC_HDR_LEN = 23 TREC_HDR_LEN = 23
DREC_HDR_LEN = 42 DREC_HDR_LEN = 42
...@@ -55,7 +55,7 @@ DREC_HDR_LEN = 42 ...@@ -55,7 +55,7 @@ DREC_HDR_LEN = 42
VERBOSE = 0 VERBOSE = 0
def hexify(s): def hexify(s):
"""Format an 8-bite string as hex""" """Format an 8-bit string as hex"""
l = [] l = []
for c in s: for c in s:
h = hex(ord(c)) h = hex(ord(c))
...@@ -64,7 +64,7 @@ def hexify(s): ...@@ -64,7 +64,7 @@ def hexify(s):
if len(h) == 1: if len(h) == 1:
l.append("0") l.append("0")
l.append(h) l.append(h)
return "0x" + string.join(l, '') return "0x" + ''.join(l)
def chatter(msg, level=1): def chatter(msg, level=1):
if VERBOSE >= level: if VERBOSE >= level:
...@@ -130,7 +130,7 @@ def check_trec(path, file, pos, ltid, file_size): ...@@ -130,7 +130,7 @@ def check_trec(path, file, pos, ltid, file_size):
if status == Status.checkpoint: if status == Status.checkpoint:
raise FormatError("%s checkpoint flag was not cleared at %s" raise FormatError("%s checkpoint flag was not cleared at %s"
% (path, pos)) % (path, pos))
if status not in ' up': if status not in b' up':
raise FormatError("%s has invalid status '%s' at %s" % raise FormatError("%s has invalid status '%s' at %s" %
(path, status, pos)) (path, status, pos))
...@@ -199,8 +199,7 @@ def check_drec(path, file, pos, tpos, tid): ...@@ -199,8 +199,7 @@ def check_drec(path, file, pos, tpos, tid):
return pos, oid return pos, oid
def usage(): def usage():
print(__doc__) sys.exit(__doc__)
sys.exit(-1)
def main(args=None): def main(args=None):
if args is None: if args is None:
...@@ -221,8 +220,7 @@ def main(args=None): ...@@ -221,8 +220,7 @@ def main(args=None):
try: try:
check(args[0]) check(args[0])
except FormatError as msg: except FormatError as msg:
print(msg) sys.exit(msg)
sys.exit(-1)
chatter("no errors detected") chatter("no errors detected")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment