zope.component, browser:addMenuItem, ZCML factory => ForbiddenAttribute: ('__call__', <...>)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Won't Fix
|
Undecided
|
Unassigned | ||
zope.component |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
> Hi,
>
> I had some difficulty to use "browser:
>
> <browser:
> factory=
> title="MyContent"
> permission=
> />
>
> with my Factory :
>
> <utility
> factory=
> name="myproject
> permission=
> />
>
> mycontent.py file :
>
> from zope.component.
>
> ...
>
> class MyContentFactor
> implements(
>
> title = u"Create a new MyContent"
> description = u"This factory instantiates new MyContent"
>
> def __call__(self):
> return MyContent()
>
> def getInterfaces(
> return implementedBy(
>
> Now, if I try to append a MyContent object through ZMI I've this error :
>
> File "/home/
> i686.egg/
> content = factory()
> File "/home/
> i686.egg/
> self._checker2.
> ForbiddenAttribute: ('__call__', <myproject.
> object at 0x93f5b0c>)
>
> Well, if I look in zope/app/
> method I see this comment :
>
> # TODO: If the factory wrapped by LocationProxy is already a
> Proxy,
> # then ProxyFactory does not do the right thing and the
> # original's checker info gets lost. No factory that was
> # registered via ZCML and was used via addMenuItem worked
> # here. (SR)
>
> I think "No factory that was registered via ZCML and was used via
> addMenuItem worked here" speak about my issue ?
>
> I've looked in zope.app.container browser test and I found this tip :
>
> mycontent.py file fixed with the tip :
>
> from zope.component.
> import zope.security.
>
> ...
>
> class MyContentFactor
> implements(
>
> title = u"Create a new MyContent"
> description = u"This factory instantiates new MyContent"
>
> def __init__(self):
> self.__
> (['__call__'])
>
> def __call__(self):
> return MyContent()
>
> def getInterfaces(
> return implementedBy(
>
> With this __Security_
> a MyContent object through ZMI.
>
> Now, I've some comment and question about it :
>
> * I think this tip isn't "developer friendly", what is the good method ?
>
> * Philipp von Weitershausen's book (Web Component Development with Zope
> 3) give first version of my example (without __Security_
> and its example didn't working with zope 3.4 (zopeproject use). Why this
> compatibility breaking ?
Well, I've this problem with zope.component 3.5.1, it's unstable version. It's a
answer to "Why this compatibility breaking". I think it's a bug.
I know what revision bring the issue : http://
Before the utility function in zope/component/
def utility(_context, provides=None, component=None, factory=None,
if factory:
if component:
raise TypeError("Can't specify factory and component.")
component = factory()
if provides is None:
if factory:
else:
if len(provides) == 1:
else:
raise TypeError("Missing 'provides' attribute")
if permission is not None:
if permission == PublicPermission:
checker = InterfaceChecke
component = proxify(component, checker)
_context.
callable = handler,
args = ('registerUtility', component, provides, name)
)
_context.
callable = provideInterface,
args = (provides.
)
now it's :
def utility(_context, provides=None, component=None, factory=None,
if factory and component:
raise TypeError("Can't specify factory and component.")
if provides is None:
if factory:
else:
if len(provides) == 1:
else:
raise TypeError("Missing 'provides' attribute")
if permission is not None:
if permission == PublicPermission:
checker = InterfaceChecke
component = proxify(component, checker)
_context.
callable = handler,
args = ('registerUtility', component, provides, name),
kw = dict(factory=
)
_context.
callable = provideInterface,
args = (provides.
)
So, in new version, if factory is given then permission isn't used because
component is None. Before, component was builded with factory and permission was
applied on this component and this ZCML declaration worked perfeclty with
"browser:
Now, I don't know how can I fix this issue with new Utility ZMCL design.
Regards,
Stephane
Changed in zope3: | |
status: | New → Won't Fix |
Now tracked on Github:
https:/ /github. com/zopefoundat ion/zope. component/ issues/ 7