Zope Container
Project description
This package define interfaces of container components, and provides container implementations such as a BTreeContainer and OrderedContainer, as well as the base class used by zope.site.folder for the Folder implementation.
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.container.interfaces import IContainer, IContained >>> from zope.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.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.8.0 (2009-04-03)
Change configure.zcml to not depend on zope.app.component. Fixes: https://bugs.launchpad.net/bugs/348329
Moved the declaration of IOrderedContainer.updateOrder to a new, basic IOrdered interface and let IOrderedContainer inherit it. This allows easier reuse of the declaration.
3.7.2 (2009-03-12)
Fix: added missing ComponentLookupError, missing since revision 95429 and missing in last release.
Adapt to the move of IDefaultViewName from zope.component.interfaces to zope.publisher.interfaces.
Add support for reserved names for containers. To specify reserved names for some container, you need to provide an adapter from the container to the zope.container.interfaces.IReservedNames interface. The default NameChooser is now also aware of reserved names.
3.7.1 (2009-02-05)
Raise more “Pythonic” errors from __setitem__, losing the dependency on zope.exceptions:
o zope.exceptions.DuplicationError -> KeyError
o zope.exceptions.UserError -> ValueError
Moved import of IBroken interface to use new zope.broken package, which has no dependencies beyond zope.interface.
Made test part pull in the extra test requirements of this package.
Split the z3c.recipe.compattest configuration out into a new file, compat.cfg, to reduce the burden of doing standard unit tests.
Stripped out bogus develop eggs from buildout.cfg.
3.7.0 (2009-01-31)
Split this package off zope.app.container. This package is intended to have far less dependencies than zope.app.container.
This package also contains the container implementation that used to be in zope.app.folder.
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.container-3.8.0-py2.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4107f2da774cd4b598f4d6d991ab955af09309ff82ee77e174b3a20005b7ba1e |
|
MD5 | 0d932b1a9965b9471cdb2a821f0310b7 |
|
BLAKE2b-256 | 2621dcc78a3f83a72220ee5fefea17c2cf35f849fd76bc499b4492f2c6dd21bf |
Hashes for zope.container-3.8.0-py2.6-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7201f7a51b374f557e0353744d829341b287a15c93e27f48d526e614697d65 |
|
MD5 | dc32ec5f02ed90177ea098d6ce80e424 |
|
BLAKE2b-256 | 0262694b4e7db5dfee2675348a44ed5589e909be2344dc6e60108ef3af6a78e6 |
Hashes for zope.container-3.8.0-py2.5-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 248571d4f37c41c5e71e327637635268e64ab4f996254441f3892509a92a9095 |
|
MD5 | 7377a80a0c8a1d5fa12087c840a7e82d |
|
BLAKE2b-256 | 4ca9ac69baac1a1327a48e71a3ab591fa1bb836653bf0a6945cb01ccfee8e350 |
Hashes for zope.container-3.8.0-py2.4-win32.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f87577888bfa38724f489981f24e16c3138c7b52579a5eae6d8c5ef36daf31 |
|
MD5 | 91dbf9528cb2c33e907262100a7f6fb4 |
|
BLAKE2b-256 | f46e7fd5ab3b84cd24d03912bd59780afc6b704567c3aa558a92cb1d34583c9b |