[Zope3-checkins] CVS: Zope3/src/zodb/storage - base.py:1.22

Barry Warsaw barry@wooz.org
Thu, 20 Mar 2003 17:54:19 -0500


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

Modified Files:
	base.py 
Log Message:
Minor hacks to allow for two in-memory storages based on the Berkeley
storages.

First, if db can't be imported (from bsddb or bsddb3), then we'll fake
just enough of the namespace to allow for the constant and exception
lookups to succeed.

BerkeleyBase.__init__(): Factor out the creation of the environment
into _newenv().  This is enough of a hook so that MemoryStorage can
fake the BerkeleyDB layer.


=== Zope3/src/zodb/storage/base.py 1.21 => 1.22 ===
--- Zope3/src/zodb/storage/base.py:1.21	Mon Mar 17 15:21:10 2003
+++ Zope3/src/zodb/storage/base.py	Thu Mar 20 17:54:19 2003
@@ -35,8 +35,16 @@
         from bsddb3 import db
     berkeley_is_available = True
 except ImportError:
-    db = None
     berkeley_is_available = False
+    # But, DemoStorage piggybacks on the implementation of BDBFullStorage so
+    # create a fake db object that has some useful constants.
+    class db:
+        DB_QUEUE = 1
+        DB_DUP = 2
+
+        class DBNotFoundError: pass
+        class DBKeyEmpty: pass
+
 
 from zodb.conflict import ConflictResolver
 from zodb.timestamp import newTimeStamp, TimeStamp
@@ -494,12 +502,8 @@
 
         self.log('Creating Berkeley environment')
         envdir = config.envdir or name
-        # Use the absolute path to the environment directory as the name.
-        # This should be enough of a guarantee that sortKey() -- which via
-        # BaseStorage uses the name -- is globally unique.
-        envdir = os.path.abspath(envdir)
         self.log('Berkeley environment dir: %s', envdir)
-        self._env, self._lockfile = env_from_string(envdir, config)
+        self._env, self._lockfile = self._newenv(envdir)
 
         BaseStorage.__init__(self, envdir)
         self._is_read_only = config.read_only
@@ -547,6 +551,13 @@
 
     def _init(self):
         raise NotImplementedError
+
+    def _newenv(self, envdir):
+        # Use the absolute path to the environment directory as the name.
+        # This should be enough of a guarantee that sortKey() -- which via
+        # BaseStorage uses the name -- is globally unique.
+        envdir = os.path.abspath(envdir)
+        return env_from_string(envdir, self._config)
 
     def _version_check(self):
         raise NotImplementedError