Skip to content

Commit 8f6b6b0

Browse files
author
Victor Stinner
committed
Issue #9992: Remove PYTHONFSENCODING environment variable.
1 parent aa96592 commit 8f6b6b0

File tree

8 files changed

+8
-100
lines changed

8 files changed

+8
-100
lines changed

‎Doc/using/cmdline.rst‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,6 @@ These environment variables influence Python's behavior.
442442
import of source modules.
443443

444444

445-
.. envvar:: PYTHONFSENCODING
446-
447-
If this is set before running the interpreter, it overrides the encoding used
448-
for the filesystem encoding (see :func:`sys.getfilesystemencoding`).
449-
450-
This variable is not available (ignored) on Windows and Mac OS X: the
451-
filesystem encoding is pinned to ``'mbcs'`` on Windows and ``'utf-8'`` on
452-
Mac OS X.
453-
454-
.. versionadded:: 3.2
455-
456-
457445
.. envvar:: PYTHONIOENCODING
458446

459447
If this is set before running the interpreter, it overrides the encoding used

‎Doc/whatsnew/3.2.rst‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,6 @@ A number of small performance enhancements have been added:
569569
Filenames and Unicode
570570
=====================
571571

572-
The filesystem encoding can be specified by setting the
573-
:envvar:`PYTHONFSENCODING` environment variable before running the interpreter.
574-
The value is an encoding name, e.g. ``iso-8859-1``. This variable is not
575-
available (ignored) on Windows and Mac OS X: the filesystem encoding is pinned
576-
to ``'mbcs'`` on Windows and ``'utf-8'`` on Mac OS X.
577-
578572
The :mod:`os` module has two new functions: :func:`~os.fsencode` and
579573
:func:`~os.fsdecode`.
580574

‎Lib/test/test_os.py‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,36 +1172,6 @@ def test_identity(self):
11721172
continue
11731173
self.assertEquals(os.fsdecode(bytesfn), fn)
11741174

1175-
def get_output(self, fs_encoding, func):
1176-
env = os.environ.copy()
1177-
env['PYTHONIOENCODING'] = 'utf-8'
1178-
env['PYTHONFSENCODING'] = fs_encoding
1179-
code = 'import os; print(%s, end="")' % func
1180-
process = subprocess.Popen(
1181-
[sys.executable, "-c", code],
1182-
stdout=subprocess.PIPE, env=env)
1183-
stdout, stderr = process.communicate()
1184-
self.assertEqual(process.returncode, 0)
1185-
return stdout.decode('utf-8')
1186-
1187-
@unittest.skipIf(sys.platform in ('win32', 'darwin'),
1188-
'PYTHONFSENCODING is ignored on Windows and Mac OS X')
1189-
def test_encodings(self):
1190-
def check(encoding, bytesfn, unicodefn):
1191-
encoded = self.get_output(encoding, 'repr(os.fsencode(%a))' % unicodefn)
1192-
self.assertEqual(encoded, repr(bytesfn))
1193-
1194-
decoded = self.get_output(encoding, 'repr(os.fsdecode(%a))' % bytesfn)
1195-
self.assertEqual(decoded, repr(unicodefn))
1196-
1197-
check('utf-8', b'\xc3\xa9\x80', '\xe9\udc80')
1198-
1199-
# Raise SkipTest() if sys.executable is not encodable to ascii
1200-
support.workaroundIssue8611()
1201-
1202-
check('ascii', b'abc\xff', 'abc\udcff')
1203-
check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
1204-
12051175

12061176
class PidTests(unittest.TestCase):
12071177
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")

‎Lib/test/test_subprocess.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,6 @@ def test_undecodable_env(self):
885885
script = "import os; print(ascii(os.getenv(%s)))" % repr(key)
886886
env = os.environ.copy()
887887
env[key] = value
888-
# Force surrogate-escaping of \xFF in the child process;
889-
# otherwise it can be decoded as-is if the default locale
890-
# is latin-1.
891-
env['PYTHONFSENCODING'] = 'ascii'
892888
stdout = subprocess.check_output(
893889
[sys.executable, "-c", script],
894890
env=env)

‎Lib/test/test_sys.py‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -602,35 +602,6 @@ def test_getfilesystemencoding(self):
602602
expected = None
603603
self.check_fsencoding(fs_encoding, expected)
604604

605-
@unittest.skipIf(sys.platform in ('win32', 'darwin'),
606-
'PYTHONFSENCODING is ignored on Windows and Mac OS X')
607-
def test_pythonfsencoding(self):
608-
def get_fsencoding(env):
609-
output = subprocess.check_output(
610-
[sys.executable, "-c",
611-
"import sys; print(sys.getfilesystemencoding())"],
612-
env=env)
613-
return output.rstrip().decode('ascii')
614-
615-
# Raise SkipTest() if sys.executable is not encodable to ascii
616-
test.support.workaroundIssue8611()
617-
618-
# Use C locale to get ascii for the locale encoding
619-
env = os.environ.copy()
620-
env['LC_ALL'] = 'C'
621-
try:
622-
del env['PYTHONFSENCODING']
623-
except KeyError:
624-
pass
625-
self.check_fsencoding(get_fsencoding(env), 'ascii')
626-
627-
# Filesystem encoding is hardcoded on Windows and Mac OS X
628-
for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'):
629-
env = os.environ.copy()
630-
env['PYTHONFSENCODING'] = encoding
631-
self.check_fsencoding(get_fsencoding(env), encoding)
632-
633-
634605

635606
class SizeofTest(unittest.TestCase):
636607

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.2 Beta 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9992: Remove PYTHONFSENCODING environment variable.
14+
1315
Library
1416
-------
1517

‎Modules/main.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ static char *usage_5 =
9999
" The default module search path uses %s.\n"
100100
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"
101101
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n"
102-
#if !(defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)) && !defined(__APPLE__)
103-
"PYTHONFSENCODING: Encoding used for the filesystem.\n"
104-
#endif
105102
;
106103

107104
static int

‎Python/pythonrun.c‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -980,22 +980,12 @@ initfsencoding(void)
980980
char *codeset = NULL;
981981

982982
if (Py_FileSystemDefaultEncoding == NULL) {
983-
const char *env_encoding = Py_GETENV("PYTHONFSENCODING");
984-
if (env_encoding != NULL) {
985-
codeset = get_codec_name(env_encoding);
986-
if (!codeset) {
987-
fprintf(stderr, "PYTHONFSENCODING is not a valid encoding:\n");
988-
PyErr_Print();
989-
}
990-
}
991-
if (!codeset) {
992-
/* On Unix, set the file system encoding according to the
993-
user's preference, if the CODESET names a well-known
994-
Python codec, and Py_FileSystemDefaultEncoding isn't
995-
initialized by other means. Also set the encoding of
996-
stdin and stdout if these are terminals. */
997-
codeset = get_codeset();
998-
}
983+
/* On Unix, set the file system encoding according to the
984+
user's preference, if the CODESET names a well-known
985+
Python codec, and Py_FileSystemDefaultEncoding isn't
986+
initialized by other means. Also set the encoding of
987+
stdin and stdout if these are terminals. */
988+
codeset = get_codeset();
999989
if (codeset != NULL) {
1000990
if (redecode_filenames(codeset))
1001991
Py_FatalError("Py_Initialize: can't redecode filenames");

0 commit comments

Comments
 (0)