[Zope-Checkins] CVS: Releases/Zope/lib/python/Products/PythonScripts - PythonScript.py:1.43.6.2
Evan Simpson
evan@zope.com
Tue, 10 Jun 2003 17:14:37 -0400
Update of /cvs-repository/Releases/Zope/lib/python/Products/PythonScripts
In directory cvs.zope.org:/tmp/cvs-serv15134/lib/python/Products/PythonScripts
Modified Files:
Tag: Zope-2_6-branch
PythonScript.py
Log Message:
Fix Collector #902: Script recursion broken due to shared globals.
=== Releases/Zope/lib/python/Products/PythonScripts/PythonScript.py 1.43.6.1 => 1.43.6.2 ===
--- Releases/Zope/lib/python/Products/PythonScripts/PythonScript.py:1.43.6.1 Tue Oct 8 18:25:30 2002
+++ Releases/Zope/lib/python/Products/PythonScripts/PythonScript.py Tue Jun 10 17:14:36 2003
@@ -19,7 +19,7 @@
__version__='$Revision$'[11:-2]
-import sys, os, traceback, re, marshal
+import sys, os, traceback, re, marshal, new
from Globals import DTMLFile, MessageDialog, package_home
import AccessControl, OFS, RestrictedPython
from OFS.SimpleItem import SimpleItem
@@ -210,7 +210,7 @@
self._compile()
self._v_change = 1
elif self._code is None:
- self._v_f = None
+ self._v_ft = None
else:
self._newfun(marshal.loads(self._code))
@@ -224,7 +224,7 @@
self.warnings = tuple(r[2])
if errors:
self._code = None
- self._v_f = None
+ self._v_ft = None
self._setFuncSignature((), (), 0)
# Fix up syntax errors.
filestring = ' File "<string>",'
@@ -255,7 +255,8 @@
}
l = {}
exec code in g, l
- self._v_f = f = l.values()[0]
+ f = l.values()[0]
+ self._v_ft = (f.func_code, g, f.func_defaults or ())
return f
def _makeFunction(self, dummy=0): # CMFCore.FSPythonScript uses dummy arg.
@@ -263,7 +264,7 @@
self._compile()
def _editedBindings(self):
- if getattr(self, '_v_f', None) is not None:
+ if getattr(self, '_v_ft', None) is not None:
self._makeFunction()
def _exec(self, bound_names, args, kw):
@@ -292,21 +293,19 @@
#__traceback_info__ = bound_names, args, kw, self.func_defaults
- f = self._v_f
- if f is None:
+ ft = self._v_ft
+ if ft is None:
__traceback_supplement__ = (
PythonScriptTracebackSupplement, self)
raise RuntimeError, '%s %s has errors.' % (self.meta_type, self.id)
+ fcode, g, fadefs = ft
+ g = g.copy()
if bound_names is not None:
- # 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__'] = (
+ g.update(bound_names)
+ g['__traceback_supplement__'] = (
PythonScriptTracebackSupplement, self, -1)
+ f = new.function(fcode, g, None, fadefs)
# Execute the function in a new security context.
security=getSecurityManager()