[Zodb-checkins] SVN: ZODB/trunk/src/ Enhanced the database opening conveniences:
Jim Fulton
jim at zope.com
Thu May 13 12:41:54 EDT 2010
Log message for revision 112283:
Enhanced the database opening conveniences:
- You can now pass storage keyword arguments to ZODB.DB and
ZODB.connection.
- You can now pass None (rather than a storage or file name) to get
a database with a mapping storage.
Changed:
U ZODB/trunk/src/CHANGES.txt
U ZODB/trunk/src/ZODB/DB.py
U ZODB/trunk/src/ZODB/tests/testDB.py
-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt 2010-05-13 16:16:48 UTC (rev 112282)
+++ ZODB/trunk/src/CHANGES.txt 2010-05-13 16:41:54 UTC (rev 112283)
@@ -24,6 +24,14 @@
(transaction-manager attempts method) introduced in the
``transaction`` 1.1.0 release.
+- Enhanced the database opening conveniences:
+
+ - You can now pass storage keyword arguments to ZODB.DB and
+ ZODB.connection.
+
+ - You can now pass None (rather than a storage or file name) to get
+ a database with a mapping storage.
+
Bugs Fixed
----------
Modified: ZODB/trunk/src/ZODB/DB.py
===================================================================
--- ZODB/trunk/src/ZODB/DB.py 2010-05-13 16:16:48 UTC (rev 112282)
+++ ZODB/trunk/src/ZODB/DB.py 2010-05-13 16:41:54 UTC (rev 112283)
@@ -386,7 +386,7 @@
databases=None,
xrefs=True,
max_saved_oids=999,
- ):
+ **storage_args):
"""Create an object database.
:Parameters:
@@ -409,7 +409,10 @@
"""
if isinstance(storage, basestring):
from ZODB import FileStorage
- storage = ZODB.FileStorage.FileStorage(storage)
+ storage = ZODB.FileStorage.FileStorage(storage, **storage_args)
+ elif storage is None:
+ from ZODB import MappingStorage
+ storage = ZODB.MappingStorage.MappingStorage(**storage_args)
# Allocate lock.
x = threading.RLock()
Modified: ZODB/trunk/src/ZODB/tests/testDB.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testDB.py 2010-05-13 16:16:48 UTC (rev 112282)
+++ ZODB/trunk/src/ZODB/tests/testDB.py 2010-05-13 16:41:54 UTC (rev 112283)
@@ -161,6 +161,17 @@
>>> db.close()
"""
+def passing_None_to_DB():
+ """You can pass None DB to get a MappingStorage.
+
+ (Also note that we can access DB in ZODB.)
+
+ >>> db = ZODB.DB(None)
+ >>> db.storage # doctest: +ELLIPSIS
+ <ZODB.MappingStorage.MappingStorage object at ...
+ >>> db.close()
+ """
+
def open_convenience():
"""Often, we just want to open a single connection.
@@ -180,6 +191,22 @@
>>> conn.root()
{'x': 1}
>>> db.close()
+
+
+ We can pass storage-specific arguments if they don't conflict with
+ DB arguments.
+
+ >>> conn = ZODB.connection('data.fs', blob_dir='blobs')
+ >>> conn.root()['b'] = ZODB.blob.Blob('test')
+ >>> transaction.commit()
+ >>> conn.close()
+
+ >>> db = ZODB.DB('data.fs', blob_dir='blobs')
+ >>> conn = db.open()
+ >>> conn.root()['b'].open().read()
+ 'test'
+ >>> db.close()
+
"""
if sys.version_info >= (2, 6):
More information about the Zodb-checkins
mailing list