##// END OF EJS Templates
Fix unicode problem with SyntaxError traceback
Jörgen Stenarson -
Show More
@@ -104,6 +104,7 b' from IPython.utils import py3compat'
104 from IPython.utils import pyfile
104 from IPython.utils import pyfile
105 from IPython.utils import ulinecache
105 from IPython.utils import ulinecache
106 from IPython.utils.data import uniq_stable
106 from IPython.utils.data import uniq_stable
107 from IPython.utils.openpy import read_py_file
107 from IPython.utils.warn import info, error
108 from IPython.utils.warn import info, error
108
109
109 # Globals
110 # Globals
@@ -543,7 +544,6 b' class ListTB(TBTools):'
543
544
544 Also lifted nearly verbatim from traceback.py
545 Also lifted nearly verbatim from traceback.py
545 """
546 """
546
547 have_filedata = False
547 have_filedata = False
548 Colors = self.Colors
548 Colors = self.Colors
549 list = []
549 list = []
@@ -560,16 +560,25 b' class ListTB(TBTools):'
560 (Colors.normalEm,
560 (Colors.normalEm,
561 Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm,
561 Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm,
562 Colors.linenoEm, value.lineno, Colors.Normal ))
562 Colors.linenoEm, value.lineno, Colors.Normal ))
563 if value.text is not None:
563 if value.filename[:1] != "<":
564 # The value.text on the exception seems to be encoded using error="replace"
565 # Read source file directly
566 textline = read_py_file(value.filename, skip_encoding_cookie=False).split("\n")[value.lineno - 1]
567 else:
568 #It seems code entered at the prompt always results in source
569 #encoded in utf-8 format
570 textline = py3compat.cast_unicode(value.text, encoding="utf-8")
571
572 if textline is not None:
564 i = 0
573 i = 0
565 while i < len(value.text) and value.text[i].isspace():
574 while i < len(textline) and textline[i].isspace():
566 i += 1
575 i += 1
567 list.append('%s %s%s\n' % (Colors.line,
576 list.append('%s %s%s\n' % (Colors.line,
568 py3compat.cast_unicode(value.text.strip()),
577 textline.strip(),
569 Colors.Normal))
578 Colors.Normal))
570 if value.offset is not None:
579 if value.offset is not None:
571 s = ' '
580 s = ' '
572 for c in value.text[i:value.offset-1]:
581 for c in textline[i:value.offset-1]:
573 if c.isspace():
582 if c.isspace():
574 s += c
583 s += c
575 else:
584 else:
General Comments 0
You need to be logged in to leave comments. Login now