diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-18 21:23:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-18 21:23:25 (GMT) |
commit | 94908bbc1503df830d1d615e7b57744ae1b41079 (patch) | |
tree | 21569de8c7a5018cd83c3692c06544ba77de6f6c /Lib | |
parent | 56ab01b66aaee7495615beecd90438fe9ed99615 (diff) | |
download | cpython-94908bbc1503df830d1d615e7b57744ae1b41079.zip cpython-94908bbc1503df830d1d615e7b57744ae1b41079.tar.gz cpython-94908bbc1503df830d1d615e7b57744ae1b41079.tar.bz2 |
Issue #8622: Add PYTHONFSENCODING environment variable to override the
filesystem encoding.
initfsencoding() displays also a better error message if get_codeset() failed.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_pep277.py | 2 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 32 |
2 files changed, 25 insertions, 9 deletions
diff --git a/Lib/test/test_pep277.py b/Lib/test/test_pep277.py index 60d99db..0699317 100644 --- a/Lib/test/test_pep277.py +++ b/Lib/test/test_pep277.py @@ -43,7 +43,7 @@ if sys.platform != 'darwin': # Is it Unicode-friendly? if not os.path.supports_unicode_filenames: - fsencoding = sys.getfilesystemencoding() or sys.getdefaultencoding() + fsencoding = sys.getfilesystemencoding() try: for name in filenames: name.encode(fsencoding) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 44ef5c1..d2f5b85 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -863,16 +863,24 @@ class SizeofTest(unittest.TestCase): def test_getfilesystemencoding(self): import codecs - def check_fsencoding(fs_encoding): + def check_fsencoding(fs_encoding, expected=None): self.assertIsNotNone(fs_encoding) if sys.platform == 'darwin': self.assertEqual(fs_encoding, 'utf-8') codecs.lookup(fs_encoding) + if expected: + self.assertEqual(fs_encoding, expected) fs_encoding = sys.getfilesystemencoding() check_fsencoding(fs_encoding) - # Even in C locale + def get_fsencoding(env): + output = subprocess.check_output( + [sys.executable, "-c", + "import sys; print(sys.getfilesystemencoding())"], + env=env) + return output.rstrip().decode('ascii') + try: sys.executable.encode('ascii') except UnicodeEncodeError: @@ -880,14 +888,22 @@ class SizeofTest(unittest.TestCase): # see issue #8611 pass else: + # Even in C locale env = os.environ.copy() env['LANG'] = 'C' - output = subprocess.check_output( - [sys.executable, "-c", - "import sys; print(sys.getfilesystemencoding())"], - env=env) - fs_encoding = output.rstrip().decode('ascii') - check_fsencoding(fs_encoding) + try: + del env['PYTHONFSENCODING'] + except KeyError: + pass + check_fsencoding(get_fsencoding(env), 'ascii') + + # Filesystem encoding is hardcoded on Windows and Mac OS X + if sys.platform not in ('win32', 'darwin'): + for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'): + env = os.environ.copy() + env['PYTHONFSENCODING'] = encoding + check_fsencoding(get_fsencoding(env), encoding) + def test_setfilesystemencoding(self): old = sys.getfilesystemencoding() |