@@ -198,19 +198,19 @@ def __restricted_import__(*args):
198198
199199def open_wrapper (* args ):
200200 if is_python3 :
201- raise Exception ('''open() is not supported.
201+ raise Exception ('''open() is not supported by Python Tutor .
202202Instead use io.StringIO() to simulate a file.
203203Here is an example: http://goo.gl/uNvBGl''' )
204204 else :
205- raise Exception ('''open() is not supported.
205+ raise Exception ('''open() is not supported by Python Tutor .
206206Instead use StringIO.StringIO() to simulate a file.
207207Here is an example: http://goo.gl/Q9xQ4p''' )
208208
209-
210- # use a wrapper to prevent bdb from diving 'inside' of these functions
211- # and causing massive confusion
212- def eval_wrapper ( * args ):
213- return eval ( * args )
209+ # create a more sensible error message for unsupported features
210+ def create_banned_builtins_wrapper ( fn_name ):
211+ def err_func ( * args ):
212+ raise Exception ( "'" fn_name + "' is not supported by Python Tutor." )
213+ return err_func
214214
215215
216216class RawInputException (Exception ):
@@ -252,14 +252,10 @@ def mouse_input_wrapper(prompt=''):
252252
253253# blacklist of builtins
254254BANNED_BUILTINS = ['reload' , 'open' , 'compile' ,
255- 'file' , 'exec' , 'execfile' ,
255+ 'file' , 'eval' , ' exec' , 'execfile' ,
256256 'exit' , 'quit' , 'help' ,
257257 'dir' , 'globals' , 'locals' , 'vars' ]
258258# Peter says 'apply' isn't dangerous, so don't ban it
259- #
260- # April 2016: don't ban 'eval' (or Python 2 'input') since this tool is
261- # already eval-ing user-inputted code, so might as well support more user code
262-
263259
264260IGNORE_VARS = set (('__user_stdout__' , '__OPT_toplevel__' , '__builtins__' , '__name__' , '__exception__' , '__doc__' , '__package__' ))
265261
@@ -1214,10 +1210,8 @@ def _runscript(self, script_str, custom_globals=None):
12141210 for (k , v ) in builtin_items :
12151211 if k == 'open' : # put this before BANNED_BUILTINS
12161212 user_builtins [k ] = open_wrapper
1217- elif k == 'eval' :
1218- user_builtins [k ] = eval_wrapper
12191213 elif k in BANNED_BUILTINS :
1220- continue
1214+ user_builtins [ k ] = create_banned_builtins_wrapper ( k )
12211215 elif k == '__import__' :
12221216 user_builtins [k ] = __restricted_import__
12231217 else :
0 commit comments