[Zope3-checkins] CVS: ZODB4/src/zodb/storage - bdbfull.py:1.11

Barry Warsaw barry@wooz.org
Tue, 4 Feb 2003 11:44:46 -0500


Update of /cvs-repository/ZODB4/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv19613

Modified Files:
	bdbfull.py 
Log Message:
Simplify some imports (yes, import * is used deliberately), and
simplify exception raising and catching.

Set __implements__

Remove history()


=== ZODB4/src/zodb/storage/bdbfull.py 1.10 => 1.11 ===
--- ZODB4/src/zodb/storage/bdbfull.py:1.10	Fri Jan 24 13:54:12 2003
+++ ZODB4/src/zodb/storage/bdbfull.py	Tue Feb  4 11:44:44 2003
@@ -21,12 +21,14 @@
 import cPickle as pickle
 from struct import pack, unpack
 
-from zodb import interfaces
+# I really don't want a 10 line import or __implements__ :/
+from zodb.interfaces import *
 from zodb.utils import p64, u64
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp
 from zodb.conflict import ConflictResolvingStorage, ResolvedSerial
-from zodb.interfaces import ITransactionAttrs, StorageSystemError
+# I really don't want a 10 line import or __implements__ :/
+from zodb.storage.interfaces import *
 from zodb.storage.base import db, ZERO, BerkeleyBase, PackStop, _WorkThread
 from zodb.storage._helper import incr
 
@@ -52,6 +54,8 @@
 
 
 class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
+    __implements__ = IStorage, IUndoStorage, IVersionStorage
+
     def _init(self):
         # Data Type Assumptions:
         #
@@ -516,7 +520,7 @@
                 oversion = self._versions[ovid]
                 # We're trying to make a change on a version that's different
                 # than the version the current revision is on.  Nuh uh.
-                raise interfaces.VersionLockError(oid, oversion)
+                raise VersionLockError(oid, oversion)
             else:
                 # We're making another change to this object on this version.
                 # The non-version revid is the same as for the previous
@@ -546,7 +550,7 @@
     def store(self, oid, serial, data, version, transaction):
         # Lock and transaction wrapper
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dostore, oid, serial, data, version)
@@ -647,7 +651,7 @@
         # should be considered just a hint, and is ignored if the transaction
         # doesn't exist.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             self._withtxn(
@@ -678,7 +682,7 @@
     def _doAbortVersion(self, txn, version):
         vid = self._vids.get(version)
         if vid is None:
-            raise interfaces.VersionError, 'not a version: %s' % version
+            raise VersionError, 'not a version: %s' % version
         # We need to keep track of the oids that are affected by the abort so
         # that we can return it to the connection, which must invalidate the
         # objects so they can be reloaded.
@@ -757,10 +761,10 @@
         # Abort the version, but retain enough information to make the abort
         # undoable.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         # We can't abort the empty version, because it's not a version!
         if not version:
-            raise interfaces.VersionError
+            raise VersionError
         self._lock_acquire()
         try:
             return self._withtxn(self._doAbortVersion, version)
@@ -832,10 +836,10 @@
         # and dest are version strings, and if we're committing to a
         # non-version, dest will be empty.
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         # Sanity checks
         if not src or src == dest:
-            raise interfaces.VersionCommitError
+            raise VersionCommitError
         self._lock_acquire()
         try:
             return self._withtxn(self._doCommitVersion, src, dest)
@@ -1097,7 +1101,7 @@
             # The object's revision is in it's initial creation state but
             # we're asking for an undo of something other than the initial
             # creation state.  No, no.
-            raise interfaces.UndoError, 'Undoing mismatched zombification'
+            raise UndoError, 'Undoing mismatched zombification'
         last_lrevid     = self._metadata[oid+last_prevrevid][16:24]
         target_metadata = self._metadata[oid+target_prevrevid]
         target_lrevid   = target_metadata[16:24]
@@ -1115,15 +1119,15 @@
             try:
                 data = self.resolveConflict(
                     oid, ctid, tid, self._pickles[oid+target_lrevid])
-            except interfaces.ConflictError:
-                raise interfaces.UndoError('Cannot undo transaction')
+            except ConflictError:
+                raise UndoError, 'Cannot undo transaction'
             return oid, target_metadata, data
 
     def _dotxnundo(self, txn, tid):
         # First, make sure the transaction isn't protected by a pack.
         packtime = self._last_packtime()
         if tid <= packtime:
-            raise interfaces.UndoError, 'Transaction cannot be undone'
+            raise UndoError, 'Transaction cannot be undone'
         # Calculate all the oids of objects modified in this transaction
         newrevs = []
         c = self._txnoids.cursor(txn=txn)
@@ -1183,7 +1187,7 @@
 
     def transactionalUndo(self, tid, transaction):
         if transaction is not self._transaction:
-            raise interfaces.StorageTransactionError(self, transaction)
+            raise StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
             return self._withtxn(self._dotxnundo, tid)
@@ -1254,59 +1258,6 @@
         if last < 0:
             last = abs(last)
         return self._withlock(self._doundolog, first, last, filter)
-
-    def history(self, oid, version=None, size=1, filter=None):
-        self._lock_acquire()
-        try:
-            # Jim says:
-            #
-            #     This documentation is wrong. I think that the version should
-            #     be ignored.  It really shouldn't be in the signature. Zope
-            #     never passes the version argument.
-            #
-            # so we ignore `version', which makes our lives a bit easier.  We
-            # start with the most recent revision of the object, then search
-            # the transaction records backwards until we find enough records.
-            history = []
-            serial, tid = self._getSerialAndTid(oid)
-            # BAW: Again, let KeyErrors percolate up
-            while len(history) < size:
-                # Some information comes out of the revision metadata...
-                vid, nvrevid, lrevid, previd = unpack(
-                    '>8s8s8s8s', self._metadata[oid+tid])
-                # ...while other information comes out of the transaction
-                # metadata.
-                txnmeta = self._txnMetadata[tid]
-                userlen, desclen = unpack('>II', txnmeta[:8])
-                user = txnmeta[8:8+userlen]
-                desc = txnmeta[8+userlen:8+userlen+desclen]
-                # Now get the pickle size
-                data = self._pickles[oid+lrevid]
-                # Create a HistoryEntry structure, which turns out to be a
-                # dictionary with some specifically named entries (BAW:
-                # although this poorly documented).
-                if vid == ZERO:
-                    retvers = ''
-                else:
-                    retvers = self._versions[vid]
-                # The HistoryEntry object
-                d = {'time'       : TimeStamp(tid).timeTime(),
-                     'user_name'  : user,
-                     'description': desc,
-                     'serial'     : serial,
-                     'version'    : retvers,
-                     'size'       : len(data),
-                     }
-                if filter is None or filter(d):
-                    history.append(d)
-                # Chase the link backwards to the next most historical
-                # revision, stopping when we've reached the end.
-                if previd == ZERO:
-                    break
-                serial = tid = previd
-            return history
-        finally:
-            self._lock_release()
 
     # Packing
     #