<s> """<STR_LIT>""" <EOL> from jedi . parser import representation as pr <EOL> from jedi import debug <EOL> from jedi import settings <EOL> from jedi . evaluate import compiled <EOL> from jedi . evaluate import iterable <EOL> def recursion_decorator ( func ) : <EOL> def run ( evaluator , stmt , * args , ** kwargs ) : <EOL> rec_detect = evaluator . recursion_detector <EOL> if rec_detect . push_stmt ( stmt ) : <EOL> return [ ] <EOL> else : <EOL> result = func ( evaluator , stmt , * args , ** kwargs ) <EOL> rec_detect . pop_stmt ( ) <EOL> return result <EOL> return run <EOL> class RecursionDetector ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . top = None <EOL> self . current = None <EOL> def push_stmt ( self , stmt ) : <EOL> self . current = _RecursionNode ( stmt , self . current ) <EOL> check = self . _check_recursion ( ) <EOL> if check : <EOL> debug . warning ( '<STR_LIT>' , stmt , <EOL> check . stmt , stmt . start_pos ) <EOL> self . pop_stmt ( ) <EOL> return True <EOL> return False <EOL> def pop_stmt ( self ) : <EOL> if self . current is not None : <EOL> self . current = self . current . parent <EOL> def _check_recursion ( self ) : <EOL> test = self . current <EOL> while True : <EOL> test = test . parent <EOL> if self . current == test : <EOL> return test <EOL> if not test : <EOL> return False <EOL> def node_statements ( self ) : <EOL> result = [ ] <EOL> n = self . current <EOL> while n : <EOL> result . insert ( <NUM_LIT:0> , n . stmt ) <EOL> n = n . parent <EOL> return result <EOL> class _RecursionNode ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stmt , parent ) : <EOL> self . script = stmt . get_parent_until ( ) <EOL> self . position = stmt . start_pos <EOL> self . parent = parent <EOL> self . stmt = stmt <EOL> self . is_ignored = isinstance ( stmt , pr . Param ) or ( self . script == compiled . builtin ) <EOL> def __eq__ ( self , other ) : <EOL> if not other : <EOL> return None <EOL> is_list_comp = lambda x : isinstance ( x , pr . ForFlow ) and x . is_list_comp <EOL> return self . script == other . script and self . position == other . position and not is_list_comp ( self . stmt . parent ) and not is_list_comp ( other . parent ) and not self . is_ignored and not other . is_ignored <EOL> def execution_recursion_decorator ( func ) : <EOL> def run ( execution , evaluate_generator = False ) : <EOL> detector = execution . _evaluator . execution_recursion_detector <EOL> if detector . push_execution ( execution , evaluate_generator ) : <EOL> result = [ ] <EOL> else : <EOL> result = func ( execution , evaluate_generator ) <EOL> detector . pop_execution ( ) <EOL> return result <EOL> return run <EOL> class ExecutionRecursionDetector ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . recursion_level = <NUM_LIT:0> <EOL> self . parent_execution_funcs = [ ] <EOL> self . execution_funcs = set ( ) <EOL> self . execution_count = <NUM_LIT:0> <EOL> def __call__ ( self , execution , evaluate_generator = False ) : <EOL> debug . dbg ( '<STR_LIT>' , execution , self . recursion_level , <EOL> self . execution_count , len ( self . execution_funcs ) ) <EOL> if self . check_recursion ( execution , evaluate_generator ) : <EOL> result = [ ] <EOL> else : <EOL> result = self . func ( execution , evaluate_generator ) <EOL> self . pop_execution ( ) <EOL> return result <EOL> def pop_execution ( cls ) : <EOL> cls . parent_execution_funcs . pop ( ) <EOL> cls . recursion_level -= <NUM_LIT:1> <EOL> def push_execution ( cls , execution , evaluate_generator ) : <EOL> in_par_execution_funcs = execution . base in cls . parent_execution_funcs <EOL> in_execution_funcs = execution . base in cls . execution_funcs <EOL> cls . recursion_level += <NUM_LIT:1> <EOL> cls . execution_count += <NUM_LIT:1> <EOL> cls . execution_funcs . add ( execution . base ) <EOL> cls . parent_execution_funcs . append ( execution . base ) <EOL> if cls . execution_count > settings . max_executions : <EOL> return True <EOL> if isinstance ( execution . base , ( iterable . Array , iterable . Generator ) ) : <EOL> return False <EOL> module = execution . get_parent_until ( ) <EOL> if evaluate_generator or module == compiled . builtin : <EOL> return False <EOL> if in_par_execution_funcs : <EOL> if cls . recursion_level > settings . max_function_recursion_level : <EOL> return True <EOL> if in_execution_funcs and len ( cls . execution_funcs ) > settings . max_until_execution_unique : <EOL> return True <EOL> if cls . execution_count > settings . max_executions_without_builtins : <EOL> return True <EOL> return False </s>
