[Zope-dev] Zope hacking help

Michel Pelletier michel@digicool.com
Sat, 11 Sep 1999 05:40:31 -0400


 
> At 04:29 PM 9/10/99 -0300, you wrote:
> >One day of hacking Zope made my head dizzy :-( pdb was no help,
> >neither grepping for everything I could think of.
> >
> >And so many components to check... ZServer, medusa, ZPublisher, aaagh!
> >
> >Can someone help me to the point where Zope decides what object
> >to serve, based on the URL, and the point where this object is
> >processed (eg, if it's DTML)?

I'll give you a little tidbit, but it's advanced stuff.  Your question
can be answered quite acurately with the Zope debugger.  In your
lib/python directory, run python1.5.2:

[michel@localhost python]$ python
Python 1.5.2 (#9, Jul  8 1999, 02:04:22)  [GCC egcs-2.91.66
19990314/Linux (egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import Zope, ZPublisher

This imports the Zope system and ZPublisher.  ZPublisher contains the
debugger.

>>> ZPublisher.Zope('index_html', d=1)

Here, we are calling the main Zope app with a request and a debug
argument.  This will cause the debugger to run, as you see below.  This
request is looking for the top level 'index_html'.  You can type any
absolute URL path in here when your looking to debug specific objects.

* Type "s<cr>c<cr>" to jump to beginning of real publishing process.
* Then type c<cr> to jump to the beginning of the URL traversal
  algorithm.
* Then type c<cr> to jump to published object call.
> <string>(0)?()

Here we are in the debugger.  To step into it, hit 's'.

pdb> s
> <string>(1)?()

And then continue on to the first breakpoint with 'c':

pdb> c
> /home/michel/Zope2/lib/python/ZPublisher/Publish.py(112)publish()
-> def publish(request, module_name, after_list, debug=0,

The Zope debugger sets up two breakpoints for you.  Here you can see we
are stoped at the first breakpoint, right at the beginning of the URL to
object traversal.  This method is called 'publish'.  It looks a bit like
this:

pdb> list
107  	    request.response.badRequestError(name)
108  	
109  	def dont_publish_class(klass, request):
110  	    request.response.forbiddenError("class %s" % klass.__name__)
111  	
112 B->	def publish(request, module_name, after_list, debug=0,
113  	            # Optimize:
114  	            call_object=call_object,
115  	            missing_name=missing_name,
116  	            dont_publish_class=dont_publish_class,
117  	            mapply=mapply,

From here you can 's'tep and 'n'ext through the traversal process, or
you can hit 'c' to continue on to the next handy breakpoint the debugger
sets for you, which is at the *end* of the traversal:

pdb> c
> /home/michel/Zope2/lib/python/ZPublisher/Publish.py(101)call_object()
-> def call_object(object, args, request):

After the ORB find the object you are looking for (in this case,
'index_html' which is what 'object' is set to, verify it yourself by
typing 'p object').  It calls the object in the 'call_object' method,
the target of the second breakpoint.   'S'tep into this:

pdb> s

Here the object is being called.  Step into the apply()

> /home/michel/Zope2/lib/python/ZPublisher/Publish.py(102)call_object()
-> result=apply(object,args) # Type s<cr> to step into published object.

pdb> s
> /home/michel/Zope2/lib/python/OFS/DTMLMethod.py(133)__call__()
-> def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
pdb> 

At this point we find outselves in the __call__ method of a DTMLMethod
object.  This is the beginning of the DTML rendering process.  Some of
you may notice that this is the same call method that is used to call
any DTML Method or Document.  Here, ZPublisher will pass in a REQUEST
and RESPONSE object so that the DTML Method can render itself.


-Michel