[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Avoid repr(tid) (use tid.raw()).

Tres Seaver cvs-admin at zope.org
Sat Dec 15 19:28:11 UTC 2012


Log message for revision 128679:
  Avoid repr(tid) (use tid.raw()).
  
  Ensure that we use bytes literals for tid values.
  
  Remove non-comment / docstring use of backticks.

Changed:
  U   ZODB/trunk/src/ZODB/BaseStorage.py
  U   ZODB/trunk/src/ZODB/FileStorage/FileStorage.py
  U   ZODB/trunk/src/ZODB/FileStorage/fspack.py
  U   ZODB/trunk/src/ZODB/MappingStorage.py
  U   ZODB/trunk/src/ZODB/blob.py
  U   ZODB/trunk/src/ZODB/fsrecover.py
  U   ZODB/trunk/src/ZODB/scripts/fstest.py
  U   ZODB/trunk/src/ZODB/scripts/migrate.py
  U   ZODB/trunk/src/ZODB/scripts/repozo.py
  U   ZODB/trunk/src/ZODB/scripts/zodbload.py
  U   ZODB/trunk/src/ZODB/tests/BasicStorage.py
  U   ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py
  U   ZODB/trunk/src/ZODB/tests/blob_packing.txt
  U   ZODB/trunk/src/ZODB/tests/testConnection.py
  U   ZODB/trunk/src/ZODB/tests/testFileStorage.py
  U   ZODB/trunk/src/ZODB/tests/testPersistentList.py
  U   ZODB/trunk/src/ZODB/tests/testRecover.py
  U   ZODB/trunk/src/ZODB/utils.py

-=-
Modified: ZODB/trunk/src/ZODB/BaseStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/BaseStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/BaseStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -380,7 +380,7 @@
                 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:

Modified: ZODB/trunk/src/ZODB/FileStorage/FileStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/FileStorage/FileStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/FileStorage/FileStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -894,7 +894,7 @@
 
         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 @@
         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 @@
             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 @@
 
     pos = start
     seek(start)
-    tid = '\0' * 7 + '\1'
+    tid = b'\0' * 7 + b'\1'
 
     while 1:
         # Read the transaction record
@@ -1664,7 +1665,7 @@
         # 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 @@
         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:

Modified: ZODB/trunk/src/ZODB/FileStorage/fspack.py
===================================================================
--- ZODB/trunk/src/ZODB/FileStorage/fspack.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/FileStorage/fspack.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -53,7 +53,7 @@
             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

Modified: ZODB/trunk/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/MappingStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/MappingStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -189,7 +189,7 @@
         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

Modified: ZODB/trunk/src/ZODB/blob.py
===================================================================
--- ZODB/trunk/src/ZODB/blob.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/blob.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -435,7 +435,8 @@
 
         """
         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 @@
 
         # 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()
 

Modified: ZODB/trunk/src/ZODB/fsrecover.py
===================================================================
--- ZODB/trunk/src/ZODB/fsrecover.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/fsrecover.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -314,7 +314,7 @@
                     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:

Modified: ZODB/trunk/src/ZODB/scripts/fstest.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/fstest.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/scripts/fstest.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -91,7 +91,7 @@
         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 @@
     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:

Modified: ZODB/trunk/src/ZODB/scripts/migrate.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/migrate.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/scripts/migrate.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -262,7 +262,7 @@
                         '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:

Modified: ZODB/trunk/src/ZODB/scripts/repozo.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/repozo.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/scripts/repozo.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -283,7 +283,7 @@
 
 
 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()

Modified: ZODB/trunk/src/ZODB/scripts/zodbload.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/zodbload.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/scripts/zodbload.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -319,7 +319,7 @@
         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()

Modified: ZODB/trunk/src/ZODB/tests/BasicStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/BasicStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/BasicStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -32,11 +32,11 @@
 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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
             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):

Modified: ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/MVCCMappingStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -30,7 +30,7 @@
     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 @@
             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

Modified: ZODB/trunk/src/ZODB/tests/blob_packing.txt
===================================================================
--- ZODB/trunk/src/ZODB/tests/blob_packing.txt	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/blob_packing.txt	2012-12-15 19:28:08 UTC (rev 128679)
@@ -65,7 +65,7 @@
 
     >>> 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:

Modified: ZODB/trunk/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testConnection.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/testConnection.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -659,7 +659,7 @@
     >>> 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 @@
 
     >>> 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):

Modified: ZODB/trunk/src/ZODB/tests/testFileStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testFileStorage.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/testFileStorage.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -272,9 +272,9 @@
         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 @@
 # 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))

Modified: ZODB/trunk/src/ZODB/tests/testPersistentList.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testPersistentList.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/testPersistentList.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -50,7 +50,7 @@
 
         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__
 

Modified: ZODB/trunk/src/ZODB/tests/testRecover.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testRecover.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/tests/testRecover.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -147,11 +147,11 @@
 
         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 @@
         # 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'.

Modified: ZODB/trunk/src/ZODB/utils.py
===================================================================
--- ZODB/trunk/src/ZODB/utils.py	2012-12-15 15:51:26 UTC (rev 128678)
+++ ZODB/trunk/src/ZODB/utils.py	2012-12-15 19:28:08 UTC (rev 128679)
@@ -66,7 +66,7 @@
     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 @@
 
 # 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:



More information about the Zodb-checkins mailing list