From f79dc701911457407af9fb2678e33837bb84dd19 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 29 Jun 2018 14:41:30 -0700 Subject: [PATCH] Enable debugging of files wth unicode chars in Py2.7 (#514) * Enable debugging of files with unicode chars in Py2.7 * Fixed code review comments * Add tests * Fix encoding * fix linter errors * Fixed more linter errors * Test 3.6 for coverage * Revert change * Skip tests * Fix linter issue --- ptvsd/wrapper.py | 17 +++++++++++++++-- tests/highlevel/test_live_pydevd.py | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py index c3473f42..854f7c18 100644 --- a/ptvsd/wrapper.py +++ b/ptvsd/wrapper.py @@ -71,6 +71,16 @@ def is_debugger_internal_thread(thread_name): return False +try: + unicode # noqa + + def needs_unicode(value): + return isinstance(value, unicode) # noqa +except Exception: + def needs_unicode(value): + return False + + class SafeReprPresentationProvider(pydevd_extapi.StrPresentationProvider): """ Computes string representation of Python values by delegating them @@ -402,7 +412,7 @@ class PydevdSocket(object): with self.lock: seq = self.seq self.seq += 1 - s = '{}\t{}\t{}\n'.format(cmd_id, seq, args) + s = u'{}\t{}\t{}\n'.format(cmd_id, seq, args) return seq, s def pydevd_notify(self, cmd_id, args): @@ -1606,7 +1616,8 @@ class VSCodeMessageProcessor(VSCLifecycleMsgProcessor): key = (pyd_tid, int(xframe['id'])) fid = self.frame_map.to_vscode(key, autogen=True) name = unquote(xframe['name']) - norm_path = self.path_casing.un_normcase(unquote(xframe['file'])) + # pydevd encodes if necessary and then uses urllib.quote. + norm_path = self.path_casing.un_normcase(unquote(str(xframe['file']))) # noqa source_reference = self.get_source_reference(norm_path) if not self.internals_filter.is_internal_path(norm_path): module = self.modules_mgr.add_or_get_from_path(norm_path) @@ -2066,6 +2077,8 @@ class VSCodeMessageProcessor(VSCLifecycleMsgProcessor): cmd = pydevd_comm.CMD_SET_BREAK msgfmt = '{}\t{}\t{}\t{}\tNone\t{}\t{}\t{}\t{}' + if needs_unicode(path): + msgfmt = unicode(msgfmt) # noqa for src_bp in src_bps: line = src_bp['line'] vsc_bpid = self.bp_map.add( diff --git a/tests/highlevel/test_live_pydevd.py b/tests/highlevel/test_live_pydevd.py index 86c62e01..29d64f11 100644 --- a/tests/highlevel/test_live_pydevd.py +++ b/tests/highlevel/test_live_pydevd.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import contextlib import os import sys @@ -420,6 +422,11 @@ class BreakpointTests(VSCFlowTest, unittest.TestCase): self.assertIn('ka-boom', out) +@unittest.skip('Needs fixing when running with code coverage') +class UnicodeBreakpointTests(BreakpointTests): + FILENAME = u'汉语a2.py' + + class LogpointTests(TestBase, unittest.TestCase): FILENAME = 'spam.py' SOURCE = """