calling ZPublisher from python
I'd like to write a python function that returns the value of a Zope object whose URL is given as the function argument. Something like: import Zope, ZPublisher def f(URL): return ZPublisher.Zope(URL) But this doesn't work (in an external method). Can anybody help me? Thanks, Benjamin.
You're looking for restrictedTraverse: objd = self.restrictedTraverse('/a/b/c/d') Florent Benjamin Buffereau <benjamin.buffereau@enst-bretagne.fr> wrote:
I'd like to write a python function that returns the value of a Zope object whose URL is given as the function argument. Something like:
import Zope, ZPublisher def f(URL): return ZPublisher.Zope(URL)
But this doesn't work (in an external method). Can anybody help me?
Thanks, Benjamin.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:fg@nuxeo.com
Benjamin Buffereau writes:
I'd like to write a python function that returns the value of a Zope object whose URL is given as the function argument. Something like:
import Zope, ZPublisher def f(URL): return ZPublisher.Zope(URL) You may create a request (ZPublisher.HTTPRequest.HTTPRequest) and use its "traverse" method. Making a request is not, "traverse" is happy with is not completely trivial, though.
I looked at "publish_module" and "publish" in "ZPublisher.Publish" to find out the requirements. The environment should define "SERVER_NAME", "SERVER_PORT" and "SCRIPT_NAME". Alternatively, you can use: from Zope import app o= root= app() # the root object for seg in URL.split('/'): o= getattr(o,seg) The result will not be the same as for "traverse", as this later method does not recognize Zope's traversal hooks. Dieter
participants (3)
-
Benjamin Buffereau -
Dieter Maurer -
Florent Guillaume