[Zope3-dev] Constraints conundrum
Jim Fulton
jim at zope.com
Thu Jan 8 17:10:54 EST 2004
Roché Compaan wrote:
> In my app IOrganisation may contain amongst other things IBranches and
> IBranches in turn may contain IOrganisation. I tried to declare a very
> relaxed constraint on IBranches and "fix up" the constraint afterwards
> but that doesn't work eg.:
>
> class IBranches(Interface):
>
> __setitem__.precondition = ItemTypePrecondition(Interface)
I assume you also had a def for __setitem__.
Get rid of the precondition.
> class IOrganisation(Interface):
>
> __setitem__.precondition = ItemTypePrecondition(IBranches)
ditto
> IBranches.__dict__['_InterfaceClass__attrs']['__setitem__'
> ] = ItemTypePrecondition(IOrganisation)
Don't mess with an interface's dictionary. It's private.
> When I do the above the security checker moans:
Cool. :)
> Module zope.security.checker, line 172, in check
> raise ForbiddenAttribute, (name, object)
> - class: zope.app.container.constraints.ItemTypePrecondition
> - type: __builtin__.instance
>
> I can probably make a precondition that takes an Interface name as
> parameter and lookup the Interface at runtime, but maybe there is
> another way?
Yes:
After creating IOrganization and IBranches, with definitions for __setitem__,
IBranches['__setitem__'].setTaggedValue(
'precondition', ItemTypePrecondition(IOrganization, ...))
and likewise for IOrganization.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list