[Zope] The funny _.None,_ feature in DTML kind of question
Vitaly Osipov
vos@telenor.cz
Thu, 1 Jun 2000 14:55:24 +0200
I must admit that it was a bit too prompt reply by me:) - I guess that
_.None is used almost always - I do not know any uses for values other than
_.None, but the following exerpt from sources of Zope 2.1.6 can get some
hints:
DT_String.py: (afaik module from which all dtml methods inherit __call__ )
def __call__(self,client=None,mapping={},**kw):
'''\
Generate a document from a document template.
The document will be generated by inserting values into the
format string specified when the document template was
created. Values are inserted using standard python named
string formats.
The optional argument 'client' is used to specify a object
containing values to be looked up. Values will be looked up
using getattr, so inheritence of values is supported. Note
that names beginning with '_' will not be looked up from the
client.
The optional argument, 'mapping' is used to specify a mapping
object containing values to be inserted.
Values will be inserted from one of several sources. The
sources, in the order in which they are consulted, are:
o Keyword arguments,
o The 'client' argument,
o The 'mapping' argument,
o The keyword arguments provided when the object was
created, and
o The 'mapping' argument provided when the template was
created
'''
so client part provides some more indirection than simple "_" mapping, which
is, as Michel Pelletier wrote in the letter I quoted, "the current DTML
namespace"...
also in DTMLDocument.py:
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping,
Response, and key word arguments."""
kw['document_id'] =self.id
kw['document_title']=self.title
if hasattr(self, 'aq_explicit'): bself=self.aq_explicit
else: bself=self
if client is None:
# Called as subtemplate, so don't need error propigation!
r=apply(HTML.__call__, (self, bself, REQUEST), kw)
if RESPONSE is None: return r
return decapitate(r, RESPONSE)
r=apply(HTML.__call__, (self, (client, bself), REQUEST), kw)
if type(r) is not type(''): return r
if RESPONSE is None: return r
hh=RESPONSE.headers.has_key
if not (hh('content-type') or hh('Content-Type')):
if self.__dict__.has_key('content_type'):
c=self.content_type
else:
c, e=guess_content_type(self.__name__, r)
RESPONSE.setHeader('Content-Type', c)
return r
seems like client is supplied only when called over the http, not as a
method inside a method(???)
----- Original Message -----
From: "Shalabh Chaturvedi" <shalabh@pspl.co.in>
>
> Reading that left me a bit confused because here you say (and I have read
> elsewhere too) that method is passed client=_.None. I thought that the
client
> should be the object on which the dtml method 'operates'. So how does the
dmtl
> method access the attributes of the object it is called upon? Is it
because the
> namespace object '_' has the namespace of the object on top?
Hmm... what do you mean by method operatind on some object? I thought that
in dtml "methods" are kind of an object themselves... so e.g. they inherit
properties of their containers just because those attributes are in a
namespace. (the only exclusion here could be methods of ZClasses)
>
> Any example of where the client parameter would be useful?
>
Maybe (I didn't look into the code - I am not a python/C wizard, especially
when it comes to python classes defined in C programs :) ) those client
settings are used in Zclasses? i.e. class as an object is passed in that
client argument to all methods of its instances... It is most likely what
could be called "methods operating on objects" in dtml
Regards,
Vitaly