# HG changeset patch # User Thierry Florac # Date 1350596665 -7200 # Node ID ad0c70fceea98e403d5f191a5278a5d343833255 # Parent 612a350cc660a333e6c94031807b14b86f1d2b1c# Parent b28d7a44b81fc6f9b162dd7b6a73b8f2a1426370 Merge with b28d7a44b81fc6f9b162dd7b6a73b8f2a1426370 diff -r b28d7a44b81f -r ad0c70fceea9 src/ztfy/utils/interfaces.py --- a/src/ztfy/utils/interfaces.py Thu Oct 18 11:22:16 2012 +0200 +++ b/src/ztfy/utils/interfaces.py Thu Oct 18 23:44:25 2012 +0200 @@ -23,7 +23,7 @@ # import local interfaces # import Zope3 packages -from zope.interface import Interface +from zope.interface import Interface, Attribute from zope.schema import TextLine, Int, Password, Bool # import local packages @@ -189,6 +189,8 @@ required=True, default=False) + connection = Attribute(_("Opened ZEO connection")) + def getSettings(self): """Get ZEO connection setting as a JSON dict""" diff -r b28d7a44b81f -r ad0c70fceea9 src/ztfy/utils/zodb.py --- a/src/ztfy/utils/zodb.py Thu Oct 18 11:22:16 2012 +0200 +++ b/src/ztfy/utils/zodb.py Thu Oct 18 23:44:25 2012 +0200 @@ -45,6 +45,10 @@ implements(IZEOConnection) + _storage = None + _db = None + _connection = None + server_name = FieldProperty(IZEOConnection['server_name']) server_port = FieldProperty(IZEOConnection['server_port']) storage = FieldProperty(IZEOConnection['storage']) @@ -79,6 +83,21 @@ db = DB(storage) return (storage, db) if get_storage else db + @property + def connection(self): + return self._connection + + def __enter__(self): + self._storage, self._db = self.getConnection(get_storage=True) + self._connection = self._db.open() + return self + + def __exit__(self, exc_type, exc_value, traceback): + if self._connection is not None: + self._connection.close() + if self._storage is not None: + self._storage.close() + class ZEOConnectionUtility(ZEOConnectionInfo, Persistent, Contained): """Persistent ZEO connection settings utility"""