I have been fighting a problem with PythonMethods/ZClasses. I have a
ZClass, MyTestClass, which has four methods:

  method1 (DTML Method)
  method2 (DTML Method)
  showMethods (DTML Method)
  showMethods2 (PythonMethod)

showMethods is defined as:

  <dtml-var standard_html_header>
  method1 = <dtml-var "_.hasattr(this(), 'method1')"><br>
  method2 = <dtml-var "_.hasattr(this(), 'method2')"><br>
  nullmethod = <dtml-var "_.hasattr(this(), 'nullmethod')">
  <dtml-var standard_html_footer>

and showMethods2 is defined:

  print getattr(self, 'method1')
  print getattr(self, 'method2')
  print getattr(self, 'nullmethod')
  return printed

showMethods, when invoked on an instance of my ZClass, returns:

  method1 = 1
  method2 = 1
  nullmethod = 0

Bingo. showMethods2, the PythonMethod, results in an AttributeError in
DT_Util.py:135. Digging into the Zope source, I see:

  validate=md.validate  # line 135

  if validate is None: return v

By inserting some print statements, I notice that md is an empty 
dictionary ([]) when careful_getattr() is called. Therefore, the
validate=md.validate line throws an AttributeError.

I fixed the "problem", and my code as a result, by changing this to read:

  try: validate=md.validate
  except: validate=None

  if validate is None: return v

I have a really strong feeling, though, that I just opened a whole can of
worms. Does my change break an intended behavior of Zope? Is it supposed
to throw an AttributeError when md does not have a 'validate'? If so, is
there a bug in PythonMethods that is causing md to not be initialized
properly before the call to careful_getattr()?

I am pressed for time on this project, and could really use some insight,
here. I am fresh out of ideas, and have hit the limits of my knowledge.



Jeff K. Hoffman                               704.849.0731 x108
Chief Technology Officer                      mailto:[EMAIL PROTECTED]
Going Virtual, L.L.C.                         http://www.goingv.com/

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to