[Zodb-checkins] CVS: Zope/lib/python/ZODB - BaseStorage.py:1.21.2.1

Jeremy Hylton jeremy@zope.com
Tue, 5 Nov 2002 16:58:49 -0500


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv17338

Modified Files:
      Tag: Zope-2_6-branch
	BaseStorage.py 
Log Message:
Backport several bug fixes (and some obscuring indentation errors).
Track new signature for restore().
Fix a mysterious occurrence of 'dumps'.
Make tpc_begin() a read-only method.


=== Zope/lib/python/ZODB/BaseStorage.py 1.21 => 1.21.2.1 ===
--- Zope/lib/python/ZODB/BaseStorage.py:1.21	Wed Aug 28 13:04:16 2002
+++ Zope/lib/python/ZODB/BaseStorage.py	Tue Nov  5 16:58:48 2002
@@ -17,6 +17,7 @@
 import string
 __version__ = string.split('$Revision$')[-2:][0]
 
+import cPickle
 import ThreadLock, bpthread
 import time, UndoLogCompatible
 import POSException
@@ -108,48 +109,54 @@
     def tpc_abort(self, transaction):
         self._lock_acquire()
         try:
-            if transaction is not self._transaction: return
+            if transaction is not self._transaction:
+                return
             self._abort()
             self._clear_temp()
-            self._transaction=None
+            self._transaction = None
             self._commit_lock_release()
-        finally: self._lock_release()
+        finally:
+            self._lock_release()
 
     def _abort(self):
         """Subclasses should redefine this to supply abort actions"""
         pass
 
     def tpc_begin(self, transaction, tid=None, status=' '):
+        if self._is_read_only:
+            raise POSException.ReadOnlyError()
         self._lock_acquire()
         try:
-            if self._transaction is transaction: return
+            if self._transaction is transaction:
+                return
             self._lock_release()
             self._commit_lock_acquire()
             self._lock_acquire()
-            self._transaction=transaction
+            self._transaction = transaction
             self._clear_temp()
 
-            user=transaction.user
-            desc=transaction.description
-            ext=transaction._extension
-            if ext: ext=dumps(ext,1)
-            else: ext=""
-            self._ude=user, desc, ext
+            user = transaction.user
+            desc = transaction.description
+            ext = transaction._extension
+            if ext:
+                ext = cPickle.dumps(ext, 1)
+            else:
+                ext = ""
+            self._ude = user, desc, ext
 
             if tid is None:
-                t=time.time()
-                t=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
-                self._ts=t=t.laterThan(self._ts)
-                self._serial=`t`
+                now = time.time()
+                t = TimeStamp(*(time.gmtime(now)[:5] + (now % 60,)))
+                self._ts = t = t.laterThan(self._ts)
+                self._serial = `t`
             else:
-                self._ts=TimeStamp(tid)
-                self._serial=tid
-
-            self._tstatus=status
+                self._ts = TimeStamp(tid)
+                self._serial = tid
 
+            self._tstatus = status
             self._begin(self._serial, user, desc, ext)
-
-        finally: self._lock_release()
+        finally:
+            self._lock_release()
 
     def _begin(self, tid, u, d, e):
         """Subclasses should redefine this to supply transaction start actions.
@@ -159,7 +166,8 @@
     def tpc_vote(self, transaction):
         self._lock_acquire()
         try:
-            if transaction is not self._transaction: return
+            if transaction is not self._transaction:
+                return
             self._vote()
         finally:
             self._lock_release()
@@ -172,16 +180,17 @@
     def tpc_finish(self, transaction, f=None):
         self._lock_acquire()
         try:
-            if transaction is not self._transaction: return
+            if transaction is not self._transaction:
+                return
             try:
-                if f is not None: f()
-
-                u,d,e=self._ude
+                if f is not None:
+                    f()
+                u, d, e = self._ude
                 self._finish(self._serial, u, d, e)
                 self._clear_temp()
             finally:
-                self._ude=None
-                self._transaction=None
+                self._ude = None
+                self._transaction = None
                 self._commit_lock_release()
         finally:
             self._lock_release()
@@ -272,7 +281,8 @@
                 oid=r.oid
                 if verbose: print `oid`, r.version, len(r.data)
                 if restoring:
-                    self.restore(oid, r.serial, r.data, r.version, transaction)
+                    self.restore(oid, r.serial, r.data, r.version,
+                                 r.data_txn, transaction)
                 else:
                     pre=preget(oid, None)
                     s=self.store(oid, pre, r.data, r.version, transaction)