Skip to main content

Dolmen Zope3 Grok Storage Annotation

Project description defines a clear high-level API to deal with pluggable storage components.



A storage is a component dedicated to store contents. It behaves like a container and provides the interface

Out of the box, two IStorage components are available, based on ZODB BTrees:

>>> from import IStorage
>>> from import container
>>> from zope.container.interfaces import IContainer

>>> otree = container.OOBTreeStorage()
>>> itree = container.IOBTreeStorage()

>>> IStorage.extends(IContainer)

>>> from zope.interface import verify
>>> verify.verifyObject(IStorage, otree)
>>> verify.verifyObject(IStorage, itree)

Delegated storage

A delegated storage is a component behaving like a Storage but delegating all the container-level methods to a storage attribute:

>>> from import IDelegatedStorage, DelegatedStorage

>>> class MyStorage(DelegatedStorage):
...     def __init__(self):
... = container.OOBTreeStorage()
>>> container = MyStorage()

>>> verify.verifyObject(IDelegatedStorage, container)

>>> container['manfred'] = 'mammoth'
>>> 'manfred' in container
>>> 'manfred' in

The storage attribute has to be a valid IStorage:

>>> class FailingStorage(DelegatedStorage):
...     def __init__(self):
... = list()
>>> container = FailingStorage()
Traceback (most recent call last):


These storage components are used to provide a very flexible annotation storage facility.

Annotation Storage

The annotation storage provides a way to delegate the storage in an annotation container:

>>> import grokcore.component as grok
>>> from 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):

>>> manfred = Mammoth()
>>> named_storage = NamedStorage(manfred)
>>> IDelegatedStorage.providedBy(named_storage)

>>> named_storage['test'] = 'This is a simple test'
>>> list(named_storage.values())
['This is a simple test']

>>> annotations = IAnnotations(manfred).get("")
>>> annotations ==
>>> annotations['test']
'This is a simple test'

Annotation property

The annotation property allows a direct access to an annotation storage or value via a FieldProperty-like property:

>>> from zope.schema import TextLine
>>> from zope.interface import Interface
>>> from 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")


0.4 (2010-12-23)

  • The delegated AnnotationStorage now uses a zope.location.LocationProxy to avoid writting the location information directly on the storage object. This removes all related read/write conflicts.

0.3 (2010-02-21)

  • Cleaned all dependencies. Now, is 100% free.

0.2 (2009-12-26)

  • ZTK compatibility imports change.

0.1 (2009-10-19)

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (10.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page