@@ -24,54 +24,54 @@ class BasePythonScriptEngineEnvironment:
24
24
def __init__ (self , environment_globals = None ):
25
25
self .globals = environment_globals or {}
26
26
27
- def evaluate (self , expression , context , external_methods = None ):
27
+ def evaluate (self , expression , context , external_context = None ):
28
28
raise NotImplementedError ("Subclass must implement this method" )
29
29
30
- def execute (self , script , context , external_methods = None ):
30
+ def execute (self , script , context , external_context = None ):
31
31
raise NotImplementedError ("Subclass must implement this method" )
32
32
33
33
34
34
class TaskDataEnvironment (BasePythonScriptEngineEnvironment ):
35
35
36
- def evaluate (self , expression , context , external_methods = None ):
36
+ def evaluate (self , expression , context , external_context = None ):
37
37
my_globals = copy .copy (self .globals ) # else we pollute all later evals.
38
38
self ._prepare_context (context )
39
- my_globals .update (external_methods or {})
39
+ my_globals .update (external_context or {})
40
40
my_globals .update (context )
41
41
return eval (expression , my_globals )
42
42
43
- def execute (self , script , context , external_methods = None ):
44
- self .check_for_overwrite (context , external_methods or {})
43
+ def execute (self , script , context , external_context = None ):
44
+ self .check_for_overwrite (context , external_context or {})
45
45
my_globals = copy .copy (self .globals )
46
46
self ._prepare_context (context )
47
- my_globals .update (external_methods or {})
47
+ my_globals .update (external_context or {})
48
48
context .update (my_globals )
49
49
try :
50
50
exec (script , context )
51
51
finally :
52
- self ._remove_globals_and_functions_from_context (context , external_methods )
52
+ self ._remove_globals_and_functions_from_context (context , external_context )
53
53
return True
54
54
55
55
def _prepare_context (self , context ):
56
56
pass
57
57
58
- def _remove_globals_and_functions_from_context (self , context , external_methods = None ):
58
+ def _remove_globals_and_functions_from_context (self , context , external_context = None ):
59
59
"""When executing a script, don't leave the globals, functions
60
60
and external methods in the context that we have modified."""
61
61
for k in list (context ):
62
62
if k == "__builtins__" or \
63
63
hasattr (context [k ], '__call__' ) or \
64
64
k in self .globals or \
65
- external_methods and k in external_methods :
65
+ external_context and k in external_context :
66
66
context .pop (k )
67
67
68
- def check_for_overwrite (self , context , external_methods ):
68
+ def check_for_overwrite (self , context , external_context ):
69
69
"""It's possible that someone will define a variable with the
70
70
same name as a pre-defined script, rendering the script un-callable.
71
71
This results in a nearly indecipherable error. Better to fail
72
72
fast with a sensible error message."""
73
73
func_overwrites = set (self .globals ).intersection (context )
74
- func_overwrites .update (set (external_methods ).intersection (context ))
74
+ func_overwrites .update (set (external_context ).intersection (context ))
75
75
if len (func_overwrites ) > 0 :
76
76
msg = f"You have task data that overwrites a predefined " \
77
77
f"function(s). Please change the following variable or " \
0 commit comments