jonathanslenders / ptpdb

prompt_toolkit/ptpython pdb frontend
183 stars 20 forks source link

Breaks on non-ASCII chars in source code #11

Closed icemac closed 8 years ago

icemac commented 9 years ago

I have a source code file containing German umlauts. It has a valid coding declaration. Using ptpdb in it breaks with::

XXX/tests/test_file.py:205: in test_file__Add__Edit__Download_1
    assert False
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py:49: in trace_dispatch
    return self.dispatch_line(frame)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py:67: in dispatch_line
    self.user_line(frame)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py:158: in user_line
    self.interaction(frame, None)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py:210: in interaction
    self.cmdloop()
../../../python/eggs/ptpdb-0.9-py2.7.egg/ptpdb/__init__.py:305: in cmdloop
    line = self._get_input()
../../../python/eggs/ptpdb-0.9-py2.7.egg/ptpdb/__init__.py:345: in _get_input
    self._show_source_code(self.curframe.f_code.co_filename)
../../../python/eggs/ptpdb-0.9-py2.7.egg/ptpdb/__init__.py:389: in _show_source_code
    source_code_doc = self._get_source_code_document(filename)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ptpdb.PtPdb instance at 0x109336830>
filename = 'XXX/tests/test_file.py'

    def _get_source_code_document(self, filename):
        """
            Return source code around current line as string.
            """
>       source_code = ''.join(linecache.getlines(filename))
E       UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 28: ordinal not in range(128)

../../../python/eggs/ptpdb-0.9-py2.7.egg/ptpdb/__init__.py:397: UnicodeDecodeError
starenka commented 8 years ago

Same w/ me

simonwahlgren commented 8 years ago

I have a fix for this, see PR #15

jonathanslenders commented 8 years ago

Fixed in: https://github.com/jonathanslenders/ptpdb/commit/071d809f7152add42f4e4c8f7ccc949a7a2d2021 and https://github.com/jonathanslenders/ptpdb/commit/26f11f79b1547b5921b788ccea2d2f7879be9e42