Commit e17bbd1d authored by Jim Fulton's avatar Jim Fulton

dryed convenience functions a little

parent 7e84d9b4
......@@ -21,20 +21,17 @@ ZEO is now part of ZODB; ZODB's home on the web is
"""
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
......
......@@ -956,6 +956,15 @@ class DB(object):
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 @@ class TransactionalUndo(object):
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment