Author JGoutin
Recipients JGoutin, paul.moore, steve.dower, tim.golden, zach.ware
Date 2017-01-11.12:28:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484137681.59.0.0301192140292.issue29241@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-01-11 12:28:01JGoutinsetrecipients: + JGoutin, paul.moore, tim.golden, zach.ware, steve.dower
2017-01-11 12:28:01JGoutinsetmessageid: <1484137681.59.0.0301192140292.issue29241@psf.upfronthosting.co.za>
2017-01-11 12:28:01JGoutinlinkissue29241 messages
2017-01-11 12:28:01JGoutincreate