提供用于存储密钥/值对的层。
ftw.dictstorage的Python项目详细描述
简介
这个包提供了一个存储密钥/值对的层储藏室 可以通过提供 使用dict存储的上下文。
示例
适配器默认使用非持久dict:
>>> from ftw.dictstorage.interfaces import IDictStorage >>> context = layer['example_context'] >>> print context <ftw.dictstorage.testing.ExampleContext object at ...> >>> storage = IDictStorage(context) >>> storage['key'] = 'value' >>> print storage['key'] value >>> print storage.storage {'key': 'value'} >>> print IDictStorage(context).storage {}
要配置自定义存储,请实现自己的IConfig,它使用 自定义IDictStorage:
>>> from ftw.dictstorage.interfaces import IConfig >>> from ftw.dictstorage.base import DictStorage >>> from zope.component import provideAdapter, adapts >>> from zope.interface import Interface, alsoProvides, implements >>> context = layer['example_context'] >>> class IMyContext(Interface): ... pass >>> alsoProvides(context, IMyContext) >>> class ContextStorageConfig(object): ... implements(IConfig) ... adapts(IMyContext) ... ... def __init__(self, context): ... self.context = context ... ... def get_storage(self): ... if not hasattr(self.context, '_dictstorage'): ... self.context._dictstorage = {} ... return self.context._dictstorage >>> provideAdapter(ContextStorageConfig) >>> class ContextDictStorage(DictStorage): ... implements(IDictStorage) ... adapts(IMyContext, IConfig) ... ... def __init__(self, context, config): ... self.context = context ... self.config = config ... self._storage = config.get_storage() ... ... @property ... def storage(self): ... return self._storage ... >>> provideAdapter(ContextDictStorage) >>> storage = IDictStorage(context) >>> storage['foo'] = 'bar' >>> print storage['foo'] bar >>> print context._dictstorage {'foo': 'bar'} >>> print IDictStorage(context)['foo'] bar
如果使用sqlalchemy,
链接
变更日志
1.2(2012-06-05)
- 声明zope依赖项。 [乔恩]
- 更新自述文件。 [乔恩]
1.1(2012-03-28)
- 从idictstorage接口定义中删除“self”。 这使得使用verifyClass验证实现成为可能。 [乔恩]
1.0(2011-11-17)
- 为plone 4.1添加了测试构建 [eschmutz]
1.0A4(2011-07-12)
- 某些类方法的固定签名 [lgraf]