def console_exec(thread_id, frame_id, expression, dbg): """returns 'False' in case expression is partially correct """ frame = pydevd_vars.find_frame(thread_id, frame_id) is_multiline = expression.count('@LINE@') > 1 try: expression = str(expression.replace('@LINE@', '\n')) except UnicodeEncodeError as e: expression = expression.replace('@LINE@', '\n') # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 # (Names not resolved in generator expression in method) # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html updated_globals = {} updated_globals.update(frame.f_globals) updated_globals.update( frame.f_locals ) # locals later because it has precedence over the actual globals if PYTEST_RUN_CONFIG: enable_pytest_output() if IPYTHON: need_more = exec_code(CodeFragment(expression), updated_globals, updated_globals, dbg) if not need_more: update_frame_local_variables_and_save(frame, updated_globals) return need_more interpreter = ConsoleWriter() if not is_multiline: try: code = compile_command(expression) except (OverflowError, SyntaxError, ValueError): # Case 1 interpreter.showsyntaxerror() return False if code is None: # Case 2 return True else: code = expression # Case 3 try: # It is important that globals and locals we pass to the exec function are the same object. # Otherwise generator expressions can confuse their scope. Passing updated_globals dictionary seems to be a safe option here # because it contains globals and locals in the right precedence. # See: https://stackoverflow.com/questions/15866398/why-is-a-python-generator-confusing-its-scope-with-global-in-an-execd-script. Exec(code, updated_globals, updated_globals) except SystemExit: raise except: interpreter.showtraceback() else: update_frame_local_variables_and_save(frame, updated_globals) return False
def console_exec(thread_id, frame_id, expression, dbg): """returns 'False' in case expression is partially correct """ frame = pydevd_vars.find_frame(thread_id, frame_id) is_multiline = expression.count('@LINE@') > 1 try: expression = str(expression.replace('@LINE@', '\n')) except UnicodeEncodeError as e: expression = expression.replace('@LINE@', '\n') # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 # (Names not resolved in generator expression in method) # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html updated_globals = {} updated_globals.update(frame.f_globals) updated_globals.update( frame.f_locals ) # locals later because it has precedence over the actual globals if PYTEST_RUN_CONFIG: enable_pytest_output() if IPYTHON: need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals, dbg) if not need_more: pydevd_save_locals.save_locals(frame) return need_more interpreter = ConsoleWriter() if not is_multiline: try: code = compile_command(expression) except (OverflowError, SyntaxError, ValueError): # Case 1 interpreter.showsyntaxerror() return False if code is None: # Case 2 return True else: code = expression # Case 3 try: Exec(code, updated_globals, frame.f_locals) except SystemExit: raise except: interpreter.showtraceback() else: pydevd_save_locals.save_locals(frame) return False
def console_exec(thread_id, frame_id, expression, dbg): """returns 'False' in case expression is partially correct """ frame = pydevd_vars.find_frame(thread_id, frame_id) is_multiline = expression.count('@LINE@') > 1 try: expression = str(expression.replace('@LINE@', '\n')) except UnicodeEncodeError as e: expression = expression.replace('@LINE@', '\n') # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 # (Names not resolved in generator expression in method) # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html updated_globals = {} updated_globals.update(frame.f_globals) updated_globals.update(frame.f_locals) # locals later because it has precedence over the actual globals if PYTEST_RUN_CONFIG: enable_pytest_output() if IPYTHON: need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals, dbg) if not need_more: pydevd_save_locals.save_locals(frame) return need_more interpreter = ConsoleWriter() if not is_multiline: try: code = compile_command(expression) except (OverflowError, SyntaxError, ValueError): # Case 1 interpreter.showsyntaxerror() return False if code is None: # Case 2 return True else: code = expression # Case 3 try: Exec(code, updated_globals, frame.f_locals) except SystemExit: raise except: interpreter.showtraceback() else: pydevd_save_locals.save_locals(frame) return False