Synchronize some minor changes from pydevd.

This commit is contained in:
Fabio Zadrozny 2022-07-14 13:45:46 -03:00
parent d117b091c5
commit b31dee3e79
4 changed files with 6 additions and 16 deletions

View file

@ -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)

View file

@ -21,7 +21,7 @@ def find_in_pythonpath(module_name):
return found_at
class DebuggerInitializationError(BaseException):
class DebuggerInitializationError(Exception):
pass

View file

@ -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:

View file

@ -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))