Commit 6c88dc5c authored by Jim Fulton's avatar Jim Fulton

Updated DemoStorage ZConfig support.

parent 40e98541
......@@ -278,3 +278,52 @@ storage wrapped around it when necessary:
>>> 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()
......@@ -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>
......
......@@ -120,15 +120,17 @@ class MappingStorage(BaseConfig):
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):
......
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