I've created a BasicMethod which is derived from the DTMLMethod. everything works great until I try to have the sub class's (BasicMethod) __call__ method call the super class's (DTMLMethod) __call__ method. class BasicMethod(DTMLMethod): """BasicMethod objects are DocumentTemplate.HTML objects that act as methods whose 'self' is the BasicMethod itself.""" meta_type='Basic Method' def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): print 'Sub Class __call__' DTMLMethod.__call__(self, client, REQUEST, RESPONSE, kw) Globals.default__class_init__(BasicMethod) when I view the BasicMethod in Zope, I get: Error Type: TypeError Error Value: too many arguments; expected 4, got 5 I believe that I need the self arg, if I remove it I get an unbound python method error. Any thoughts??? DR
On Fri, 25 Aug 2000, Daniel Rusch wrote:
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): print 'Sub Class __call__' DTMLMethod.__call__(self, client, REQUEST, RESPONSE, kw)
[...]
when I view the BasicMethod in Zope, I get: Error Type: TypeError Error Value: too many arguments; expected 4, got 5
I believe that I need the self arg, if I remove it I get an unbound python method error.
Any thoughts???
DTMLMethod's __call__ only takes three arguments: client, REQUEST, and RESPONSE. **kw turns any additional keyword arguments (x=y) into a dictionary kw. To pass the ones your __call__ receives on to DTMLMethod's __call__, you have to turn them back into a keyword list somehow. A quick check of the python language reference doesn't reveal any special syntactic sugar for doing this. However, in the definition of __call__ in DTMLMethod I found this: r = apply(HTML.__call__, (self, client, REQUEST), kw) Reading about apply in the python docs, it's obviously designed to do just the job you need <grin>. --RDM
I'm not sure if this is the same situation I encountered in Xron's XronDTMLMethod.py, where I'm overriding CatalogAware's index_object method. # Only index if nextEventTime returns something def index_object(self): if self.nextEventTime() is not None: CatalogAware.index_object.im_func(self) # see Python Reference Manual "The standard type hierarchy" # for the built-in type im_func -- HTH -- Loren ----- Original Message ----- From: "Daniel Rusch" <drusch@globalcrossing.com> To: <zope@zope.org> Sent: August 25, 2000 02:51 PM Subject: [Zope] Sub Class Question
I've created a BasicMethod which is derived from the DTMLMethod. everything works great until I try to have the sub class's (BasicMethod) __call__ method call the super class's (DTMLMethod) __call__ method.
class BasicMethod(DTMLMethod): """BasicMethod objects are DocumentTemplate.HTML objects that act as methods whose 'self' is the BasicMethod itself."""
meta_type='Basic Method'
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): print 'Sub Class __call__' DTMLMethod.__call__(self, client, REQUEST, RESPONSE, kw)
Globals.default__class_init__(BasicMethod)
when I view the BasicMethod in Zope, I get: Error Type: TypeError Error Value: too many arguments; expected 4, got 5
I believe that I need the self arg, if I remove it I get an unbound python method error.
Any thoughts???
DR
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Sat, 26 Aug 2000, Loren Stafford wrote:
def index_object(self): if self.nextEventTime() is not None: CatalogAware.index_object.im_func(self) # see Python Reference Manual "The standard type hierarchy" # for the built-in type im_func
I realize this is a Python and a not a Zope question, but what is the difference between CatalogAware.index_object.im_func(self) and CatalogAware.index_object(self) ? --RDM
From: "R. David Murray" <bitz@bitdance.com>
On Sat, 26 Aug 2000, Loren Stafford wrote:
def index_object(self): if self.nextEventTime() is not None: CatalogAware.index_object.im_func(self) # see Python Reference Manual "The standard type hierarchy" # for the built-in type im_func
I realize this is a Python and a not a Zope question, but what is the difference between
CatalogAware.index_object.im_func(self)
and
CatalogAware.index_object(self)
?
--RDM
Here's what MJ told me about that case. I'm not sure it applies to your case. Did you try it? Did it work? -- Loren ----- Original Message ----- From: "Martijn Pieters" <mj@digicool.com> To: "Loren Stafford" <lstaffor@dynalogic.com>; "zope-dev" <zope-dev@zope.org> Sent: March 01, 2000 11:57 AM Subject: [Zope-dev] Re: What is im_func?
From: "Loren Stafford" <lstaffor@dynalogic.com>
Could you elaborate on what im_func is and what it's role is here.
# Only index if nextEventTime returns something def index_object(self): if self.nextEventTime() is not None: CatalogAware.index_object.im_func(self)
im_func is a part of Python introspection. It is the pure function definition of a class, not bound to that class, so I can pass in an alternate self.
I am trying to call a superclass method here, and normally CatalogAware.index_object() would suffice. But because of Extension Classes, Python gets confused as to what is a class method, and what is a regular function. It will accuse me of calling an unbound method, which of course I am not. I circumvent this by calling the unbound function, and passing in self explicitly.
Martijn Pieters
On Sun, 27 Aug 2000, Loren Stafford wrote:
Here's what MJ told me about that case. I'm not sure it applies to your case. Did you try it? Did it work?
Thanks for the info. It was the Extension class piece I was missing. I tested it on a regular class, of course <grin>. The original problem wasn't mine. I think his problem was different (passing **kw on to a class method), and I think I pointed him to the right answer but haven't seen a followup post. --RDM
participants (3)
-
Daniel Rusch -
Loren Stafford -
R. David Murray