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

Tres Seaver tseaver at palladion.com
Wed Feb 13 21:42:55 GMT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sean Upton wrote:
> 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.

It would likely be more forward-compatible (avoiding a potential
deprecation warning) to try importing first from 'transaction', and then
fall back to 'ZODB.POSExcception'.

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

Rather than using a flag, I think I would be tempted to do the work in
the 'else:' clause of the try-wrapped import.  That's just style,
though:  your way should work fine.

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

That part of the diff looks fine to me.

> 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
> 


- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHs2Rf+gerLs4ltQ4RAhV1AJ0aCbVRRgUnoE0cX8jMqqFCbRaLMQCfXKmx
1PyhH8GxStqHkNiDB9tOvlE=
=Bemq
-----END PGP SIGNATURE-----



More information about the storm mailing list