[Zodb-checkins] SVN: ZODB/trunk/src/Z dryed convenience functions a little
Jim Fulton
jim at zope.com
Fri Nov 18 10:41:46 UTC 2011
Log message for revision 123419:
dryed convenience functions a little
Changed:
U ZODB/trunk/src/ZEO/__init__.py
U ZODB/trunk/src/ZODB/DB.py
-=-
Modified: ZODB/trunk/src/ZEO/__init__.py
===================================================================
--- ZODB/trunk/src/ZEO/__init__.py 2011-11-18 06:06:49 UTC (rev 123418)
+++ ZODB/trunk/src/ZEO/__init__.py 2011-11-18 10:41:45 UTC (rev 123419)
@@ -21,20 +21,17 @@
"""
-def DB(*args, **kw):
- import ZEO.ClientStorage, ZODB
- return ZODB.DB(ZEO.ClientStorage.ClientStorage(*args, **kw))
-
-def connection(*args, **kw):
- db = DB(*args, **kw)
- conn = db.open()
- conn.onCloseCallback(db.close)
- return conn
-
def client(*args, **kw):
import ZEO.ClientStorage
return ZEO.ClientStorage.ClientStorage(*args, **kw)
+def DB(*args, **kw):
+ import ZODB
+ return ZODB.DB(client(*args, **kw))
+
+def connection(*args, **kw):
+ return DB(*args, **kw).open_then_close_db_when_connection_closes()
+
def server(path=None, blob_dir=None, storage_conf=None, zeo_conf=None,
port=None):
"""Convenience function to start a server for interactive exploration
Modified: ZODB/trunk/src/ZODB/DB.py
===================================================================
--- ZODB/trunk/src/ZODB/DB.py 2011-11-18 06:06:49 UTC (rev 123418)
+++ ZODB/trunk/src/ZODB/DB.py 2011-11-18 10:41:45 UTC (rev 123419)
@@ -956,7 +956,16 @@
def new_oid(self):
return self.storage.new_oid()
+ def open_then_close_db_when_connection_closes(self):
+ """Create and return a connection.
+ When the connection closes, the database will close too.
+ """
+ conn = self.open()
+ conn.onCloseCallback(self.close)
+ return conn
+
+
class ContextManager:
"""PEP 343 context manager
"""
@@ -1016,7 +1025,4 @@
return "%s:%s" % (self._storage.sortKey(), id(self))
def connection(*args, **kw):
- db = DB(*args, **kw)
- conn = db.open()
- conn.onCloseCallback(db.close)
- return conn
+ return DB(*args, **kw).open_then_close_db_when_connection_closes()
More information about the Zodb-checkins
mailing list