Dolmen Zope3 Grok存储注释
dolmen.storage的Python项目详细描述
dolmen.storage定义了一个清晰的高级api来处理可插入的 存储组件。
部件
储存
存储器是专用于存储内容的组件。它的行为就像 一个容器,提供接口dolmen.storage.istage。
基于zodb,两个istorage组件是现成的 树:
>>> from dolmen.storage import IStorage >>> from dolmen.storage import container >>> from zope.container.interfaces import IContainer >>> otree = container.OOBTreeStorage() >>> itree = container.IOBTreeStorage() >>> IStorage.extends(IContainer) True >>> from zope.interface import verify >>> verify.verifyObject(IStorage, otree) True >>> verify.verifyObject(IStorage, itree) True
委托存储
委派存储是一个组件,其行为类似于存储,但是 将所有容器级方法委派给存储区 属性:
>>> from dolmen.storage import IDelegatedStorage, DelegatedStorage >>> class MyStorage(DelegatedStorage): ... def __init__(self): ... self.storage = container.OOBTreeStorage() >>> container = MyStorage() >>> verify.verifyObject(IDelegatedStorage, container) True >>> container['manfred'] = 'mammoth' >>> 'manfred' in container True >>> 'manfred' in container.storage True
存储属性必须是有效的历史记录:
>>> class FailingStorage(DelegatedStorage): ... def __init__(self): ... self.storage = list() >>> container = FailingStorage() Traceback (most recent call last): ... SchemaNotProvided
注释
这些存储组件被用来提供非常灵活的 注释存储设施。
注释存储
注意!
此功能在包的测试中有详细说明。请读 有关注释存储的更多信息的测试。
注释存储提供了一种在 注释容器:
>>> import grokcore.component as grok >>> from dolmen.storage import AnnotationStorage >>> from zope.annotation.interfaces import IAnnotations >>> from zope.annotation.interfaces import IAttributeAnnotatable >>> class Mammoth(object): ... '''A furry creature ... ''' ... grok.implements(IAttributeAnnotatable) >>> class NamedStorage(AnnotationStorage): ... grok.name('some.name') >>> manfred = Mammoth() >>> named_storage = NamedStorage(manfred) >>> IDelegatedStorage.providedBy(named_storage) True >>> named_storage['test'] = 'This is a simple test' >>> list(named_storage.values()) ['This is a simple test'] >>> annotations = IAnnotations(manfred).get("some.name") >>> annotations == named_storage.storage True >>> annotations['test'] 'This is a simple test'
注释属性
注意!
此功能在包的测试中有详细说明。请读 测试以获取有关注释属性的更多信息。
Annotation属性允许直接访问批注 通过字段属性(如属性:
>>> from zope.schema import TextLine >>> from zope.interface import Interface >>> from dolmen.storage import AnnotationProperty >>> class WildMammoth(object): ... '''A furry creature ... ''' ... grok.implements(IAttributeAnnotatable) >>> class IRidingMount(Interface): ... rider = TextLine(title=u'Name of the rider', default=None) >>> class MammothRiding(grok.Adapter): ... rider = AnnotationProperty(IRidingMount['rider']) >>> wooly = WildMammoth() >>> annotator = MammothRiding(wooly) >>> annotator.rider = u'Grok' >>> IAnnotations(wooly).get("rider") u'Grok'
更改日志
0.4(2010-12-23)
- 委托的AnnotationStorage现在使用 zope.location.LocationProxy以避免写入位置 直接有关存储对象的信息。这将删除所有相关的 读/写冲突。
0.3(2010-02-21)
- 已清除所有依赖项。现在,dolmen.storage是100%zope.app 免费的。
0.2(2009-12-26)
- ZTK兼容性导入更改。
0.1(2009-10-19)
- 初始版本