Re: [Zope3-dev] path adapters
Jean-Marc Orliaguet wrote: Jim Fulton wrote: Jean-Marc Orliaguet wrote: Stephan Richter wrote: On Sunday 11 September 2005 11:32, Jean-Marc Orliaguet wrote: it there any technical reason why: tal:define="displayable nocall:context/displayable" could not return the adapted object based on the context instead of triggering a traversal error? Yes. You are not using the path adapter syntax as far as I can see. You need to have: object/path_adapter_name:function You should check the parsing implementation (probably some traversing code) to see about the assumptions. Regards, Stephan I know that, I was about to file this as a bug, or write a proposal to let tal:define="adapted nocall:object/path_adapter_name" return the adapted object, but I found a workaround, by adding: You both are off on the path adapter syntax. The syntax allows the attribute name to be ommitted. You can write: tal:define="adapted nocall:object/path_adapter_name:" (note the trailing colon) Yes, this is what I tried first (by guessing), but I get a traversal error unless I write something after the trailing colon return traversable.traverse(nm, further_path) File "/home/jmo/Zope3/src/zope/app/container/traversal.py", line 100, in traverse raise TraversalError(name) TraversalError: 'displayable:' note that the 'IDisplayable' adapter does not implement ITraversable, but it implements IPathAdapter class Displayable(object): """This adapter makes elements displayable. """ implements(IDisplayable, IPathAdapter) def __init__(self, context): self.context = context def getDisplay(...): ... adapter ZCML declaration: so either it is a bug, or am I missing something? Sounds like a bug. Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
Jim Fulton wrote: > Jean-Marc Orliaguet wrote: > >> Stephan Richter wrote: >> >> >>> On Sunday 11 September 2005 11:32, Jean-Marc Orliaguet wrote: >>> >>> >>> it there any technical reason why: tal:define="displayable nocall:context/displayable" could not return the adapted object based on the context instead of triggering a traversal error? >>> >>> >>> Yes. You are not using the path adapter syntax as far as I can see. >>> You need to have: object/path_adapter_name:function >>> >>> You should check the parsing implementation (probably some >>> traversing code) to see about the assumptions. >>> >>> Regards, >>> Stephan >>> >>> >> >> >> I know that, I was about to file this as a bug, or write a proposal >> to let >> >> tal:define="adapted nocall:object/path_adapter_name" >> >> return the adapted object, but I found a workaround, by adding: > > > You both are off on the path adapter syntax. The syntax allows > the attribute name to be ommitted. You can write: > > tal:define="adapted nocall:object/path_adapter_name:" > > (note the trailing colon) > Yes, this is what I tried first (by guessing), but I get a traversal error unless I write something after the trailing colon return traversable.traverse(nm, further_path) File "/home/jmo/Zope3/src/zope/app/container/traversal.py", line 100, in traverse raise TraversalError(name) TraversalError: 'displayable:' note that the 'IDisplayable' adapter does not implement ITraversable, but it implements IPathAdapter class Displayable(object): """This adapter makes elements displayable. """ implements(IDisplayable, IPathAdapter) def __init__(self, context): self.context = context def getDisplay(...): ... adapter ZCML declaration: so either it is a bug, or am I missing something? regards /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
Jean-Marc Orliaguet wrote: Stephan Richter wrote: On Sunday 11 September 2005 11:32, Jean-Marc Orliaguet wrote: it there any technical reason why: tal:define="displayable nocall:context/displayable" could not return the adapted object based on the context instead of triggering a traversal error? Yes. You are not using the path adapter syntax as far as I can see. You need to have: object/path_adapter_name:function You should check the parsing implementation (probably some traversing code) to see about the assumptions. Regards, Stephan I know that, I was about to file this as a bug, or write a proposal to let tal:define="adapted nocall:object/path_adapter_name" return the adapted object, but I found a workaround, by adding: You both are off on the path adapter syntax. The syntax allows the attribute name to be ommitted. You can write: tal:define="adapted nocall:object/path_adapter_name:" (note the trailing colon) to get just the adapter. Note that the syntax: ob/foo:bar and ob/foo:/bar are equivalent. This syntax is kinda silly, as pointed out in: http://www.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/TALESPathExpressionAdapters Unfortunately, because we could never agree on an alternate syntax, we're stuck with the current syntax, at least for now. Jim -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
Stephan Richter wrote: >On Sunday 11 September 2005 11:32, Jean-Marc Orliaguet wrote: > > >>it there any technical reason why: >> >> tal:define="displayable nocall:context/displayable" >> >>could not return the adapted object based on the context instead of >>triggering a traversal error? >> >> > >Yes. You are not using the path adapter syntax as far as I can see. You need >to have: object/path_adapter_name:function > >You should check the parsing implementation (probably some traversing code) to >see about the assumptions. > >Regards, >Stephan > > I know that, I was about to file this as a bug, or write a proposal to let tal:define="adapted nocall:object/path_adapter_name" return the adapted object, but I found a workaround, by adding: def this(self): """Return the adapted object. """ return self to the adapter. Now I can use instead: tal:define=" displayable context/displayable:this; display python: displayable.getDisplay(perspective)" " which in terms of performance means that I don't need doing an adapter lookup for each of the adapter's method that I want to call. That is a pretty straightforward optimization. still it feels like an unnecessarily complicated way of doing something simple. /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
On Sunday 11 September 2005 11:32, Jean-Marc Orliaguet wrote: > it there any technical reason why: > > tal:define="displayable nocall:context/displayable" > > could not return the adapted object based on the context instead of > triggering a traversal error? Yes. You are not using the path adapter syntax as far as I can see. You need to have: object/path_adapter_name:function You should check the parsing implementation (probably some traversing code) to see about the assumptions. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
Stephan Richter wrote: >On Friday 02 September 2005 04:20, Jean-Marc Orliaguet wrote: > > >>this only solution I found was to write: >> >>tal:define="getDisplay nocall:context/displayable/getDisplay; >> display python: getDisplay(param);" >> >>But it means that I have to adapt the same object each time, why can't >>the adapted object be a variable? >> >> > >Path adapters are not designed to support arguments in function calls and >should be used as follows: > >context/displayable:getDisplay > >Functions on a path adapter should only rely on the context. Otherwise use a >view. > >Regards, >Stephan > > Hi, if I remember correctly, the reason why I asked the question was because the ZPT path adapter implementation feels counter-intuitive in the sense that it break a programming pattern used in python and in ZPT otherwise. why can't the following python pattern: displayable = IDisplayable(context) display = displayable.getDisplay() be transposed in ZPT as: tal:define=" displayable nocall:context/displayable; display displayable/getDisplay; " or as the one would write with any object: tal:define=" object nocall:context/getObject; value object/getValue; " it there any technical reason why: tal:define="displayable nocall:context/displayable" could not return the adapted object based on the context instead of triggering a traversal error? regards /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] path adapters
On Friday 02 September 2005 04:20, Jean-Marc Orliaguet wrote: > this only solution I found was to write: > > tal:define="getDisplay nocall:context/displayable/getDisplay; > display python: getDisplay(param);" > > But it means that I have to adapt the same object each time, why can't > the adapted object be a variable? Path adapters are not designed to support arguments in function calls and should be used as follows: context/displayable:getDisplay Functions on a path adapter should only rely on the context. Otherwise use a view. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com