Commit 19e851c2 authored by Tres Seaver's avatar Tres Seaver

Avoid repr(tid) (use tid.raw()).

Ensure that we use bytes literals for tid values.

Remove non-comment / docstring use of backticks.
parent 994af0c5
...@@ -380,7 +380,7 @@ def copy(source, dest, verbose=0): ...@@ -380,7 +380,7 @@ def copy(source, dest, verbose=0):
if ok: print ('Time stamps out of order %s, %s' % (_ts, t)) if ok: print ('Time stamps out of order %s, %s' % (_ts, t))
ok = 0 ok = 0
_ts = t.laterThan(_ts) _ts = t.laterThan(_ts)
tid = `_ts` tid = _ts.raw()
else: else:
_ts = t _ts = t
if not ok: if not ok:
......
...@@ -894,7 +894,7 @@ class FileStorage( ...@@ -894,7 +894,7 @@ class FileStorage(
with self._lock: with self._lock:
# Find the right transaction to undo and call _txn_undo_write(). # Find the right transaction to undo and call _txn_undo_write().
tid = base64.decodestring(transaction_id + '\n') tid = base64.decodestring(transaction_id + b'\n')
assert len(tid) == 8 assert len(tid) == 8
tpos = self._txn_find(tid, 1) tpos = self._txn_find(tid, 1)
tindex = self._txn_undo_write(tpos) tindex = self._txn_undo_write(tpos)
...@@ -1048,8 +1048,9 @@ class FileStorage( ...@@ -1048,8 +1048,9 @@ class FileStorage(
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
stop=`TimeStamp(*time.gmtime(t)[:5]+(t%60,))` stop = TimeStamp(*time.gmtime(t)[:5]+(t%60,)).raw()
if stop==z64: raise FileStorageError('Invalid pack time') if stop==z64:
raise FileStorageError('Invalid pack time')
# If the storage is empty, there's nothing to do. # If the storage is empty, there's nothing to do.
if not self._index: if not self._index:
...@@ -1176,7 +1177,7 @@ class FileStorage( ...@@ -1176,7 +1177,7 @@ class FileStorage(
handle_dir = ZODB.blob.remove_committed_dir handle_dir = ZODB.blob.remove_committed_dir
# Fist step: move or remove oids or revisions # Fist step: move or remove oids or revisions
for line in open(os.path.join(self.blob_dir, '.removed')): for line in open(os.path.join(self.blob_dir, '.removed')): #XXX bytes
line = line.strip().decode('hex') line = line.strip().decode('hex')
if len(line) == 8: if len(line) == 8:
...@@ -1471,7 +1472,7 @@ def read_index(file, name, index, tindex, stop='\377'*8, ...@@ -1471,7 +1472,7 @@ def read_index(file, name, index, tindex, stop='\377'*8,
pos = start pos = start
seek(start) seek(start)
tid = '\0' * 7 + '\1' tid = b'\0' * 7 + b'\1'
while 1: while 1:
# Read the transaction record # Read the transaction record
...@@ -1664,7 +1665,7 @@ class FileIterator(FileStorageFormatter): ...@@ -1664,7 +1665,7 @@ class FileIterator(FileStorageFormatter):
# implementation. So just return 0. # implementation. So just return 0.
return 0 return 0
# This allows us to pass an iterator as the `other' argument to # This allows us to pass an iterator as the `other` argument to
# copyTransactionsFrom() in BaseStorage. The advantage here is that we # copyTransactionsFrom() in BaseStorage. The advantage here is that we
# can create the iterator manually, e.g. setting start and stop, and then # can create the iterator manually, e.g. setting start and stop, and then
# just let copyTransactionsFrom() do its thing. # just let copyTransactionsFrom() do its thing.
...@@ -1681,7 +1682,7 @@ class FileIterator(FileStorageFormatter): ...@@ -1681,7 +1682,7 @@ class FileIterator(FileStorageFormatter):
file = self._file file = self._file
pos1 = self._pos pos1 = self._pos
file.seek(pos1) file.seek(pos1)
tid1 = file.read(8) tid1 = file.read(8) # XXX bytes
if len(tid1) < 8: if len(tid1) < 8:
raise CorruptedError("Couldn't read tid.") raise CorruptedError("Couldn't read tid.")
if start < tid1: if start < tid1:
......
...@@ -53,7 +53,7 @@ class PackCopier(FileStorageFormatter): ...@@ -53,7 +53,7 @@ class PackCopier(FileStorageFormatter):
self._file.seek(pos - 8) self._file.seek(pos - 8)
pos = pos - u64(self._file.read(8)) - 8 pos = pos - u64(self._file.read(8)) - 8
self._file.seek(pos) self._file.seek(pos)
h = self._file.read(TRANS_HDR_LEN) h = self._file.read(TRANS_HDR_LEN) # XXX bytes
_tid = h[:8] _tid = h[:8]
if _tid == tid: if _tid == tid:
return pos return pos
......
...@@ -189,7 +189,7 @@ class MappingStorage(object): ...@@ -189,7 +189,7 @@ class MappingStorage(object):
if not self._data: if not self._data:
return return
stop = `ZODB.TimeStamp.TimeStamp(*time.gmtime(t)[:5]+(t%60,))` stop = ZODB.TimeStamp.TimeStamp(*time.gmtime(t)[:5]+(t%60,)).raw()
if self._last_pack is not None and self._last_pack >= stop: if self._last_pack is not None and self._last_pack >= stop:
if self._last_pack == stop: if self._last_pack == stop:
return return
......
...@@ -435,7 +435,8 @@ class FilesystemHelper: ...@@ -435,7 +435,8 @@ class FilesystemHelper:
""" """
oidpath = self.getPathForOID(oid) oidpath = self.getPathForOID(oid)
fd, name = tempfile.mkstemp(suffix='.tmp', prefix=utils.tid_repr(tid), fd, name = tempfile.mkstemp(suffix='.tmp',
prefix=utils.tid_repr(tid),
dir=oidpath) dir=oidpath)
return fd, name return fd, name
...@@ -816,7 +817,7 @@ class BlobStorage(BlobStorageMixin): ...@@ -816,7 +817,7 @@ class BlobStorage(BlobStorageMixin):
# The serial_id is assumed to be given to us base-64 encoded # The serial_id is assumed to be given to us base-64 encoded
# (belying the web UI legacy of the ZODB code :-() # (belying the web UI legacy of the ZODB code :-()
serial_id = base64.decodestring(serial_id+'\n') serial_id = base64.decodestring(serial_id + b'\n')
self._lock_acquire() self._lock_acquire()
......
...@@ -314,7 +314,7 @@ def recover(inp, outp, verbose=0, partial=False, force=False, pack=None): ...@@ -314,7 +314,7 @@ def recover(inp, outp, verbose=0, partial=False, force=False, pack=None):
print ("Time stamps out of order %s, %s" % (_ts, t)) print ("Time stamps out of order %s, %s" % (_ts, t))
ok = 0 ok = 0
_ts = t.laterThan(_ts) _ts = t.laterThan(_ts)
tid = `_ts` tid = _ts.raw()
else: else:
_ts = t _ts = t
if not ok: if not ok:
......
...@@ -91,7 +91,7 @@ def check(path): ...@@ -91,7 +91,7 @@ def check(path):
raise FormatError("invalid file header") raise FormatError("invalid file header")
pos = 4L pos = 4L
tid = '\000' * 8 # lowest possible tid to start tid = b'\000' * 8 # lowest possible tid to start
i = 0 i = 0
while pos: while pos:
_pos = pos _pos = pos
...@@ -110,7 +110,7 @@ def check_trec(path, file, pos, ltid, file_size): ...@@ -110,7 +110,7 @@ def check_trec(path, file, pos, ltid, file_size):
used for generating error messages. used for generating error messages.
""" """
h = file.read(TREC_HDR_LEN) h = file.read(TREC_HDR_LEN) #XXX must be bytes under Py3k
if not h: if not h:
return None, None return None, None
if len(h) != TREC_HDR_LEN: if len(h) != TREC_HDR_LEN:
......
...@@ -262,7 +262,7 @@ def doit(srcdb, dstdb, options): ...@@ -262,7 +262,7 @@ def doit(srcdb, dstdb, options):
'Time stamps are out of order %s, %s' % (ts, t)) 'Time stamps are out of order %s, %s' % (ts, t))
ok = False ok = False
ts = t.laterThan(ts) ts = t.laterThan(ts)
tid = `ts` tid = ts.raw()
else: else:
ts = t ts = t
if not ok: if not ok:
......
...@@ -283,7 +283,7 @@ def copyfile(options, dst, start, n): ...@@ -283,7 +283,7 @@ def copyfile(options, dst, start, n):
def concat(files, ofp=None): def concat(files, ofp=None):
# Concatenate a bunch of files from the repository, output to `outfile' if # Concatenate a bunch of files from the repository, output to 'ofp' if
# given. Return the number of bytes written and the md5 checksum of the # given. Return the number of bytes written and the md5 checksum of the
# bytes. # bytes.
sum = md5() sum = md5()
......
...@@ -319,7 +319,7 @@ def run1(tid, db, factory, job, args): ...@@ -319,7 +319,7 @@ def run1(tid, db, factory, job, args):
start, tid, wcomp, ccomp, rconflicts, wconflicts, wcommit, ccommit, start, tid, wcomp, ccomp, rconflicts, wconflicts, wcommit, ccommit,
factory.__name__, r) factory.__name__, r)
def run(jobs, tid=''): def run(jobs, tid=b''):
import Zope2 import Zope2
while 1: while 1:
factory, job, args, repeatp = jobs.next() factory, job, args, repeatp = jobs.next()
......
...@@ -32,11 +32,11 @@ import transaction ...@@ -32,11 +32,11 @@ import transaction
import zope.interface import zope.interface
import zope.interface.verify import zope.interface.verify
ZERO = '\0'*8 ZERO = b'\0'*8
class BasicStorage: class BasicStorage:
def checkBasics(self): def checkBasics(self):
self.assertEqual(self._storage.lastTransaction(), '\0'*8) self.assertEqual(self._storage.lastTransaction(), ZERO)
t = transaction.Transaction() t = transaction.Transaction()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
...@@ -220,7 +220,7 @@ class BasicStorage: ...@@ -220,7 +220,7 @@ class BasicStorage:
return thread return thread
def check_checkCurrentSerialInTransaction(self): def check_checkCurrentSerialInTransaction(self):
oid = '\0\0\0\0\0\0\0\xf0' oid = b'\0\0\0\0\0\0\0\xf0'
tid = self._dostore(oid) tid = self._dostore(oid)
tid2 = self._dostore(oid, revid=tid) tid2 = self._dostore(oid, revid=tid)
data = 'cpersistent\nPersistent\nq\x01.N.' # a simple persistent obj data = 'cpersistent\nPersistent\nq\x01.N.' # a simple persistent obj
...@@ -231,8 +231,8 @@ class BasicStorage: ...@@ -231,8 +231,8 @@ class BasicStorage:
t = transaction.get() t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
try: try:
self._storage.store('\0\0\0\0\0\0\0\xf1', self._storage.store(b'\0\0\0\0\0\0\0\xf1',
'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid, t) self._storage.checkCurrentSerialInTransaction(oid, tid, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
except POSException.ReadConflictError, v: except POSException.ReadConflictError, v:
...@@ -249,8 +249,8 @@ class BasicStorage: ...@@ -249,8 +249,8 @@ class BasicStorage:
transaction.begin() transaction.begin()
t = transaction.get() t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf2', self._storage.store(b'\0\0\0\0\0\0\0\xf2',
'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid2, t) self._storage.checkCurrentSerialInTransaction(oid, tid2, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
...@@ -261,8 +261,8 @@ class BasicStorage: ...@@ -261,8 +261,8 @@ class BasicStorage:
transaction.begin() transaction.begin()
t = transaction.get() t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf3', self._storage.store(b'\0\0\0\0\0\0\0\xf3',
'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid2, t) self._storage.checkCurrentSerialInTransaction(oid, tid2, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -272,15 +272,15 @@ class BasicStorage: ...@@ -272,15 +272,15 @@ class BasicStorage:
thread.join(33) thread.join(33)
tid3 = self._storage.load(oid)[1] tid3 = self._storage.load(oid)[1]
self.assert_(tid3 > self._storage.load('\0\0\0\0\0\0\0\xf3')[1]) self.assert_(tid3 > self._storage.load(b'\0\0\0\0\0\0\0\xf3')[1])
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# non-stale competing trans after checkCurrentSerialInTransaction # non-stale competing trans after checkCurrentSerialInTransaction
transaction.begin() transaction.begin()
t = transaction.get() t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf4', self._storage.store(b'\0\0\0\0\0\0\0\xf4',
'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid3, t) self._storage.checkCurrentSerialInTransaction(oid, tid3, t)
thread = self._do_store_in_separate_thread(oid, tid3, False) thread = self._do_store_in_separate_thread(oid, tid3, False)
...@@ -298,7 +298,7 @@ class BasicStorage: ...@@ -298,7 +298,7 @@ class BasicStorage:
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
thread.join() thread.join()
tid4 = self._storage.load(oid)[1] tid4 = self._storage.load(oid)[1]
self.assert_(tid4 > self._storage.load('\0\0\0\0\0\0\0\xf4')[1]) self.assert_(tid4 > self._storage.load(b'\0\0\0\0\0\0\0\xf4')[1])
def check_tid_ordering_w_commit(self): def check_tid_ordering_w_commit(self):
......
...@@ -30,7 +30,7 @@ class MVCCMappingStorage(MappingStorage): ...@@ -30,7 +30,7 @@ class MVCCMappingStorage(MappingStorage):
def __init__(self, name="MVCC Mapping Storage"): def __init__(self, name="MVCC Mapping Storage"):
MappingStorage.__init__(self, name=name) MappingStorage.__init__(self, name=name)
# _polled_tid contains the transaction ID at the last poll. # _polled_tid contains the transaction ID at the last poll.
self._polled_tid = '' self._polled_tid = b''
self._data_snapshot = None # {oid->(state, tid)} self._data_snapshot = None # {oid->(state, tid)}
self._main_lock_acquire = self._lock_acquire self._main_lock_acquire = self._lock_acquire
self._main_lock_release = self._lock_release self._main_lock_release = self._lock_release
...@@ -77,7 +77,7 @@ class MVCCMappingStorage(MappingStorage): ...@@ -77,7 +77,7 @@ class MVCCMappingStorage(MappingStorage):
if self._transactions: if self._transactions:
new_tid = self._transactions.maxKey() new_tid = self._transactions.maxKey()
else: else:
new_tid = '' new_tid = b''
# Copy the current data into a snapshot. This is obviously # Copy the current data into a snapshot. This is obviously
# very inefficient for large storages, but it's good for # very inefficient for large storages, but it's good for
......
...@@ -65,7 +65,7 @@ Put some revisions of a blob object in our database and on the filesystem: ...@@ -65,7 +65,7 @@ Put some revisions of a blob object in our database and on the filesystem:
>>> oid = root['blob']._p_oid >>> oid = root['blob']._p_oid
>>> fns = [ blob_storage.fshelper.getBlobFilename(oid, x) for x in tids ] >>> fns = [ blob_storage.fshelper.getBlobFilename(oid, x) for x in tids ]
>>> [ os.path.exists(x) for x in fns ] >>> [ os.path.exists(x) for x in fns ] # no pack
[True, True, True, True, True] [True, True, True, True, True]
Do a pack to the slightly before the first revision was written: Do a pack to the slightly before the first revision was written:
......
...@@ -659,7 +659,7 @@ implementation of checkCurrentSerialInTransaction. ...@@ -659,7 +659,7 @@ implementation of checkCurrentSerialInTransaction.
>>> from ZODB.POSException import ReadConflictError >>> from ZODB.POSException import ReadConflictError
>>> bad = set() >>> bad = set()
>>> def checkCurrentSerialInTransaction(oid, serial, trans): >>> def checkCurrentSerialInTransaction(oid, serial, trans):
... print 'checkCurrentSerialInTransaction', `oid` ... print 'checkCurrentSerialInTransaction', repr(oid)
... if not trans == transaction.get(): print 'oops' ... if not trans == transaction.get(): print 'oops'
... if oid in bad: ... if oid in bad:
... raise ReadConflictError(oid=oid) ... raise ReadConflictError(oid=oid)
...@@ -730,7 +730,7 @@ The storage may raise it later: ...@@ -730,7 +730,7 @@ The storage may raise it later:
>>> def checkCurrentSerialInTransaction(oid, serial, trans): >>> def checkCurrentSerialInTransaction(oid, serial, trans):
... if not trans == transaction.get(): print 'oops' ... if not trans == transaction.get(): print 'oops'
... print 'checkCurrentSerialInTransaction', `oid` ... print 'checkCurrentSerialInTransaction', repr(oid)
... store.badness = ReadConflictError(oid=oid) ... store.badness = ReadConflictError(oid=oid)
>>> def tpc_vote(t): >>> def tpc_vote(t):
......
...@@ -272,9 +272,9 @@ class FileStorageTests( ...@@ -272,9 +272,9 @@ class FileStorageTests(
self.open() self.open()
key = None key = None
for x in ('\000', '\001', '\002'): for x in (b'\000', b'\001', b'\002'):
oid, tid, data, next_oid = self._storage.record_iternext(key) oid, tid, data, next_oid = self._storage.record_iternext(key)
self.assertEqual(oid, ('\000' * 7) + x) self.assertEqual(oid, (b'\000' * 7) + x)
key = next_oid key = next_oid
expected_data, expected_tid = self._storage.load(oid, '') expected_data, expected_tid = self._storage.load(oid, '')
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
...@@ -432,7 +432,7 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase): ...@@ -432,7 +432,7 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase):
# Raise an exception if the tids in FileStorage fs aren't # Raise an exception if the tids in FileStorage fs aren't
# strictly increasing. # strictly increasing.
def checkIncreasingTids(fs): def checkIncreasingTids(fs):
lasttid = '\0' * 8 lasttid = b'\0' * 8
for txn in fs.iterator(): for txn in fs.iterator():
if lasttid >= txn.tid: if lasttid >= txn.tid:
raise ValueError("tids out of order %r >= %r" % (lasttid, txn.tid)) raise ValueError("tids out of order %r >= %r" % (lasttid, txn.tid))
......
...@@ -50,7 +50,7 @@ class TestPList(unittest.TestCase): ...@@ -50,7 +50,7 @@ class TestPList(unittest.TestCase):
eq(str(u0), str(l0), "str(u0) == str(l0)") eq(str(u0), str(l0), "str(u0) == str(l0)")
eq(repr(u1), repr(l1), "repr(u1) == repr(l1)") eq(repr(u1), repr(l1), "repr(u1) == repr(l1)")
eq(`u2`, `l2`, "`u2` == `l2`") eq(repr(u2), repr(l2), "repr(u2) == repr(l2)")
# Test __cmp__ and __len__ # Test __cmp__ and __len__
......
...@@ -147,11 +147,11 @@ class RecoverTest(ZODB.tests.util.TestCase): ...@@ -147,11 +147,11 @@ class RecoverTest(ZODB.tests.util.TestCase):
L = self.storage.undoLog() L = self.storage.undoLog()
r = L[3] r = L[3]
tid = base64.decodestring(r["id"] + "\n") tid = base64.decodestring(r["id"] + b"\n")
pos1 = self.storage._txn_find(tid, 0) pos1 = self.storage._txn_find(tid, 0)
r = L[8] r = L[8]
tid = base64.decodestring(r["id"] + "\n") tid = base64.decodestring(r["id"] + b"\n")
pos2 = self.storage._txn_find(tid, 0) pos2 = self.storage._txn_find(tid, 0)
self.storage.close() self.storage.close()
...@@ -185,7 +185,7 @@ class RecoverTest(ZODB.tests.util.TestCase): ...@@ -185,7 +185,7 @@ class RecoverTest(ZODB.tests.util.TestCase):
# Find a transaction near the end. # Find a transaction near the end.
L = self.storage.undoLog() L = self.storage.undoLog()
r = L[1] r = L[1]
tid = base64.decodestring(r["id"] + "\n") tid = base64.decodestring(r["id"] + b"\n")
pos = self.storage._txn_find(tid, 0) pos = self.storage._txn_find(tid, 0)
# Overwrite its status with 'c'. # Overwrite its status with 'c'.
......
...@@ -66,7 +66,7 @@ def deprecated38(msg): ...@@ -66,7 +66,7 @@ def deprecated38(msg):
warnings.warn("This will be removed in ZODB 3.8:\n%s" % msg, warnings.warn("This will be removed in ZODB 3.8:\n%s" % msg,
DeprecationWarning, stacklevel=3) DeprecationWarning, stacklevel=3)
z64 = '\0'*8 z64 = b'\0' * 8
assert sys.hexversion >= 0x02030000 assert sys.hexversion >= 0x02030000
...@@ -145,7 +145,7 @@ tid_repr = serial_repr ...@@ -145,7 +145,7 @@ tid_repr = serial_repr
# For example, produce # For example, produce
# '0x03441422948b4399 2002-04-14 20:50:34.815000' # '0x03441422948b4399 2002-04-14 20:50:34.815000'
# for 8-byte string tid '\x03D\x14"\x94\x8bC\x99'. # for 8-byte string tid b'\x03D\x14"\x94\x8bC\x99'.
def readable_tid_repr(tid): def readable_tid_repr(tid):
result = tid_repr(tid) result = tid_repr(tid)
if isinstance(tid, str) and len(tid) == 8: if isinstance(tid, str) and len(tid) == 8:
......
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