[Zope-CVS] CVS: Products/Ape/apelib/zope2/setup - TmpStore.py:1.1 __init__.py:1.1 dbtab.py:1.1 patches.py:1.1
Shane Hathaway
shane@zope.com
Sat, 15 Mar 2003 20:13:47 -0500
Update of /cvs-repository/Products/Ape/apelib/zope2/setup
In directory cvs.zope.org:/tmp/cvs-serv12186/apelib/zope2/setup
Added Files:
TmpStore.py __init__.py dbtab.py patches.py
Log Message:
Corrected documentation and circumvented a bug involving relative imports of the apelib module.
=== Added File Products/Ape/apelib/zope2/setup/TmpStore.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from ZODB import POSException
from ZODB.utils import p64, u64
import tempfile
class TmpStore:
"""A storage to support subtransactions."""
_bver = ''
def __init__(self, base_version):
self._transaction = None
if base_version:
self._bver = base_version
self._file = tempfile.TemporaryFile()
# _pos: current file position
# _tpos: file position at last commit point
self._pos = self._tpos = 0L
# _index: map oid to pos of last committed version
self._index = {}
# _tindex: map oid to pos for new updates
self._tindex = {}
self._db = None
self._creating = []
def __del__(self):
# XXX Is this necessary?
self._file.close()
def close(self):
self._file.close()
def getName(self):
return self._db.getName()
def getSize(self):
return self._pos
def load(self, oid, version):
pos = self._index.get(oid)
if pos is None:
return self._storage.load(oid, self._bver)
self._file.seek(pos)
h = self._file.read(8)
oidlen = u64(h)
read_oid = self._file.read(oidlen)
if read_oid != oid:
raise POSException.StorageSystemError('Bad temporary storage')
h = self._file.read(16)
size = u64(h[8:])
serial = h[:8]
return self._file.read(size), serial
# XXX clarify difference between self._storage & self._db._storage
def modifiedInVersion(self, oid):
if self._index.has_key(oid):
return self._bver
return self._db._storage.modifiedInVersion(oid)
def new_oid(self):
return self._db._storage.new_oid()
def registerDB(self, db, limit):
self._db = db
self._storage = db._storage
def store(self, oid, serial, data, version, transaction):
if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction)
self._file.seek(self._pos)
l = len(data)
if serial is None:
serial = '\0' * 8
header = p64(len(oid)) + oid + serial + p64(l)
self._file.write(header)
self._file.write(data)
self._tindex[oid] = self._pos
self._pos += l + len(header)
return serial
def tpc_abort(self, transaction):
if transaction is not self._transaction:
return
self._tindex.clear()
self._transaction = None
self._pos = self._tpos
def tpc_begin(self, transaction):
if self._transaction is transaction:
return
self._transaction = transaction
self._tindex.clear() # Just to be sure!
self._pos = self._tpos
def tpc_vote(self, transaction):
pass
def tpc_finish(self, transaction, f=None):
if transaction is not self._transaction:
return
if f is not None:
f()
self._index.update(self._tindex)
self._tindex.clear()
self._tpos = self._pos
def undoLog(self, first, last, filter=None):
return ()
def versionEmpty(self, version):
# XXX what is this supposed to do?
if version == self._bver:
return len(self._index)
=== Added File Products/Ape/apelib/zope2/setup/__init__.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Run-time Zope 2 configuration modules.
$Id: __init__.py,v 1.1 2003/03/16 01:13:46 shane Exp $
"""
=== Added File Products/Ape/apelib/zope2/setup/dbtab.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Configuration of storage types for DBTab/ZODB
$Id: dbtab.py,v 1.1 2003/03/16 01:13:46 shane Exp $
"""
def convertApeStorageArgs(name, factory=None, **kw):
from apelib.zodb3.db import callMapperFactory
from apelib.zodb3.resource import StaticResource
if factory is None:
raise RuntimeError('factory is required')
mapper, conns = callMapperFactory(factory, kw)
return {
'mapper_resource': StaticResource(mapper),
'tpc_conns': conns,
'name': name,
}
try:
from Products.DBTab.StorageTypes import storage_types
from Products.DBTab.DBTab import database_types
except ImportError:
pass
else:
storage_types['ApeStorage'] = (
'apelib.zodb3.storage', convertApeStorageArgs)
database_types['ApeDB'] = 'apelib.zodb3.db'
=== Added File Products/Ape/apelib/zope2/setup/patches.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Monkey-patches necessary to make apelib work in Zope.
$Id: patches.py,v 1.1 2003/03/16 01:13:46 shane Exp $
"""
from __future__ import nested_scopes
from cPickle import Pickler, Unpickler
from cStringIO import StringIO
from Acquisition import aq_base
from DateTime import DateTime
from apelib.zodb3.utils import copyOf
def applyPersistentExtraPatch():
# We need to do this until mtimes are made available.
# It makes mtime always look like the current time.
def bobobase_modification_time(self):
jar=self._p_jar
oid=self._p_oid
if jar is None or oid is None or getattr(jar, 'no_mtime_available', 0):
return DateTime()
try:
t=self._p_mtime
if t is None: return DateTime()
except: t=0
return DateTime(t)
from Persistence import Persistent
import App.PersistentExtra # Let Zope do its own patching, then override
Persistent.__dict__[
'bobobase_modification_time'] = bobobase_modification_time
def applyCopySupportPatch():
# Fall back to copying by pickle when ZEXP export/import is not
# implemented.
def _getCopy(self, container):
try:
return self._real_getCopy(container)
except NotImplementedError:
return copyOf(aq_base(self))
from OFS.CopySupport import CopySource
CopySource._real_getCopy = CopySource._getCopy
CopySource._getCopy = _getCopy
def applySetObPatch():
# Fall back to copying when move/rename is not possible.
def _setOb(self, id, object):
if object._p_oid is not None:
if (getattr(self, '_use_fixed_oids_', 0) or (
object._p_jar is not None and object._p_jar != self._p_jar)):
old = object
# Forget changes to the original object
old._p_changed = 0
object = copyOf(object)
setattr(self, id, object)
from OFS.ObjectManager import ObjectManager
ObjectManager._setOb = _setOb
def applyTmpStorePatch():
from TmpStore import TmpStore as patched_TmpStore
import ZODB.TmpStore
ZODB.TmpStore.TmpStore = patched_TmpStore
def applyPatches():
applyPersistentExtraPatch()
applyCopySupportPatch()
applySetObPatch()
applyTmpStorePatch()