Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix debugging of generated code in Py3
  • Loading branch information
inducer committed Oct 20, 2015
1 parent 60437a6 commit 9d0aa74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pudb/debugger.py
Expand Up @@ -11,7 +11,7 @@
CONFIG = load_config()
save_config(CONFIG)

from pudb.py3compat import PY3, raw_input
from pudb.py3compat import PY3, raw_input, text_type
if PY3:
_next = "__next__"
else:
Expand Down Expand Up @@ -599,18 +599,21 @@ def get_lines(self, debugger_ui):

lines = self.code.split("\n")

from pudb.lowlevel import detect_encoding
source_enc, _ = detect_encoding(getattr(iter(lines), _next))
if isinstance(self.code, text_type):
decoded_lines = lines
else:
from pudb.lowlevel import detect_encoding
source_enc, _ = detect_encoding(getattr(iter(lines), _next))

decoded_lines = []
for i, l in enumerate(lines):
if hasattr(l, "decode"):
l = l.decode(source_enc)
decoded_lines = []
for i, l in enumerate(lines):
if hasattr(l, "decode"):
l = l.decode(source_enc)

if i+1 < len(lines):
l += "\n"
if i+1 < len(lines):
l += "\n"

decoded_lines.append(l)
decoded_lines.append(l)

return format_source(debugger_ui, decoded_lines, set())

Expand Down Expand Up @@ -2093,6 +2096,7 @@ def event_loop(self, toplevel=None):
"\nChanges in version 2015.4:\n\n"
"- Support for (somewhat rudimentary) remote debugging\n"
" through a telnet connection.\n"
"- Fix debugging of generated code in Python 3.\n"

"\nChanges in version 2015.3:\n\n"
"- Disable set_trace lines from the UI (Aaron Meurer)\n"
Expand Down
2 changes: 2 additions & 0 deletions pudb/py3compat.py
Expand Up @@ -6,11 +6,13 @@
xrange = range
integer_types = (int,)
string_types = (str,)
text_type = str
def execfile(fname, globs, locs=None):
exec(compile(open(fname).read(), fname, 'exec'), globs, locs or globs)
else:
raw_input = raw_input
xrange = xrange
integer_types = (int, long)
string_types = (basestring,)
text_type = unicode
execfile = execfile

0 comments on commit 9d0aa74

Please sign in to comment.