diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-12-09 00:04:09 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-12-09 00:04:09 +0100 |
commit | 6d2677d63f14ec7d725ce31daa67504609a19b58 (patch) | |
tree | eb512881cade9b292536a809f7229160c0e919c1 /Lib/platform.py | |
parent | 3358e6136adc3656270a44bb8e735cdd8d3b8f1d (diff) | |
parent | 098daf7de64cd9fe550c4e013315bd8b33675ec5 (diff) | |
download | cpython-6d2677d63f14ec7d725ce31daa67504609a19b58.tar.gz |
(Merge 3.3) Issue #17429: platform.linux_distribution() now decodes files from
the UTF-8 encoding with the surrogateescape error handler, instead of decoding
from the locale encoding in strict mode. It fixes the function on Fedora 19
which is probably the first major distribution release with a non-ASCII name.
Patch written by Toshio Kuratomi.
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-x | Lib/platform.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index c3c4b328e1..ddddff4eb9 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -129,6 +129,10 @@ except AttributeError: # Standard Unix uses /dev/null DEV_NULL = '/dev/null' +# Directory to search for configuration information on Unix. +# Constant used by test_platform to test linux_distribution(). +_UNIXCONFDIR = '/etc' + ### Platform specific APIs _libc_search = re.compile(b'(__libc_init)' @@ -315,7 +319,7 @@ def linux_distribution(distname='', version='', id='', """ try: - etc = os.listdir('/etc') + etc = os.listdir(_UNIXCONFDIR) except OSError: # Probably not a Unix system return distname,version,id @@ -331,7 +335,8 @@ def linux_distribution(distname='', version='', id='', return _dist_try_harder(distname,version,id) # Read the first line - with open('/etc/'+file, 'r') as f: + with open(os.path.join(_UNIXCONFDIR, file), 'r', + encoding='utf-8', errors='surrogateescape') as f: firstline = f.readline() _distname, _version, _id = _parse_release_file(firstline) |