Skip to main content

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.6 (2008-08-06)

  • no changes. Retag for correct release on PyPI

3.5.5 (2008-07-27)

  • Made C code compatible with Python 2.5 on 64bit architectures.

3.5.4 (2008-07-16)

  • fixed #238579 / #163149: error with unicode traversing

  • fixed #221025adding menu is sorted with translated item

    by using a collator (better localized sorting)

  • fixed #227617 :
    • prevent the namechooser from failing on ‘+’, ‘@’ and ‘/’

    • added tests in the namechooser

    • be sure the name chooser returns unicode

  • fixed #175388 : the setitem’s size modification is now done in setitemf: setting an existing item does not change the size, and the event subscribers should see the new size instead of the old size. Reimplemented the BTreeContainer so that it directly accesses the btree methods (removed an old #TODO)

3.5.3 (2007-11-09)

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


Download files

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

Source Distribution

zope.app.container-3.5.6.tar.gz (117.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zope.app.container-3.5.6-py2.5-win32.egg (181.2 kB view details)

Uploaded Egg

zope.app.container-3.5.6-py2.4-win32.egg (183.3 kB view details)

Uploaded Egg

File details

Details for the file zope.app.container-3.5.6.tar.gz.

File metadata

File hashes

Hashes for zope.app.container-3.5.6.tar.gz
Algorithm Hash digest
SHA256 e248d37120531e82bb968379f3bacdcea1292c9272e4b2c94750c728d8973241
MD5 fb7e7d9f142e7667b96c2a12f0a7050c
BLAKE2b-256 41b42b5224965c667a07bf685566a446f7c09d1b7824362f9bbcc7d4463524d5

See more details on using hashes here.

File details

Details for the file zope.app.container-3.5.6-py2.5-win32.egg.

File metadata

File hashes

Hashes for zope.app.container-3.5.6-py2.5-win32.egg
Algorithm Hash digest
SHA256 18e599dbd84eb61dd5b86d2bc7dfdb9ad64f4731e977e80b6b781c3e3e2fc3a4
MD5 0a5d8d3f490a1a2227ed8cf040773eaa
BLAKE2b-256 4c34446b0e4704568f7d7d0fa194bc672478b8ffaf2a819949f5f26057012276

See more details on using hashes here.

File details

Details for the file zope.app.container-3.5.6-py2.4-win32.egg.

File metadata

File hashes

Hashes for zope.app.container-3.5.6-py2.4-win32.egg
Algorithm Hash digest
SHA256 4a7994d49e057d5813d842cce9ece9097eb025205669935707d4498463aed1c3
MD5 a4baf5a1e7f855fc65d8cf2813c32b22
BLAKE2b-256 0a40435228aa9d3aaa72e536dbc2d758ac069dfe2afd50e09f7e55da64f96dda

See more details on using hashes here.

Supported by

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