[storm] storm.zope in a minimal zope CA environment

Sean Upton sdupton at gmail.com
Wed Feb 13 20:39:15 GMT 2008


I'm writing applications in minimal zope component architecture
environment, and I'd like to use storm.zope.  To date, this is not
possible, but only for cosmetic reasons (likely optional
dependencies).  I am using zope.component, zope.event, zope.schema,
and the newly liberated transaction package from PYPI.  I am NOT using
ZODB nor zope.app.* packages (thus not zope.security).  I've made
local changes to work around these limitations.  All tests pass for my
changes, with some modification to the storm.zope doctest README.txt.

Changes I found necessary:
1. Fallback to importing TransactionFailedError in zstorm.py from
transaction if import from ZODB fails.  This works with recent (<3mo.)
transaction in svn and pypi.  This is a second choice, so it should
not interfere with previous deployments of earlier ZODB versions.

2. Optionally import zope.security proxy stuff in __init__.py.

3. Make zope.security proxy doctest stuff optional, dependent on
whether zope.security can be imported.

I plan to create a branch in launchpad for my changes, but I would
like some comment/review from the list before I do this (diff pasted
inline below).  Specifically, my changes to the doctests to deal with
possibly optional dependencies and conditional imports needs
review/thought.

bzr diff output is below my sig...

Any comments/ideas appreciated. Thanks,
Sean Upton
sdupton at gmail.com
sean.upton at uniontrib.com

bzr diff:

=== modified file 'storm/zope/__init__.py'
--- storm/zope/__init__.py      2007-09-19 15:59:35 +0000
+++ storm/zope/__init__.py      2008-02-12 20:21:40 +0000
@@ -19,7 +19,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 from zope.interface import classImplements
-from zope.security.checker import NoProxy, BasicTypes, _available_by_default
+try:
+    from zope.security.checker import NoProxy, BasicTypes,
_available_by_default
+    ZOPE_SECURITY = True
+except ImportError:
+    ZOPE_SECURITY = False

 from storm.info import ObjectInfo
 from storm.zope.interfaces import ISQLObjectResultSet
@@ -30,6 +34,7 @@
 # the object info set already).  With this, Storm is able to
 # gracefully handle situations when a proxied object is passed to a
 # Store.
-_available_by_default.append("__storm_object_info__")
-BasicTypes[ObjectInfo] = NoProxy
+if ZOPE_SECURITY:
+    _available_by_default.append("__storm_object_info__")
+    BasicTypes[ObjectInfo] = NoProxy
 classImplements(storm_sqlobject.SQLObjectResultSet, ISQLObjectResultSet)

=== modified file 'storm/zope/zstorm.py'
--- storm/zope/zstorm.py        2007-11-01 16:21:46 +0000
+++ storm/zope/zstorm.py        2008-02-12 20:29:40 +0000
@@ -32,7 +32,11 @@

 import transaction
 from transaction.interfaces import IDataManager, ISynchronizer
-from ZODB.POSException import TransactionFailedError
+try:
+    from ZODB.POSException import TransactionFailedError
+except ImportError:
+    # no ZODB: recent transaction alternately provides TransactionFailedError
+    from transaction.interfaces import TransactionFailedError # >svn r81268

 from storm.zope.interfaces import IZStorm, ZStormError
 from storm.database import create_database

=== modified file 'tests/zope/README.txt'
--- tests/zope/README.txt       2007-09-19 15:59:35 +0000
+++ tests/zope/README.txt       2008-02-13 20:19:05 +0000
@@ -181,14 +181,24 @@
 on Storm-managed objects.

   >>> from storm.info import get_obj_info
-  >>> from zope.security.checker import ProxyFactory
+  >>> try:
+  ...     from zope.security.checker import ProxyFactory
+  ...     ZOPE_SECURITY=True
+  ... except ImportError:
+  ...     ZOPE_SECURITY=False  #tests can pass in a minimal zope environment
+  ...
   >>> from pprint import pprint

   >>> person = store.find(Person).one()
   >>> get_obj_info(person)
   {'store': <...Store object at ...>, 'primary_vars': ...}
-  >>> get_obj_info(ProxyFactory(person))
-  {'store': <...Store object at ...>, 'primary_vars': ...}
+  >>> if ZOPE_SECURITY:
+  ...     value = get_obj_info(ProxyFactory(person))
+  ...     ## get_obj_info() return value equivalent through security proxies:
+  ...     assert type(value['store']) == type(get_obj_info(person)['store'])
+  ...     assert value['store'] == get_obj_info(person)['store']
+  ...     assert value['primary_vars'] == get_obj_info(person)['primary_vars']
+  >>>


 # vim:ts=4:sw=4:et



More information about the storm mailing list