[Zope] inspect and page templates in python product

Dieter Maurer dieter at handshake.de
Sun Jul 31 17:13:21 EDT 2005


Peter Bengtsson wrote at 2005-7-30 17:10 +0100:
>I'm using the inspect module in my python product to step back when
>doing some debugging.
>My code looks something like this::
>
>class MyProduct:
>  
>    def hasRole(self, r):
>          for i in range(25):
>              try:
>                  print inspect.stack()[i][3], 
>                  print inspect.stack()[i][2], 
>               except IndexError:
>                  break
>
>It works wonderfully well except when the caller of hasRole() is a
>Page Template defined with the PageTemplateFile function. (it might be
>equally bad with a ZODB persistent template I think).

Look at how "ExceptionFormatter" (in package "zExceptions") examines
the stack for "__traceback_info__" and "__traceback_supplement__".
You can in a similar way detect when you are in a PageTemplate
method. PageTemplates have attributes describing the current sourcefile
and line number.

-- 
Dieter


More information about the Zope mailing list