[Zope-dev] masquerading python products as functions

Mick vsl6@paradise.net.nz
Wed, 11 Jul 2001 23:38:20 +1200


Hi,

I am trying to make a product act like an external method, or dtmlmethod.
Basically I have taken the minimal product and added a __call__ function.
It works fine, and can be called as a function of the object that contains
it.  The problem is that the minimal objects namespace is also pushed onto
the stack, and to get out of it I need to go through self.aq_parent.
Reading though all the help I could find I tried adding the following (as
DTMLMethod suggests.)

#Documents masquerade as functions
class func_code: pass
func_code=func_code()
func_code.co_varnames='self','RQUEST','RESPONSE'
func_code.co_argcount=3


This doesn't seem to do anything to the namespace problem.  Actually,
reading through DTMLMethod and ExternalMEthod aren't helping at all.
mapply.py seems equally unhelpful, though I can see some of what it is
trying to do.  Reading it also made me wonder why people say the above code
make Documents masquerade as functions, it seems in mapply, that if __call__
is defined, then it is bound to f in mapply anyway.  It seems to me to be in
the __call__ method that things are important where namespaces are passed to
HTML.__call__

I am obviously missing some fundamental points or sequences that would help
me to understand this, I was hoping someone could point me in the right
direction, either documentation, or some simple explanation, that would make
reading through that code more obvious.

I am running Zope 2.4.0b2 on python 2.1.

regards
Mick