Re: [Zope] Sub Class Question

2000-08-28 Thread R. David Murray

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


___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] Sub Class Question

2000-08-27 Thread R. David Murray

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


___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] Sub Class Question

2000-08-27 Thread Loren Stafford

From: "R. David Murray" [EMAIL PROTECTED]


 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" [EMAIL PROTECTED]
To: "Loren Stafford" [EMAIL PROTECTED]; "zope-dev"
[EMAIL PROTECTED]
Sent: March 01, 2000 11:57 AM
Subject: [Zope-dev] Re: What is im_func?

 From: "Loren Stafford" [EMAIL PROTECTED]
  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



___
Zope maillist  -  [EMAIL PROTECTED]
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 )




Re: [Zope] Sub Class Question

2000-08-26 Thread Loren Stafford

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" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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  -  [EMAIL PROTECTED]
 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 )




___
Zope maillist  -  [EMAIL PROTECTED]
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 )




[Zope] Sub Class Question

2000-08-25 Thread Daniel Rusch

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  -  [EMAIL PROTECTED]
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 )




Re: [Zope] Sub Class Question

2000-08-25 Thread R. David Murray

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


___
Zope maillist  -  [EMAIL PROTECTED]
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 )