[issue6543] traceback presented in wrong encoding
Amaury Forgeot d'Arc
report at bugs.python.org
Wed Jul 22 17:04:20 CEST 2009
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
This also happens on a Western Windows (cp437, mbcs==cp1252) with a
filename like "café.py".
The attached patch corrects three problems:
- in compile.c, the c_filename member has utf8 encoding, and must not be
decoded with PyUnicode_DecodeFSDefault. This is the reported issue.
- Same thing in pythonrun.c, if you want "print(__file__)" to work.
- in traceback.c, the content of the file is not shown.
Tested with this script:
=====================================================
print("file name:", __file__)
import traceback
try:
aaa
except:
traceback.print_exc()
raise
=====================================================
The output should be:
=====================================================
file name: c:\temp\café.py
Traceback (most recent call last):
File "c:\temp\café.py", line 4, in <module>
aaa
NameError: name 'aaa' is not defined
Traceback (most recent call last):
File "c:\temp\café.py", line 4, in <module>
aaa
NameError: name 'aaa' is not defined
=====================================================
----------
keywords: +patch
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file14538/traceback-encoding.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6543>
_______________________________________
More information about the Python-bugs-list
mailing list