Skip to content

Commit

Permalink
Some renames to make the code easier to work with
Browse files Browse the repository at this point in the history
  • Loading branch information
dwt committed May 4, 2017
1 parent 5b626ea commit 65d6482
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Products/PythonScripts/PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,25 @@ def _compile(self):
self._v_change = 0

def _newfun(self, code):
glbs = get_safe_globals()
glbs['_getattr_'] = guarded_getattr
glbs['__debug__'] = __debug__
safe_globals = get_safe_globals()
safe_globals['_getattr_'] = guarded_getattr
safe_globals['__debug__'] = __debug__
# it doesn't really matter what __name__ is, *but*
# - we need a __name__
# (see testPythonScript.TestPythonScriptGlobals.test__name__)
# - it should not contain a period, so we can't use the id
# (see https://bugs.launchpad.net/zope2/+bug/142731/comments/4)
# - with Python 2.6 it should not be None
# (see testPythonScript.TestPythonScriptGlobals.test_filepath)
glbs['__name__'] = 'script'
safe_globals['__name__'] = 'script'

local = {}
safe_locals = {}
if sys.version_info > (3, 0):
exec(code, glbs, local)
exec(code, safe_globals, safe_locals)
else:
exec code in glbs, local # NOQA
func = local.values()[0]
self._v_ft = (func.func_code, glbs, func.func_defaults or ())
exec code in safe_globals, safe_locals # NOQA
func = safe_locals.values()[0]
self._v_ft = (func.func_code, safe_globals, func.func_defaults or ())
return func

def _makeFunction(self):
Expand Down Expand Up @@ -340,17 +340,17 @@ def _exec(self, bound_names, args, kw):
PythonScriptTracebackSupplement, self)
raise RuntimeError('%s %s has errors.' % (self.meta_type, self.id))

fcode, g, fadefs = ft
g = g.copy()
function_code, safe_globals, function_argument_definitions = ft
safe_globals = safe_globals.copy()
if bound_names is not None:
g.update(bound_names)
g['__traceback_supplement__'] = (
safe_globals.update(bound_names)
safe_globals['__traceback_supplement__'] = (
PythonScriptTracebackSupplement, self, -1)
g['__file__'] = getattr(self, '_filepath', None) or self.get_filepath()
f = types.FunctionType(fcode, g, None, fadefs)
safe_globals['__file__'] = getattr(self, '_filepath', None) or self.get_filepath()
function = types.FunctionType(function_code, safe_globals, None, function_argument_definitions)

try:
result = f(*args, **kw)
result = function(*args, **kw)
except SystemExit:
raise ValueError(
'SystemExit cannot be raised within a PythonScript')
Expand Down

0 comments on commit 65d6482

Please sign in to comment.