[New-bugs-announce] [issue29241] sys._enablelegacywindowsfsencoding() don't apply to os.fsencode and os.fsdecode
JGoutin
report at bugs.python.org
Wed Jan 11 07:28:01 EST 2017
New submission from JGoutin:
The doc say that calling "sys._enablelegacywindowsfsencoding()" is equivalent to use "PYTHONLEGACYWINDOWSFSENCODING" environment variable.
In fact, this no apply to "os.fsencode" and "os.fsdecode".
Example with Python 3.6 64Bits on Windows 7 64 bits :
EXAMPLE CODE 1 (sys._enablelegacywindowsfsencoding()):
import sys
import os
# Force the use of legacy encoding like versions of Python prior to 3.6.
sys._enablelegacywindowsfsencoding()
# Show actual file system encoding
encoding = sys.getfilesystemencoding()
print('File system encoding:', encoding)
# os.fsencode(filename) VS filename.encode(File system encoding)
print(os.fsencode('é'), 'é'.encode(encoding))
>>> File system encoding: mbcs
>>> b'\xc3\xa9' b'\xe9'
First is encoded with "utf-8" and not "mbcs" (The actual File system encoding)
EXAMPLE CODE 2 (PYTHONLEGACYWINDOWSFSENCODING):
import sys
import os
# Force the use of legacy encoding like versions of Python prior to 3.6.
# "PYTHONLEGACYWINDOWSFSENCODING" environment variable set before running Python.
# Show actual file system encoding
encoding = sys.getfilesystemencoding()
print('File system encoding:', encoding)
# os.fsencode(filename) VS filename.encode(File system encoding)
print(os.fsencode('é'), 'é'.encode(encoding))
>>> File system encoding: mbcs
>>> b'\xe9' b'\xe9'
Everything encoded with "mbcs" (The actual File system encoding)
In "os.fsencode" and "os.fsdecode" encoding and errors are cached on start and never updated by "sys._enablelegacywindowsfsencoding()" after.
----------
components: Windows
messages: 285220
nosy: JGoutin, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: sys._enablelegacywindowsfsencoding() don't apply to os.fsencode and os.fsdecode
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29241>
_______________________________________
More information about the New-bugs-announce
mailing list