From 8ea0421711ff1892ca3a35735b736f2dfe53af81 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Thu, 6 Dec 2018 16:36:44 -0800 Subject: [PATCH] Fix #1037: Setting breakpoint fails on Python files containing non-ASCII characters (#1068) Fix #1066: Fetching remote source for a file with a Unicode name fails on 2.7 --- src/ptvsd/pathutils.py | 2 +- src/ptvsd/wrapper.py | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/ptvsd/pathutils.py b/src/ptvsd/pathutils.py index 91f5ed9e..003f50f1 100644 --- a/src/ptvsd/pathutils.py +++ b/src/ptvsd/pathutils.py @@ -2,7 +2,7 @@ # Licensed under the MIT License. See LICENSE in the project root # for license information. -from __future__ import print_function, with_statement, absolute_import +from __future__ import print_function, with_statement, absolute_import, unicode_literals from glob import glob import os.path diff --git a/src/ptvsd/wrapper.py b/src/ptvsd/wrapper.py index 59c7d058..96e9bc8e 100644 --- a/src/ptvsd/wrapper.py +++ b/src/ptvsd/wrapper.py @@ -200,10 +200,21 @@ class UnsupportedPyDevdCommandError(Exception): self.cmdid = cmdid -def unquote(s): - if s is None: - return None - return urllib.unquote(s) +if sys.version_info >= (3,): + def unquote(s): + return None if s is None else urllib.unquote(s) +else: + # In Python 2, urllib.unquote doesn't handle Unicode strings correctly, + # so we need to convert to ASCII first, unquote, and then decode. + def unquote(s): + if s is None: + return None + if not isinstance(s, bytes): + s = bytes(s) + s = urllib.unquote(s) + if isinstance(s, bytes): + s = s.decode('utf-8') + return s def unquote_xml_path(s): @@ -1605,7 +1616,10 @@ class VSCodeMessageProcessor(VSCLifecycleMsgProcessor): if source_reference == 0: self.send_error_response(request, 'Source unavailable') else: + if sys.version_info < (3,) and not isinstance(filename, bytes): + filename = filename.encode(sys.getfilesystemencoding()) server_filename = path_to_unicode(pydevd_file_utils.norm_file_to_server(filename)) + cmd = pydevd_comm.CMD_LOAD_SOURCE _, _, content = yield self.pydevd_request(cmd, server_filename) self.send_response(request, content=content)