Zope Container
Project description
This package define interfaces of container components, and provides sample container implementations such as a BTreeContainer and OrderedContainer.
Detailed Documentation
Containment constraints
Containment constraints allow us to express restrictions on the types of items that can be placed in containers or on the types of containers an item can be placed in. We express these constraints in interfaces. Let’s define some container and item interfaces:
>>> from zope.app.container.interfaces import IContainer, IContained >>> from zope.app.container.constraints import containers, contains>>> class IBuddyFolder(IContainer): ... contains('.IBuddy')
In this example, we used the contains function to declare that objects that provide IBuddyFolder can only contain items that provide IBuddy. Note that we used a string containing a dotted name for the IBuddy interface. This is because IBuddy hasn’t been defined yet. When we define IBuddy, we can use IBuddyFolder directly:
>>> class IBuddy(IContained): ... containers(IBuddyFolder)
Now, with these interfaces in place, we can define Buddy and BuddyFolder classes and verify that we can put buddies in buddy folders:
>>> from zope import interface>>> class Buddy: ... interface.implements(IBuddy)>>> class BuddyFolder: ... interface.implements(IBuddyFolder)>>> from zope.app.container.constraints import checkObject, checkFactory >>> from zope.component.factory import Factory>>> checkObject(BuddyFolder(), 'x', Buddy()) >>> checkFactory(BuddyFolder(), 'x', Factory(Buddy)) True
If we try to use other containers or folders, we’ll get errors:
>>> class Container: ... interface.implements(IContainer)>>> class Contained: ... interface.implements(IContained)>>> checkObject(Container(), 'x', Buddy()) ... # doctest: +ELLIPSIS Traceback (most recent call last): InvalidContainerType: ...>>> checkFactory(Container(), 'x', Factory(Buddy)) False>>> checkObject(BuddyFolder(), 'x', Contained()) ... # doctest: +ELLIPSIS Traceback (most recent call last): InvalidItemType: ...>>> checkFactory(BuddyFolder(), 'x', Factory(Contained)) False
In the example, we defined the container first and then the items. We could have defined these in the opposite order:
>>> class IContact(IContained): ... containers('.IContacts')>>> class IContacts(IContainer): ... contains(IContact)>>> class Contact: ... interface.implements(IContact)>>> class Contacts: ... interface.implements(IContacts)>>> checkObject(Contacts(), 'x', Contact())>>> checkFactory(Contacts(), 'x', Factory(Contact)) True>>> checkObject(Contacts(), 'x', Buddy()) ... # doctest: +ELLIPSIS Traceback (most recent call last): InvalidItemType: ...>>> checkFactory(Contacts(), 'x', Factory(Buddy)) False
CHANGES
3.5.3 (2007-11-09)
Send IObjectModifiedEvent when changing the title through the @@contents.html view.
This fixes https://bugs.edge.launchpad.net/zope3/+bug/98483.
3.5.2 (2007-11-01)
Reactivated functional tests.
3.5.1 (2007-10-31)
Resolve ZopeSecurityPolicy and IRolePermissionManager deprecation warning.
3.5.0 (2007-10-11)
Updated package meta-data.
3.5.0a1 (2007-06-29)
Updated bootstrap script to current version.
Store length of BTreeContainer in its own Length object for faster __len__ implementation of huge containers.
3.4.0a1 (2007-04-22)
Initial release as a separate project, corresponds to zope.app.container from Zope 3.4.0a1.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for zope.app.container-3.5.3-py2.5-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6bfc02434bc05c4711dc654e4066c0db0e2d067f5ca26f5024ccf22d14bf8af |
|
MD5 | 28b39ecf4c454ae7e8a56817babf2dd9 |
|
BLAKE2b-256 | 7faec1c7e7332a6caafd8dbe54976d23e0f293c21e9ca86d7e8530979b35168c |
Hashes for zope.app.container-3.5.3-py2.4-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22c0a9c64e9d5b6fa20f6680d96bdd5ce434a68b0d213518069a9aa622906431 |
|
MD5 | 5c2d19f0d292802d1ee110729a92e396 |
|
BLAKE2b-256 | 144ca8ef3944717edb60e9f9f16fb30d9fb3498cd0fd4153c18a12c000282376 |