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
This commit is contained in:
Pavel Minaev 2018-12-06 16:36:44 -08:00 committed by GitHub
parent 3c83d6be7e
commit 8ea0421711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

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

View file

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