diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -111,6 +111,7 @@ __version__ = '1.0.7' +import collections import sys, os, re ### Globals & Constants @@ -1027,6 +1028,9 @@ ### Portable uname() interface +uname_result = collections.namedtuple("uname_result", + "system node release version machine processor") + _uname_cache = None def uname(): @@ -1161,7 +1165,7 @@ system = 'Windows' release = 'Vista' - _uname_cache = system,node,release,version,machine,processor + _uname_cache = uname_result(system,node,release,version,machine,processor) return _uname_cache ### Direct interfaces to some of the uname() return values @@ -1173,7 +1177,7 @@ An empty string is returned if the value cannot be determined. """ - return uname()[0] + return uname().system def node(): @@ -1183,7 +1187,7 @@ An empty string is returned if the value cannot be determined. """ - return uname()[1] + return uname().node def release(): @@ -1192,7 +1196,7 @@ An empty string is returned if the value cannot be determined. """ - return uname()[2] + return uname().release def version(): @@ -1201,7 +1205,7 @@ An empty string is returned if the value cannot be determined. """ - return uname()[3] + return uname().version def machine(): @@ -1210,7 +1214,7 @@ An empty string is returned if the value cannot be determined. """ - return uname()[4] + return uname().machine def processor(): @@ -1222,7 +1226,7 @@ e.g. NetBSD does this. """ - return uname()[5] + return uname().processor ### Various APIs for extracting information from sys.version diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -553,7 +553,7 @@ _CONFIG_VARS['srcdir'] = os.path.normpath(srcdir) if sys.platform == 'darwin': - kernel_version = os.uname()[2] # Kernel version (8.4.3) + kernel_version = os.uname().release # Kernel version (8.4.3) major_version = int(kernel_version.split('.')[0]) if major_version < 8: diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py --- a/Lib/test/test__locale.py +++ b/Lib/test/test__locale.py @@ -11,8 +11,8 @@ from platform import uname from test.support import run_unittest -if uname()[0] == "Darwin": - maj, min, mic = [int(part) for part in uname()[2].split(".")] +if uname().system == "Darwin": + maj, min, mic = [int(part) for part in uname().release.split(".")] if (maj, min, mic) < (8, 0, 0): raise unittest.SkipTest("locale support broken for OS X < 10.4") diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -166,7 +166,7 @@ def test_mac_ver(self): res = platform.mac_ver() - if platform.uname()[0] == 'Darwin': + if platform.uname().system == 'Darwin': # We're on a MacOSX system, check that # the right version information is returned fd = os.popen('sw_vers', 'r')