Loading ...
Sorry, an error occurred while loading the content.

4945[Cheetahtemplate-discuss] Does cheetah look at superclasses of placeholder objects?

Expand Messages
  • Gerry Duprey
    Mar 7, 2011

      I've been using Cheetah for a few weeks and am pretty happy with it (I have been
      and still am a Velocity user too, so very familiar). However, I'm running into
      a problem trying to invoke a method off a placeholder that makes me wonder if
      Cheetah is able to understand the placeholder objects might have superclasses
      and is able find methods in them.

      NOTE: To be clear, I am NOT subclassing the cheetah Template class. This is
      regarding an object that is added to my path which has a super class.

      What is happening is that when I attempt to iterate over a list of objects, the
      individual objects appear to be complete (they are not None and a $type($xxx)
      returns the correct/expected type). But any attempt to invoke a method on the
      placeholder that would in fact be a method in the placeholder objects super
      class fail with a

      File "/usr/lib/python2.6/socket.py", line 292, in write
      data = str(data) # XXX Should really reject non-string non-buffers
      File "/usr/local/lib/python2.6/dist-packages/Cheetah/Template.py", line 997,
      in __str__
      rc = getattr(self, mainMethName)()
      line 160, in respond
      TypeError: 'NoneType' object is not callable

      The fragment of the template file that is causing this is:
      #for $anEffect in $handler.getEffectList():
      #end for

      I can confirm, via debugging and copious print statements, that the object
      represented by $handler is returning a series of objects via the getEffectList()

      Each "effect" instance can be a different class instance, but all the class
      instances have a common (and single) superclass that contains the getName()
      method. For example, there could be a class of "effects.effects.ColorWasher",
      "effects.effects.ColorPulser" and "effects.effects.TwinkleColor". All classes
      have the same base class of "BaseEffect" (which defined getName() and is not
      overridden by the sub-classes).

      If I fire up the python shell and run all the same code by hand, the
      getEffectList() call correctly returns a list of effects instances which work
      fine (I can call the getName() and other methods no problem). This code has
      been working for a long time, so I'm pretty confident of it. I install the
      $handler value directly, so there are no intermediate classes that could
      hide/mask things.

      The odd thing, to me, is that if I do
      #for $anEffect in $handler.getEffectList():
      #end for

      I get an expected list of different class names, so it must see part of this,
      but an attempt to invoke any method (even methods I know do NOT exist -- just
      testing), gives the NoneType. Doing a $dir($anEffect) shows all methods,
      including the getName() method, fine, so it's there in some way.

      I have a ton of other placeholder activity including calls for other
      classes/lists of instances in the same template that work fine.

      So, hoping I've provided enough to at least start the dialog, I'm wondering if:
      1) Could there be issues because the method I'm trying to invoke belongs to a
      superclass of the instance that is being used?

      2) Could there be an issue with packages/modules/importing that has to be
      resolved (i.e. while the class is intact, Cheetah can't parse the info/find
      things because the classes are from a different package/module)?

      3) If none of the above, any suggestions on how to further track this down?

      I really appreciate it. I've spend nearly 2 days testing and trying different
      approaches and other than now being sure the underlying code (the handler,
      effects list manage and effects) are working reliably.

      Much Thanks in advance!

      Gerry Duprey
      Ann Arbor, MI 48103

      What You Don't Know About Data Connectivity CAN Hurt You
      This paper provides an overview of data connectivity, details
      its effect on application quality, and explores various alternative
      solutions. http://p.sf.net/sfu/progress-d2d
      Cheetahtemplate-discuss mailing list
    • Show all 2 messages in this topic