From b31dee3e79421f4ab24263728559bd44ccbeec06 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Thu, 14 Jul 2022 13:45:46 -0300 Subject: [PATCH] Synchronize some minor changes from pydevd. --- .../pydevd/_pydev_bundle/_pydev_execfile.py | 13 +------------ .../pydevd/_pydev_bundle/_pydev_saved_modules.py | 2 +- .../_vendored/pydevd/_pydevd_bundle/pydevd_api.py | 5 +++-- .../pydevd/tests_python/debugger_unittest.py | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_execfile.py b/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_execfile.py index 75db0a82..28ae4035 100644 --- a/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_execfile.py +++ b/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_execfile.py @@ -6,20 +6,9 @@ def execfile(file, glob=None, loc=None): if loc is None: loc = glob - # It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/ - # (but tokenize.open() is only available for python 3.2) import tokenize - if hasattr(tokenize, 'open'): - # version 3.2 - stream = tokenize.open(file) # @UndefinedVariable - else: - # version 3.0 or 3.1 - detect_encoding = tokenize.detect_encoding(open(file, mode="rb").readline) - stream = open(file, encoding=detect_encoding[0]) - try: + with tokenize.open(file) as stream: contents = stream.read() - finally: - stream.close() # execute the script (note: it's important to compile first to have the filename set in debug mode) exec(compile(contents + "\n", file, 'exec'), glob, loc) diff --git a/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py b/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py index b2288e50..bcf5f9b2 100644 --- a/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py +++ b/src/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py @@ -21,7 +21,7 @@ def find_in_pythonpath(module_name): return found_at -class DebuggerInitializationError(BaseException): +class DebuggerInitializationError(Exception): pass diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py index 58c24b85..28a28d6d 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py @@ -31,6 +31,7 @@ import linecache from _pydevd_bundle.pydevd_utils import DAPGrouper from _pydevd_bundle.pydevd_daemon_thread import run_as_pydevd_daemon_thread from _pydevd_bundle.pydevd_thread_lifecycle import pydevd_find_thread_by_id, resume_threads +import tokenize try: import dis @@ -44,7 +45,7 @@ else: def _get_code_lines(code): if not isinstance(code, types.CodeType): path = code - with open(path) as f: + with tokenize.open(path) as f: src = f.read() code = compile(src, path, 'exec', 0, dont_inherit=True) return _get_code_lines(code) @@ -725,7 +726,7 @@ class PyDevdAPI(object): filename = self.filename_to_server(filename) assert filename.__class__ == str # i.e.: bytes on py2 and str on py3 - with open(filename, 'r') as stream: + with tokenize.open(filename) as stream: source = stream.read() cmd = py_db.cmd_factory.make_load_source_message(seq, source) except: diff --git a/src/debugpy/_vendored/pydevd/tests_python/debugger_unittest.py b/src/debugpy/_vendored/pydevd/tests_python/debugger_unittest.py index 34167d6b..d7c77546 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/debugger_unittest.py +++ b/src/debugpy/_vendored/pydevd/tests_python/debugger_unittest.py @@ -1290,7 +1290,7 @@ class AbstractWriterThread(threading.Thread): def write_custom_operation(self, locator, style, codeOrFile, operation_fn_name): self.write("%s\t%s\t%s||%s\t%s\t%s" % ( - CMD_RUN_CUSTOM_OPERATION, self.next_seq(), locator, style, codeOrFile, operation_fn_name)) + CMD_RUN_CUSTOM_OPERATION, self.next_seq(), locator, style, quote_plus(codeOrFile), operation_fn_name)) def write_evaluate_expression(self, locator, expression): self.write("%s\t%s\t%s\t%s\t1" % (CMD_EVALUATE_EXPRESSION, self.next_seq(), locator, expression))