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):
if ok: print ('Time stamps out of order %s, %s' % (_ts, t))
ok = 0
_ts = t.laterThan(_ts)
tid = `_ts`
tid = _ts.raw()
else:
_ts = t
if not ok:
......
......@@ -894,7 +894,7 @@ class FileStorage(
with self._lock:
# 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
tpos = self._txn_find(tid, 1)
tindex = self._txn_undo_write(tpos)
......@@ -1048,8 +1048,9 @@ class FileStorage(
if self._is_read_only:
raise POSException.ReadOnlyError()
stop=`TimeStamp(*time.gmtime(t)[:5]+(t%60,))`
if stop==z64: raise FileStorageError('Invalid pack time')
stop = TimeStamp(*time.gmtime(t)[:5]+(t%60,)).raw()
if stop==z64:
raise FileStorageError('Invalid pack time')
# If the storage is empty, there's nothing to do.
if not self._index:
......@@ -1176,7 +1177,7 @@ class FileStorage(
handle_dir = ZODB.blob.remove_committed_dir
# 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')
if len(line) == 8:
......@@ -1471,7 +1472,7 @@ def read_index(file, name, index, tindex, stop='\377'*8,
pos = start
seek(start)
tid = '\0' * 7 + '\1'
tid = b'\0' * 7 + b'\1'
while 1:
# Read the transaction record
......@@ -1664,7 +1665,7 @@ class FileIterator(FileStorageFormatter):
# implementation. So just 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
# can create the iterator manually, e.g. setting start and stop, and then
# just let copyTransactionsFrom() do its thing.
......@@ -1681,7 +1682,7 @@ class FileIterator(FileStorageFormatter):
file = self._file
pos1 = self._pos
file.seek(pos1)
tid1 = file.read(8)
tid1 = file.read(8) # XXX bytes
if len(tid1) < 8:
raise CorruptedError("Couldn't read tid.")
if start < tid1:
......
......@@ -53,7 +53,7 @@ class PackCopier(FileStorageFormatter):
self._file.seek(pos - 8)
pos = pos - u64(self._file.read(8)) - 8
self._file.seek(pos)
h = self._file.read(TRANS_HDR_LEN)
h = self._file.read(TRANS_HDR_LEN) # XXX bytes
_tid = h[:8]
if _tid == tid:
return pos
......
......@@ -189,7 +189,7 @@ class MappingStorage(object):
if not self._data:
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 == stop:
return
......
......@@ -435,7 +435,8 @@ class FilesystemHelper:
"""
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)
return fd, name
......@@ -816,7 +817,7 @@ class BlobStorage(BlobStorageMixin):
# The serial_id is assumed to be given to us base-64 encoded
# (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()
......
......@@ -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))
ok = 0
_ts = t.laterThan(_ts)
tid = `_ts`
tid = _ts.raw()
else:
_ts = t
if not ok:
......
......@@ -91,7 +91,7 @@ def check(path):
raise FormatError("invalid file header")
pos = 4L
tid = '\000' * 8 # lowest possible tid to start
tid = b'\000' * 8 # lowest possible tid to start
i = 0
while pos:
_pos = pos
......@@ -110,7 +110,7 @@ def check_trec(path, file, pos, ltid, file_size):
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:
return None, None
if len(h) != TREC_HDR_LEN:
......
......@@ -262,7 +262,7 @@ def doit(srcdb, dstdb, options):
'Time stamps are out of order %s, %s' % (ts, t))
ok = False
ts = t.laterThan(ts)
tid = `ts`
tid = ts.raw()
else:
ts = t
if not ok:
......
......@@ -283,7 +283,7 @@ def copyfile(options, dst, start, n):
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
# bytes.
sum = md5()
......
......@@ -319,7 +319,7 @@ def run1(tid, db, factory, job, args):
start, tid, wcomp, ccomp, rconflicts, wconflicts, wcommit, ccommit,
factory.__name__, r)
def run(jobs, tid=''):
def run(jobs, tid=b''):
import Zope2
while 1:
factory, job, args, repeatp = jobs.next()
......
......@@ -32,11 +32,11 @@ import transaction
import zope.interface
import zope.interface.verify
ZERO = '\0'*8
ZERO = b'\0'*8
class BasicStorage:
def checkBasics(self):
self.assertEqual(self._storage.lastTransaction(), '\0'*8)
self.assertEqual(self._storage.lastTransaction(), ZERO)
t = transaction.Transaction()
self._storage.tpc_begin(t)
......@@ -220,7 +220,7 @@ class BasicStorage:
return thread
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)
tid2 = self._dostore(oid, revid=tid)
data = 'cpersistent\nPersistent\nq\x01.N.' # a simple persistent obj
......@@ -231,8 +231,8 @@ class BasicStorage:
t = transaction.get()
self._storage.tpc_begin(t)
try:
self._storage.store('\0\0\0\0\0\0\0\xf1',
'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.store(b'\0\0\0\0\0\0\0\xf1',
b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid, t)
self._storage.tpc_vote(t)
except POSException.ReadConflictError, v:
......@@ -249,8 +249,8 @@ class BasicStorage:
transaction.begin()
t = transaction.get()
self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf2',
'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.store(b'\0\0\0\0\0\0\0\xf2',
b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid2, t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
......@@ -261,8 +261,8 @@ class BasicStorage:
transaction.begin()
t = transaction.get()
self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf3',
'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.store(b'\0\0\0\0\0\0\0\xf3',
b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid2, t)
self._storage.tpc_vote(t)
......@@ -272,15 +272,15 @@ class BasicStorage:
thread.join(33)
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
transaction.begin()
t = transaction.get()
self._storage.tpc_begin(t)
self._storage.store('\0\0\0\0\0\0\0\xf4',
'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.store(b'\0\0\0\0\0\0\0\xf4',
b'\0\0\0\0\0\0\0\0', data, '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid3, t)
thread = self._do_store_in_separate_thread(oid, tid3, False)
......@@ -298,7 +298,7 @@ class BasicStorage:
self._storage.tpc_finish(t)
thread.join()
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):
......
......@@ -30,7 +30,7 @@ class MVCCMappingStorage(MappingStorage):
def __init__(self, name="MVCC Mapping Storage"):
MappingStorage.__init__(self, name=name)
# _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._main_lock_acquire = self._lock_acquire
self._main_lock_release = self._lock_release
......@@ -77,7 +77,7 @@ class MVCCMappingStorage(MappingStorage):
if self._transactions:
new_tid = self._transactions.maxKey()
else:
new_tid = ''
new_tid = b''
# Copy the current data into a snapshot. This is obviously
# 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:
>>> oid = root['blob']._p_oid
>>> 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]
Do a pack to the slightly before the first revision was written:
......
......@@ -659,7 +659,7 @@ implementation of checkCurrentSerialInTransaction.
>>> from ZODB.POSException import ReadConflictError
>>> bad = set()
>>> def checkCurrentSerialInTransaction(oid, serial, trans):
... print 'checkCurrentSerialInTransaction', `oid`
... print 'checkCurrentSerialInTransaction', repr(oid)
... if not trans == transaction.get(): print 'oops'
... if oid in bad:
... raise ReadConflictError(oid=oid)
......@@ -730,7 +730,7 @@ The storage may raise it later:
>>> def checkCurrentSerialInTransaction(oid, serial, trans):
... if not trans == transaction.get(): print 'oops'
... print 'checkCurrentSerialInTransaction', `oid`
... print 'checkCurrentSerialInTransaction', repr(oid)
... store.badness = ReadConflictError(oid=oid)
>>> def tpc_vote(t):
......
......@@ -272,9 +272,9 @@ class FileStorageTests(
self.open()
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)
self.assertEqual(oid, ('\000' * 7) + x)
self.assertEqual(oid, (b'\000' * 7) + x)
key = next_oid
expected_data, expected_tid = self._storage.load(oid, '')
self.assertEqual(expected_data, data)
......@@ -432,7 +432,7 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase):
# Raise an exception if the tids in FileStorage fs aren't
# strictly increasing.
def checkIncreasingTids(fs):
lasttid = '\0' * 8
lasttid = b'\0' * 8
for txn in fs.iterator():
if lasttid >= txn.tid:
raise ValueError("tids out of order %r >= %r" % (lasttid, txn.tid))
......
......@@ -50,7 +50,7 @@ class TestPList(unittest.TestCase):
eq(str(u0), str(l0), "str(u0) == str(l0)")
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__
......
......@@ -147,11 +147,11 @@ class RecoverTest(ZODB.tests.util.TestCase):
L = self.storage.undoLog()
r = L[3]
tid = base64.decodestring(r["id"] + "\n")
tid = base64.decodestring(r["id"] + b"\n")
pos1 = self.storage._txn_find(tid, 0)
r = L[8]
tid = base64.decodestring(r["id"] + "\n")
tid = base64.decodestring(r["id"] + b"\n")
pos2 = self.storage._txn_find(tid, 0)
self.storage.close()
......@@ -185,7 +185,7 @@ class RecoverTest(ZODB.tests.util.TestCase):
# Find a transaction near the end.
L = self.storage.undoLog()
r = L[1]
tid = base64.decodestring(r["id"] + "\n")
tid = base64.decodestring(r["id"] + b"\n")
pos = self.storage._txn_find(tid, 0)
# Overwrite its status with 'c'.
......
......@@ -66,7 +66,7 @@ def deprecated38(msg):
warnings.warn("This will be removed in ZODB 3.8:\n%s" % msg,
DeprecationWarning, stacklevel=3)
z64 = '\0'*8
z64 = b'\0' * 8
assert sys.hexversion >= 0x02030000
......@@ -145,7 +145,7 @@ tid_repr = serial_repr
# For example, produce
# '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):
result = tid_repr(tid)
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