[Zope3-dev] Constraints conundrum

Roché Compaan roche at upfrontsystems.co.za
Fri Jan 9 00:11:52 EST 2004


* Jim Fulton <jim at zope.com> [2004-01-09 00:14]:
> 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__.

Yep.

> 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.

Cool, thank you!

-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za



More information about the Zope3-dev mailing list