[issue4742] 3.0 distutils byte-compiling -> Syntax error: unknown encoding: cp1252

Amaury Forgeot d'Arc report at bugs.python.org
Tue Dec 30 15:38:03 CET 2008


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

This is a duplicate of issue4626.

Here, the content is correctly decoded with cp1252, then passed to
compile(); but compile() works on the internal utf-8 representation, and
tries to decode it again with cp1252!

Yes, the error message is overwritten. If I remove the code that sets
the "unknown encoding" exception, I get:

>>> compile(open("c:/temp/t1252.py", encoding="cp1252").read(),
"t1252.py", "exec")
SyntaxError: 'charmap' codec can't decode byte 0x9d in position 35:
character maps to <undefined>

The 0x9d explains easily:
>>> b"\x94".decode('cp1252').encode('utf8')
b'\xe2\x80\x9d'

----------
nosy: +amaury.forgeotdarc
superseder:  -> compile() doesn't ignore the source encoding when a string is passed in

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


More information about the Python-bugs-list mailing list