Class
zope.app.container.constraints.ItemTypePrecondition

Specify a __setitem__ precondition that restricts item types

Items must be one of the given types.

>>> class I1(zope.interface.Interface):
...     pass
>>> class I2(zope.interface.Interface):
...     pass
>>> precondition = ItemTypePrecondition(I1, I2)
>>> class Ob(object):
...     pass
>>> ob = Ob()
>>> class Factory(object):
...     def __call__(self):
...         return Ob()
...     def getInterfaces(self):
...         return zope.interface.implementedBy(Ob)
>>> factory = Factory()
>>> try:
...     precondition(None, 'foo', ob)
... except InvalidItemType, v:
...     print v[0], (v[1] is ob), (v[2] == (I1, I2))
... else:
...     print 'Should have failed'
None True True
>>> try:
...     precondition.factory(None, 'foo', factory)
... except InvalidItemType, v:
...     print v[0], (v[1] is factory), (v[2] == (I1, I2))
... else:
...     print 'Should have failed'
None True True
>>> zope.interface.classImplements(Ob, I2)
>>> precondition(None, 'foo', ob)
>>> precondition.factory(None, 'foo', factory)

Base classes

Implemented Interfaces

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses

There are no known subclasses.