[issue24230] tempfile.mkdtemp() doesn't work with bytes paths

STINNER Victor report at bugs.python.org
Tue Mar 15 07:46:23 EDT 2016


STINNER Victor added the comment:

"""
Today we're doing something like this:

tmpdir = tempfile.mkdtemp('', 'hgtests.', d and d.decode('utf-8')).encode('utf-8')
"""

Don't do that. UTF-8 is not the right encoding.

Use os.fsencode() and os.fsdecode(). Internally, Python uses sys.getfilesystemencoding() with 'surrogateescape' error handler (but 'strict' error handler on Windows).

If you use UTF-8, you can get indirectly mojibake.

----------

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


More information about the Python-bugs-list mailing list