RE: [Zope-dev] masquerading python products as functions
Thanks for all the pointers. I found the thread that Dieter was mentioning and it was very good. Interesting to follow Chris's process of enlightenment, just what I needed. This Python script solution below looks interesting too, so I must follow that up. Toby Dickenson's wrapper is very nice ... http://www.zope.org/Members/htrd/howto/FunctionTemplate thanks Mick > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf > Of Lalo Martins > Sent: Thursday, July 12, 2001 3:45 PM > To: [EMAIL PROTECTED] > Subject: Re: [Zope-dev] masquerading python products as functions > > > On Wed, Jul 11, 2001 at 11:38:20PM +1200, Mick wrote: > > 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. > > You may want to try out Shared.DC.Scripts.Script. > > I have a (preliminary) HOWTO at > http://www.zope.org/Members/lalo/scriptclass-dev > > []s, >|alo >+ > -- > http://www.laranja.org/mailto:[EMAIL PROTECTED] > pgp key: http://www.laranja.org/pessoal/pgp > > Brazil of Darkness (RPG) --- http://www.BroDar.org/ > > ___ > Zope-Dev maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope ) > ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] masquerading python products as functions
On Wed, Jul 11, 2001 at 11:38:20PM +1200, Mick wrote: > 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. You may want to try out Shared.DC.Scripts.Script. I have a (preliminary) HOWTO at http://www.zope.org/Members/lalo/scriptclass-dev []s, |alo + -- http://www.laranja.org/mailto:[EMAIL PROTECTED] pgp key: http://www.laranja.org/pessoal/pgp Brazil of Darkness (RPG) --- http://www.BroDar.org/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] masquerading python products as functions
Mick writes: > 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 only affect the ZPublisher (more precisely "mapply"). What you may need: "isDocTemp". Search the mailing list archives for it. Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] masquerading python products as functions
Mick wrote: > > 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.) Yes, the current object is at the top of the namespace in general. DTML Methods get around this with the client argument which defaults to None. AFAIK This represents the containment namespace to use for execution. > > #Documents masquerade as functions > class func_code: pass > func_code=func_code() > func_code.co_varnames='self','RQUEST','RESPONSE' > func_code.co_argcount=3 >From what I read, this tells ZPublisher what arguments to pass by default to the object when it is called by traversal. Since client is omitted from co_varnames, it defaults to None, which tells the DT_String machinery (Which executes the DTML code) to do a "containment-less" execution. The DTML "interpreter" just does lookups though a namespace mapping passed in. Perhaps you could do something similar in your implementation. > > 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 > -- | Casey Duncan | Kaivo, Inc. | [EMAIL PROTECTED] `--> ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] masquerading python products as functions
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 ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )