def _get_python_c_args(host, port, code, args, setup): setup = _get_setup_updated_with_protocol_and_ppid(setup) # i.e.: We want to make the repr sorted so that it works in tests. setup_repr = setup if setup is None else (sorted_dict_repr(setup)) future_imports = '' if '__future__' in code: # If the code has a __future__ import, we need to be able to strip the __future__ # imports from the code and add them to the start of our code snippet. future_imports, code = _separate_future_imports(code) return ("%simport sys; sys.path.insert(0, r'%s'); import pydevd; pydevd.PydevdCustomization.DEFAULT_PROTOCOL=%r; " "pydevd.settrace(host=%r, port=%s, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True, access_token=%r, client_access_token=%r, __setup_holder__=%s); " "%s" ) % ( future_imports, pydev_src_dir, pydevd_constants.get_protocol(), host, port, setup.get('access-token'), setup.get('client-access-token'), setup_repr, code)
def test_monkey_patch_args_c_flag_inline(): original = SetupHolder.setup try: SetupHolder.setup = {'client': '127.0.0.1', 'port': '0', 'ppid': os.getpid(), 'protocol-quoted-line': True, 'skip-notify-stdin': True} check = ['C:\\bin\\python.exe', '-X', 'faulthandler', '-cconnect("127.0.0.1")', 'arg1'] debug_command = ( "import sys; sys.path.insert(0, r\'%s\'); import pydevd; pydevd.PydevdCustomization.DEFAULT_PROTOCOL='quoted-line'; " 'pydevd.settrace(host=\'127.0.0.1\', port=0, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True, access_token=None, client_access_token=None, __setup_holder__=%s); ' '' 'connect("127.0.0.1")') % (pydev_src_dir, sorted_dict_repr(SetupHolder.setup)) if sys.platform == "win32": debug_command = debug_command.replace('"', '\\"') debug_command = '"%s"' % debug_command res = pydev_monkey.patch_args(check) assert res == [ 'C:\\bin\\python.exe', '-X', 'faulthandler', '-c', debug_command, 'arg1' ] finally: SetupHolder.setup = original
def test_monkey(): original = SetupHolder.setup try: SetupHolder.setup = { 'client': '127.0.0.1', 'port': '0', 'ppid': os.getpid(), 'protocol-quoted-line': True } check = '''C:\\bin\\python.exe -u -c connect(\\"127.0.0.1\\")''' debug_command = ( 'import sys; ' 'sys.path.insert(0, r\'%s\'); ' "import pydevd; pydevd.PydevdCustomization.DEFAULT_PROTOCOL='quoted-line'; " "pydevd.settrace(host='127.0.0.1', port=0, suspend=False, " 'trace_only_current_thread=False, patch_multiprocessing=True, access_token=None, client_access_token=None, __setup_holder__=%s); ' '' 'connect("127.0.0.1")') % (pydev_src_dir, sorted_dict_repr(SetupHolder.setup)) if sys.platform == "win32": debug_command = debug_command.replace('"', '\\"') debug_command = '"%s"' % debug_command assert 'C:\\bin\\python.exe -u -c %s' % debug_command == pydev_monkey.patch_arg_str_win( check) finally: SetupHolder.setup = original
def _get_python_c_args(host, port, code, args, setup): setup = _get_setup_updated_with_protocol_and_ppid(setup) # i.e.: We want to make the repr sorted so that it works in tests. setup_repr = setup if setup is None else (sorted_dict_repr(setup)) return ( "import sys; sys.path.insert(0, r'%s'); import pydevd; pydevd.PydevdCustomization.DEFAULT_PROTOCOL=%r; " "pydevd.settrace(host=%r, port=%s, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True, access_token=%r, client_access_token=%r, __setup_holder__=%s); " "%s") % (pydev_src_dir, pydevd_constants.get_protocol(), host, port, setup.get('access-token'), setup.get('client-access-token'), setup_repr, code)