[issue4282] profile doesn't support non-UTF8 source code

STINNER Victor report at bugs.python.org
Fri Mar 20 02:30:37 CET 2009


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

Oops, i misread this issue (wrong title!). #4626 is related, but this 
issue is about the profile module. The problem is that profile open 
the source code as text (with the default charset: UTF-8).

Attached patch fixes the problem.

Example:
--- x.py (ISO-8859-1 text file) ---
#coding: ISO-8859-1
print("hé hé")
-----------------------------------

Run: python -m profile x.py

Current result:
  (...)
  File ".../py3k/Lib/profile.py", line 614, in main
    script = fp.read()
  File ".../Lib/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode bytes (...)

With my patch, it works as expected.

----------
dependencies: +compile() doesn't ignore the source encoding when a string is passed in
resolution: fixed -> 
status: closed -> open
title: exec(unicode): invalid charset when #coding:xxx spec is used -> profile doesn't support non-UTF8 source code

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4282>
_______________________________________


More information about the Python-bugs-list mailing list