[ZPT] Debugging helpers

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Mon, 09 Apr 2001 09:50:35 +1000


I've made a change to Expressions.py and PageTemplate.py to make debugging
a lot easier. Sorry I can't provide patches - I'm a little out of sync with
the CVS at the moment.

In PythonExpr.__call__, I have:

            # Execute the function in a new security context.
            template = econtext.contexts['template']
            security = getSecurityManager()
            security.addContext(template)
            try:
                if Globals.DevelopmentMode:
                    __traceback_info__ = self.expr
                return f()
            finally:
                security.removeContext(template)

the __traceback_info__ is invaluable in figuring out what what's gone
wrong. Having some way to identify the actual line number of the expression
would be a real bonus.

In PageTemplate.pr_render, I have:

    def pt_render(self, source=0, extra_context={}):
        """Render this Page Template"""
        if self._v_errors:
            return self.pt_diagnostic()
        output = StringIO()
        c = self.pt_getContext()
        c.update(extra_context)
        #__traceback_info__ = c
        if Globals.DevelopmentMode:
            __traceback_info__ = pprint.pformat(c)


again, the traceback info is handy to have, but it's annoying when not
pretty-formatted.


     Richard

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)