[Zope] calling ZPublisher from python

Dieter Maurer dieter@handshake.de
Fri, 14 Dec 2001 21:11:22 +0100


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