[issue9425] Rewrite import machinery to work with unicode paths

STINNER Victor report at bugs.python.org
Sun Aug 8 15:16:16 CEST 2010

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

pyerr_warnformat.patch: create PyErr_WarnFormat() function, and use it in PyType_Ready() and PyUnicode_AsEncodedString(). The patch fixes also setup_context(): work on the unicode filename, not the encoded (bytes) filename. It does fix a bug because len is a number of characters, not a number of bytes: the number of bytes is bigger than the number of characters if the filename contains a non-ASCII character.

Advantages of PyErr_WarnFormat() over PyOS_snprintf() + PyErr_WarnEx():
 - it avoids the create a temporary byte buffer: use directly an unicode buffer,
 - it accepts Python (unicode) formatters like %U,
 - it avoids the usage of a fixed size buffer allocated on the stack (which may be too big).

Differences with Rietveld's version: rename PyErr_WarnUnicode() to warn_unicode() (it's now a static function) and document PyErr_WarnFormat().

nosy: +amaury.forgeotdarc, merwok, pitrou
Added file: http://bugs.python.org/file18432/pyerr_warnformat.patch

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list