[Zodb-checkins] CVS: Zope3/src/zodb/storage - base.py:1.4
Barry Warsaw
barry@wooz.org
Mon, 30 Dec 2002 17:37:17 -0500
Update of /cvs-repository/Zope3/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv498
Modified Files:
base.py
Log Message:
Cleanups:
- rename z64 to ZERO
- Rewrite the bsddb imports to use either Python 2.3's bsddb package
or the pybsddb (bsddb3) distutils package, in that order.
- get rid of duplicate imports, regroup imports and constants
- whitespace normalization
- booleans where appropriate
Also, in BerkeleyBase.__init__(): test env against StringTypes, since
it comes in as a unicode if configured via zcml (eventually, env may
go away).
=== Zope3/src/zodb/storage/base.py 1.3 => 1.4 ===
--- Zope3/src/zodb/storage/base.py:1.3 Mon Dec 30 11:43:15 2002
+++ Zope3/src/zodb/storage/base.py Mon Dec 30 17:37:16 2002
@@ -12,8 +12,6 @@
#
##############################################################################
-
-
"""Handy standard storage machinery
$Id$
@@ -21,15 +19,45 @@
__metaclass__ = type
+import os
+import time
+import errno
+import shutil
import threading
+from types import StringTypes
+import logging
+
+# In Python 2.3, we can simply use the bsddb module, but for Python 2.2, we
+# need to use pybsddb3, a.k.a. bsddb3.
+try:
+ try:
+ from bsddb import _db as db
+ except ImportError:
+ from bsddb3 import db
+except ImportError:
+ db = None
+
from zodb import interfaces
from zodb.timestamp import newTimeStamp, TimeStamp
from zodb.interfaces import ITransactionAttrs
-z64='\0'*8
+# BaseStorage provides primitives for lock acquisition and release, and a host
+# of other methods, some of which are overridden here, some of which are not.
+from zodb.lockfile import lock_file
+from zodb.serialize import findrefs
+
+ZERO = '\0'*8
+GBYTES = 1024 * 1024 * 1000
+JOIN_TIME = 10
+
+
+class PackStop(Exception):
+ """Escape hatch for pack operations."""
+
+
class BaseStorage:
_transaction = None # Transaction that is being committed
- _serial = z64 # Transaction serial number
+ _serial = ZERO # Transaction serial number
_tstatus = ' ' # Transaction status, used for copying data
_is_read_only = False
@@ -37,17 +65,17 @@
self._name = name
# Allocate locks:
- l=threading.RLock()
+ l = threading.RLock()
self._lock_acquire = l.acquire
self._lock_release = l.release
- l=threading.Lock()
+ l = threading.Lock()
self._commit_lock_acquire = l.acquire
self._commit_lock_release = l.release
self._ts = newTimeStamp()
self._serial = self._ts.raw()
if base is None:
- self._oid = z64
+ self._oid = ZERO
else:
self._oid = base._oid
@@ -86,17 +114,22 @@
if last is None:
self._lock_acquire()
try:
- last=self._oid
- d=ord(last[-1])
- if d < 255: last=last[:-1]+chr(d+1)
- else: last=self.new_oid(last[:-1])
- self._oid=last
+ last = self._oid
+ d = ord(last[-1])
+ if d < 255:
+ last = last[:-1] + chr(d+1)
+ else:
+ last = self.new_oid(last[:-1])
+ self._oid = last
return last
- finally: self._lock_release()
+ finally:
+ self._lock_release()
else:
- d=ord(last[-1])
- if d < 255: return last[:-1]+chr(d+1)+'\0'*(8-len(last))
- else: return self.new_oid(last[:-1])
+ d = ord(last[-1])
+ if d < 255:
+ return last[:-1] + chr(d+1) + '\0'*(8-len(last))
+ else:
+ return self.new_oid(last[:-1])
def registerDB(self, db):
pass # we don't care
@@ -110,7 +143,8 @@
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
@@ -295,7 +329,8 @@
self.tpc_begin(transaction, tid, transaction.status)
for r in transaction:
- if verbose: print `r.oid`, r.version, len(r.data)
+ if verbose:
+ print `r.oid`, r.version, len(r.data)
self.restore(r.oid, r.serial, r.data, r.version,
r.data_txn, transaction)
self.tpc_vote(transaction)
@@ -310,45 +345,6 @@
"""Abstract base class for iterator protocol."""
-"""Base class for BerkeleyStorage implementations.
-"""
-__version__ = '$Revision$'.split()[-2:][0]
-
-import os
-import time
-import errno
-import shutil
-import threading
-from types import StringType
-import logging
-
-# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
-# http://pybsddb.sourceforge.net
-try:
- from bsddb3 import db
-except ImportError:
- db = None
-
-# BaseStorage provides primitives for lock acquisition and release, and a host
-# of other methods, some of which are overridden here, some of which are not.
-from zodb.lockfile import lock_file
-
-from zodb.serialize import findrefs
-
-GBYTES = 1024 * 1024 * 1000
-
-# How long should we wait to join one of the background daemon threads? It's
-# a good idea to not set this too short, or we could corrupt our database.
-# That would be recoverable, but recovery could take a long time too, so it's
-# better to shutdown cleanly.
-JOIN_TIME = 10
-
-
-
-class PackStop(Exception):
- """Escape hatch for pack operations."""
-
-
class BerkeleyConfig:
"""Bag of bits for describing various underlying configuration options.
@@ -425,7 +421,7 @@
frequency = 0
packtime = 4 * 60 * 60
classicpack = 0
- read_only = 0
+ read_only = False
def __repr__(self):
d = self.__class__.__dict__.copy()
@@ -495,7 +491,7 @@
self.log('Creating Berkeley environment')
if env == '':
raise TypeError, 'environment name is empty'
- elif isinstance(env, StringType):
+ elif isinstance(env, StringTypes):
self._env, self._lockfile = env_from_string(env, self._config)
else:
self._env = env