85
85
def count_errors(self):
88
from analyse_user_input import User_Input_Analyser, code2list
88
from analyse_user_input import User_Input_Analyser, code2list, ResourcesError
89
89
from utils import AttrPickler, Translator, MyPrint
227
227
expr_ast_list = code2list(expr) # Syntax Error might happen here
228
228
expr_ast_list = [atom.strip() for atom in expr_ast_list]
229
229
#~ print ' *** expr_ast_list', expr_ast_list
230
prohibited_words = 'import, eval, exec, read, write, file, sys, os' # for, while ? linelenght limiting?
230
prohibited_words = 'import, eval, exec, read, write, file, sys, system, os' # for, while ? linelenght limiting?
231
232
for word in prohibited_words.split(', '):
232
if word in expr_ast_list:
233
self.my_print(_("Prohibited (for security reasons) word in expression: %s") % word)
234
self.my_print(_("Prohibited words are: %s") % prohibited_words)
233
for word_variant in (word, '__%s__'% word, "'%s'"% word):
234
if word_variant in expr_ast_list:
235
self.my_print(_("Prohibited (for security reasons) word in expression: **%s**") % word_variant)
236
self.my_print(_("Prohibited words are: %s") % prohibited_words)
237
239
self.my_print('>>> %s' % expr)
238
240
except SyntaxError:
243
246
while not expr in [':q', ':quit']:
244
247
if self._analyse__check_syntax_by_ast(expr):
249
if self.UI_type == 'web2py':
250
# first try to give full code + current expression
251
# if no resource overwhelming will be detected -- let expresion on :)
253
from sandbox_exec import sandbox_exec
255
raise Exception(_("Can't find path to sandbox -- no interactive shell :(. check file sandbox_exec.py"))
256
#~ self.my_print(_("Expression to try sandboxed: \n%s" % expr))
257
result_output = sandbox_exec( '\n'.join(self.code_passed) +'\n'+ expr )
258
#self.my_print(_("Output: \n%s" % result_output))
259
if '[Subprocess killed' in result_output:
260
#~ self.my_print(_("Error: \n%s" % result_output))
261
raise ResourcesError(_("The process takes too much resources and was terminated")) # in order to pass direct execution
263
#~ self._analyse__process_input(expr, self.code_passed)
246
267
self._analyse__process_input(expr, self.code_passed)
247
268
except Exception, e:
248
269
self._analyse__print_error(e)
250
272
self.my_print(_("Problem with your expression. please reenter."))
251
273
#yield 'interpret >>> '