Skip to content

Commit

Permalink
Merged shane-better-tracebacks-branch. The changes are explained in h…
Browse files Browse the repository at this point in the history
  • Loading branch information
hathawsh committed Apr 3, 2002
1 parent 84e0087 commit 6603fce
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Python code.
"""

__version__='$Revision: 1.40 $'[11:-2]
__version__='$Revision: 1.41 $'[11:-2]

import sys, os, traceback, re, marshal
from Globals import DTMLFile, MessageDialog, package_home
Expand Down Expand Up @@ -247,7 +247,7 @@ def _newfun(self, code):
'_getattr_': guarded_getattr,
'_getitem_': guarded_getitem,
'_write_': full_write_guard,
'_print_': RestrictedPython.PrintCollector
'_print_': RestrictedPython.PrintCollector,
}
l = {}
exec code in g, l
Expand Down Expand Up @@ -286,15 +286,24 @@ def _exec(self, bound_names, args, kw):
# Got a cached value.
return result

__traceback_info__ = bound_names, args, kw, self.func_defaults
#__traceback_info__ = bound_names, args, kw, self.func_defaults

f = self._v_f
if f is None:
__traceback_supplement__ = (
PythonScriptTracebackSupplement, self)
raise RuntimeError, '%s %s has errors.' % (self.meta_type, self.id)

if bound_names is not None:
# Updating func_globals directly *should* be thread-safe.
# XXX This causes the whole acquisition chain
# to be held by self._v_f. I think we really should
# use new.function() instead, similar to
# CMFCore.FSPythonScript. new.function() takes
# about 8 microseconds on a 1 GHz Athlon. - Shane
f.func_globals.update(bound_names)

f.func_globals['__traceback_supplement__'] = (
PythonScriptTracebackSupplement, self, -1)

# Execute the function in a new security context.
security=getSecurityManager()
security.addContext(self)
Expand Down Expand Up @@ -467,6 +476,15 @@ def document_src(self, REQUEST=None, RESPONSE=None):
RESPONSE.setHeader('Content-Type', 'text/plain')
return self.read()


class PythonScriptTracebackSupplement:
"""Implementation of ITracebackSupplement"""
def __init__(self, script, line=0):
self.object = script
# If line is set to -1, it means to use tb_lineno.
self.line = line


_first_indent = re.compile('(?m)^ *(?! |$)')
_nonempty_line = re.compile('(?m)^(.*\S.*)$')

Expand Down

0 comments on commit 6603fce

Please sign in to comment.