[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Updated DemoStorage ZConfig support.
Jim Fulton
jim at zope.com
Thu Oct 30 14:08:21 EDT 2008
Log message for revision 92719:
Updated DemoStorage ZConfig support.
Changed:
U ZODB/trunk/src/ZODB/DemoStorage.test
U ZODB/trunk/src/ZODB/component.xml
U ZODB/trunk/src/ZODB/config.py
-=-
Modified: ZODB/trunk/src/ZODB/DemoStorage.test
===================================================================
--- ZODB/trunk/src/ZODB/DemoStorage.test 2008-10-30 17:57:04 UTC (rev 92718)
+++ ZODB/trunk/src/ZODB/DemoStorage.test 2008-10-30 18:08:21 UTC (rev 92719)
@@ -278,3 +278,52 @@
>>> import os
>>> os.path.exists(blobdir)
False
+
+ZConfig support
+===============
+
+You can configure demo storages using ZConfig, using name, changes,
+and base options:
+
+ >>> import ZODB.config
+ >>> storage = ZODB.config.storageFromString("""
+ ... <demostorage>
+ ... </demostorage>
+ ... """)
+ >>> storage.getName()
+ "DemoStorage('MappingStorage', 'MappingStorage')"
+
+ >>> storage = ZODB.config.storageFromString("""
+ ... <demostorage>
+ ... <filestorage base>
+ ... path base.fs
+ ... </filestorage>
+ ...
+ ... <filestorage changes>
+ ... path changes.fs
+ ... </filestorage>
+ ... </demostorage>
+ ... """)
+ >>> storage.getName()
+ "DemoStorage('base.fs', 'changes.fs')"
+
+ >>> storage.close()
+
+ >>> storage = ZODB.config.storageFromString("""
+ ... <demostorage>
+ ... name bob
+ ... <filestorage>
+ ... path base.fs
+ ... </filestorage>
+ ...
+ ... <filestorage changes>
+ ... path changes.fs
+ ... </filestorage>
+ ... </demostorage>
+ ... """)
+ >>> storage.getName()
+ 'bob'
+ >>> storage.base.getName()
+ 'base.fs'
+
+ >>> storage.close()
Modified: ZODB/trunk/src/ZODB/component.xml
===================================================================
--- ZODB/trunk/src/ZODB/component.xml 2008-10-30 17:57:04 UTC (rev 92718)
+++ ZODB/trunk/src/ZODB/component.xml 2008-10-30 18:08:21 UTC (rev 92719)
@@ -175,8 +175,7 @@
<sectiontype name="demostorage" datatype=".DemoStorage"
implements="ZODB.storage">
<key name="name" />
- <section type="ZODB.storage" name="*" attribute="base" />
- <section type="ZODB.storage" name="changes" attribute="changes" />
+ <multisection type="ZODB.storage" name="*" attribute="factories" />
</sectiontype>
Modified: ZODB/trunk/src/ZODB/config.py
===================================================================
--- ZODB/trunk/src/ZODB/config.py 2008-10-30 17:57:04 UTC (rev 92718)
+++ ZODB/trunk/src/ZODB/config.py 2008-10-30 18:08:21 UTC (rev 92719)
@@ -120,15 +120,17 @@
class DemoStorage(BaseConfig):
def open(self):
+ base = changes = None
+ for factory in self.config.factories:
+ if factory.name == 'changes':
+ changes = factory.open()
+ else:
+ if base is None:
+ base = factory.open()
+ else:
+ raise ValueError("Too many base storages defined!")
+
from ZODB.DemoStorage import DemoStorage
- if self.config.base:
- base = self.config.base.open()
- else:
- base = None
- if self.config.changes:
- changes = self.config.changes.open()
- else:
- changes = None
return DemoStorage(self.config.name, base=base, changes=changes)
class FileStorage(BaseConfig):
More information about the Zodb-checkins
mailing list