Namespace within a product... (argh...)
Well, beeing very straightforward, I read this, in OSFP/Help/DTMLDocument.py : """ A DTMLDocument implicitly pass itself as a client argument in addition to the specified client, so names are looked up in the DTMLDocument itself. Passing in a namespace to a DTML Document is often referred to as providing the Document with a *context*. DTML Documents are called three ways: From DTML -- A DTML Document can be called from another DTML Method or Document:: <dtml-var standard_html_header> <dtml-var aDTMLDocument> <dtml-var standard_html_footer> In this example, the Document 'aDTMLDocument' is being called from another DTML object by name. The calling method passes the value 'this' as the client argument and the current DTML names pace as the REQUEST argument. The above is identical to this following usage in a DTML Python expression:: <dtml-var standard_html_header> <dtml-var "aDTMLDocument(_.None, _)"> <dtml-var standard_html_footer> From Python -- Products, External Methods, and PythonMethods can call a DTML Document in the same way as calling a DTML Document from a Python expression in DTML; as shown in the previous example. By the Publisher -- When the URL of a DTML Document is fetched from Zope, the DTML Document is called by the publisher. The REQUEST object is passes as the second argument to the Document. """ So - I had a look at DTMLDocument.py and saw the following method : def __call__ (self, client = None, REQUEST = {}, **kw): ... SO - I try to create this method for my product : def __call__ (self, client = None, REQUEST = {}, **kw): print client print REQUEST and it prints : None {} It seems that in fact the DTML document doesn't actually pass _.None and _ to my object. WHY ?????? How can I enforce DTML Docs/Meths to pass it anyway ??? Many thanks, P.-J. -- If the only tool you have is a hammer, you tend to see every problem as a nail. Si le seul outil dont vous disposez est un marteau, vous avez tendance à voir chaque problème comme un clou. --Abraham Maslow
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 Maybe someone from DC could shed some light on 'the rules' or point us to soem documentation? cheers, Chris
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
Evan, The information you just provided about the DTML Method "call signature" and the like is very useful. Is this kind of reference material written down somewhere in a guide/how-to/wiki/...? I tried to figure out the call signature of a Python method by having the called function use just "(*varargs, **kwargs)" as formal parameters, but the inscrutable mapply() function seems to thwart that effort as mapply() adjusts the function call according to what parameters the called function (or callable object, ...) expects. Very weird. Is there some document that covers the how and why of mapply()? On Tue, Oct 10, 2000 at 11:17:13AM -0400, Evan Simpson wrote:
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. ...
-- Fred Yankowski fred@OntoSys.com tel: +1.630.879.1312 Principal Consultant www.OntoSys.com fax: +1.630.879.1370 OntoSys, Inc 38W242 Deerpath Rd, Batavia, IL 60510, USA
From: Fred Yankowski <fred@ontosys.com>
The information you just provided about the DTML Method "call signature" and the like is very useful. Is this kind of reference material written down somewhere in a guide/how-to/wiki/...?
The only thing I could find offhand is http://www.zope.org//Wikis/DevSite/Projects/PythonMethods/NamespaceObjectInt..., which I wrote. I don't know if ZDP or someone else has documented it. Cheers, Evan @ digicool & 4-am
In article <00e801c032ea$50b15970$3e48a4d8@digicool.com>, Evan Simpson <evan@4-am.com> writes
From: Fred Yankowski <fred@ontosys.com>
The information you just provided about the DTML Method "call signature" and the like is very useful. Is this kind of reference material written down somewhere in a guide/how-to/wiki/...?
The only thing I could find offhand is http://www.zope.org//Wikis/DevSite/Projects/PythonMethods/NamespaceObjectInt... ce, which I wrote. I don't know if ZDP or someone else has documented it.
Cheers,
Evan @ digicool & 4-am OK so I have a similar but still to me confusing problem
I have a Product P containing two folderish ZClasses A and B. A and B both have class specific methods A_init and B_init to initialise specific bits of each. The product P has some methods eg M defined which are useful to both A and B. 1) How do I make the add methods behave identically whether I invoke as /dir/manage_addProduct/P/A_add or when I invoke from the manage add interface. I want to know the meta_type of the actual location where the product will appear not the factory's meta_type. 2) When I attempt to call B_add from inside A's private method A_init I seem to see a completely different context from when I call B_add directly on an instance of A. 3) I suppose this is related to the fact that inside A_init (the private method) I don't seem to see the same context as in A_add, ie the method M is visible in A_add, but not in A_init. How do ZClass contexts and the product context relate? -- Robin Becker
On Tue, Oct 10, 2000 at 11:56:11AM +0200, Pierre-Julien Grizel wrote:
So - I had a look at DTMLDocument.py and saw the following method :
def __call__ (self, client = None, REQUEST = {}, **kw): ...
SO - I try to create this method for my product :
def __call__ (self, client = None, REQUEST = {}, **kw): print client print REQUEST
and it prints : None {}
It seems that in fact the DTML document doesn't actually pass _.None and _ to my object. WHY ??????
Evan already answered, but the short story is: your object needs to have an attribute (it may be a class attribute and usually is) named "isDocTemp", and this attribute must evaluate to true. Otherwise, your object is called with no parameters. The relevant code is: if hasattr(v,'isDocTemp') and v.isDocTemp: v=v(None, self) else: try: v=v() except (AttributeError,TypeError): pass (from DocumentTemplate/DT_Util.py:277) []s, |alo +---- -- Hack and Roll ( http://www.hackandroll.org ) News for, uh, whatever it is that we are. http://zope.gf.com.br/lalo mailto:lalo@hackandroll.org pgp key: http://zope.gf.com.br/lalo/pessoal/pgp Brazil of Darkness (RPG) --- http://zope.gf.com.br/BroDar
participants (6)
-
Chris Withers -
Evan Simpson -
Fred Yankowski -
Lalo Martins -
Pierre-Julien Grizel -
Robin Becker