[Zope] inspect and page templates in python product

Peter Bengtsson peterbe at gmail.com
Sat Jul 30 12:10:21 EDT 2005


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).

Does anybody know if and how if there is a way to step back and found
out which template called hasRole() [ and maybe even which line] ?

If I do this debugging now, it gives me something like:

(hasRole:326, <expression>:1, __call__:47, evaluate:221,
do_condition:636, interpret:234, do_defineSlot:694, interpret:234,
no_tag:389, do_optTag:394, do_optTag_tal:409, interpret:234,
do_useMacro:671, interpret:234, __call__:190, pt_render:96, _exec:106,
_exec:343, _bindAndExec:343, __call__:306)


-- 
Peter Bengtsson, 
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list