[Zope] Black Magic

Evan Simpson evan@4-am.com
Tue, 10 Oct 2000 11:17:13 -0400


From: Chris Withers <chrisw@nipltd.com>
> Pierre-Julien Grizel wrote:
> > It seems that in fact the DTML document doesn't actually pass _.None and
> > _ to my object. WHY ??????
>
> This is deep voodoo that I don't fully understand. To me, it appears
> that what you get depends on how your __call__ was called...
>
> The arguments vary dependign on whether:
> -you were called from a bit of DTML
> -traversed directly through a URL
> -called from soem python you wrote

Here's the scoop:

1. DTML Methods' __call__ signature is (client=None, REQUEST={}, RESPONSE=None, **kw).  The client,
REQUEST, and keyword arguments are layered to form the namespace for the Method, with the keywords
on top, then the client, then REQUEST.

2. If you call a DTML Method in a Python expression, its namespace will be empty unless you
explicitly pass a client, REQUEST, and/or keyword arguments.

3. URL traversal automatically tries to look up parameter names in the REQUEST.  Both REQUEST and
RESPONSE are found in REQUEST, so they are passed to the Method.

4. When an object is named in the name attribute of a DTML tag, the DTML code checks to see whether
the object is callable and has a true attribute called "isDocTemp".  If so, it passes the namespace
to the REQUEST parameter.  Otherwise, if the object is callable it calls it with no arguments.
Thus, to simulate <dtml-var foo> in Python code, including DTML expressions, you must either use
"obj(_.None, _)" or "obj(REQUEST=_)".

Cheers,

Evan @ digicool & 4-am