#NEWLINE# def run_query( self , query ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# error = None #NEWLINE# code = compile_restricted ( query , '<string>' , 'exec' ) #NEWLINE# safe_builtins [ '_write_' ] = self . custom_write #NEWLINE# safe_builtins [ '__import__' ] = self . custom_import #NEWLINE# safe_builtins [ '_getattr_' ] = getattr #NEWLINE# safe_builtins [ 'getattr' ] = getattr #NEWLINE# safe_builtins [ '_setattr_' ] = setattr #NEWLINE# safe_builtins [ 'setattr' ] = setattr #NEWLINE# safe_builtins [ '_getitem_' ] = self . custom_get_item #NEWLINE# safe_builtins [ '_getiter_' ] = self . custom_get_iter #NEWLINE# safe_builtins [ '_print_' ] = self . _custom_print #NEWLINE# restricted_globals = dict ( __builtins__ = safe_builtins ) #NEWLINE# restricted_globals [ 'get_query_result' ] = self . get_query_result #NEWLINE# restricted_globals [ 'execute_query' ] = self . execute_query #NEWLINE# restricted_globals [ 'add_result_column' ] = self . add_result_column #NEWLINE# restricted_globals [ 'add_result_row' ] = self . add_result_row #NEWLINE# restricted_globals [ 'disable_print_log' ] = self . _custom_print . disable #NEWLINE# restricted_globals [ 'enable_print_log' ] = self . _custom_print . enable #NEWLINE# restricted_globals [ 'TYPE_DATETIME' ] = TYPE_DATETIME #NEWLINE# restricted_globals [ 'TYPE_BOOLEAN' ] = TYPE_BOOLEAN #NEWLINE# restricted_globals [ 'TYPE_INTEGER' ] = TYPE_INTEGER #NEWLINE# restricted_globals [ 'TYPE_STRING' ] = TYPE_STRING #NEWLINE# restricted_globals [ 'TYPE_DATE' ] = TYPE_DATE #NEWLINE# restricted_globals [ 'TYPE_FLOAT' ] = TYPE_FLOAT #NEWLINE# restricted_globals [ 'sorted' ] = sorted #NEWLINE# restricted_globals [ 'reversed' ] = reversed #NEWLINE# restricted_globals [ 'min' ] = min #NEWLINE# restricted_globals [ 'max' ] = max #NEWLINE# ( ( exec ( code ) in restricted_globals ) , self . _script_locals ) #NEWLINE# result = self . _script_locals [ 'result' ] #NEWLINE# result [ 'log' ] = self . _custom_print . lines #NEWLINE# json_data = json . dumps ( result ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# error = 'Query cancelled by user.' #NEWLINE# json_data = None #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# error = str ( e ) #NEWLINE# json_data = None #NEWLINE# #UNINDENT# return ( json_data , error )