Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8433243a
Commit
8433243a
authored
Jun 24, 2012
by
Larry Hastings
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15164: Change return value of platform.uname() from a
plain tuple to a collections.namedtuple.
parent
2c80746a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
18 deletions
+33
-18
Doc/library/platform.rst
Doc/library/platform.rst
+10
-4
Lib/platform.py
Lib/platform.py
+11
-7
Lib/sysconfig.py
Lib/sysconfig.py
+1
-1
Lib/test/test__locale.py
Lib/test/test__locale.py
+2
-2
Lib/test/test_platform.py
Lib/test/test_platform.py
+7
-1
Misc/NEWS
Misc/NEWS
+2
-3
No files found.
Doc/library/platform.rst
View file @
8433243a
...
@@ -158,14 +158,20 @@ Cross Platform
...
@@ -158,14 +158,20 @@ Cross Platform
.. function:: uname()
.. function:: uname()
Fairly portable uname interface. Returns a tuple of strings ``(system, node,
Fairly portable uname interface. Returns a :func:`~collections.namedtuple`
release, version, machine, processor)`` identifying the underlying platform.
containing six attributes: :attr:`system`, :attr:`node`, :attr:`release`,
:attr:`version`, :attr:`machine`, and :attr:`processor`.
Note that unlike the :func:`os.uname` function this also returns possible
Note that this adds a sixth attribute (:attr:`processor`) not present
processor information as additional tuple entry.
in the :func:`os.uname` result. Also, the attribute names are different
for the first two attributes; :func:`os.uname` names them
:attr:`sysname` and :attr:`nodename`.
Entries which cannot be determined are set to ``''``.
Entries which cannot be determined are set to ``''``.
.. versionchanged:: 3.3
Result changed from a tuple to a namedtuple.
Java Platform
Java Platform
-------------
-------------
...
...
Lib/platform.py
View file @
8433243a
...
@@ -111,6 +111,7 @@ __copyright__ = """
...
@@ -111,6 +111,7 @@ __copyright__ = """
__version__
=
'1.0.7'
__version__
=
'1.0.7'
import
collections
import
sys
,
os
,
re
import
sys
,
os
,
re
### Globals & Constants
### Globals & Constants
...
@@ -1027,6 +1028,9 @@ def architecture(executable=sys.executable,bits='',linkage=''):
...
@@ -1027,6 +1028,9 @@ def architecture(executable=sys.executable,bits='',linkage=''):
### Portable uname() interface
### Portable uname() interface
uname_result
=
collections
.
namedtuple
(
"uname_result"
,
"system node release version machine processor"
)
_uname_cache
=
None
_uname_cache
=
None
def
uname
():
def
uname
():
...
@@ -1161,7 +1165,7 @@ def uname():
...
@@ -1161,7 +1165,7 @@ def uname():
system
=
'Windows'
system
=
'Windows'
release
=
'Vista'
release
=
'Vista'
_uname_cache
=
system
,
node
,
release
,
version
,
machine
,
processor
_uname_cache
=
uname_result
(
system
,
node
,
release
,
version
,
machine
,
processor
)
return
_uname_cache
return
_uname_cache
### Direct interfaces to some of the uname() return values
### Direct interfaces to some of the uname() return values
...
@@ -1173,7 +1177,7 @@ def system():
...
@@ -1173,7 +1177,7 @@ def system():
An empty string is returned if the value cannot be determined.
An empty string is returned if the value cannot be determined.
"""
"""
return
uname
()
[
0
]
return
uname
()
.
system
def
node
():
def
node
():
...
@@ -1183,7 +1187,7 @@ def node():
...
@@ -1183,7 +1187,7 @@ def node():
An empty string is returned if the value cannot be determined.
An empty string is returned if the value cannot be determined.
"""
"""
return
uname
()
[
1
]
return
uname
()
.
node
def
release
():
def
release
():
...
@@ -1192,7 +1196,7 @@ def release():
...
@@ -1192,7 +1196,7 @@ def release():
An empty string is returned if the value cannot be determined.
An empty string is returned if the value cannot be determined.
"""
"""
return
uname
()
[
2
]
return
uname
()
.
release
def
version
():
def
version
():
...
@@ -1201,7 +1205,7 @@ def version():
...
@@ -1201,7 +1205,7 @@ def version():
An empty string is returned if the value cannot be determined.
An empty string is returned if the value cannot be determined.
"""
"""
return
uname
()
[
3
]
return
uname
()
.
version
def
machine
():
def
machine
():
...
@@ -1210,7 +1214,7 @@ def machine():
...
@@ -1210,7 +1214,7 @@ def machine():
An empty string is returned if the value cannot be determined.
An empty string is returned if the value cannot be determined.
"""
"""
return
uname
()
[
4
]
return
uname
()
.
machine
def
processor
():
def
processor
():
...
@@ -1222,7 +1226,7 @@ def processor():
...
@@ -1222,7 +1226,7 @@ def processor():
e.g. NetBSD does this.
e.g. NetBSD does this.
"""
"""
return
uname
()
[
5
]
return
uname
()
.
processor
### Various APIs for extracting information from sys.version
### Various APIs for extracting information from sys.version
...
...
Lib/sysconfig.py
View file @
8433243a
...
@@ -553,7 +553,7 @@ def get_config_vars(*args):
...
@@ -553,7 +553,7 @@ def get_config_vars(*args):
_CONFIG_VARS
[
'srcdir'
]
=
os
.
path
.
normpath
(
srcdir
)
_CONFIG_VARS
[
'srcdir'
]
=
os
.
path
.
normpath
(
srcdir
)
if
sys
.
platform
==
'darwin'
:
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
])
major_version
=
int
(
kernel_version
.
split
(
'.'
)[
0
])
if
major_version
<
8
:
if
major_version
<
8
:
...
...
Lib/test/test__locale.py
View file @
8433243a
...
@@ -11,8 +11,8 @@ import unittest
...
@@ -11,8 +11,8 @@ import unittest
from
platform
import
uname
from
platform
import
uname
from
test.support
import
run_unittest
from
test.support
import
run_unittest
if
uname
()
[
0
]
==
"Darwin"
:
if
uname
()
.
system
==
"Darwin"
:
maj
,
min
,
mic
=
[
int
(
part
)
for
part
in
uname
()
[
2
]
.
split
(
"."
)]
maj
,
min
,
mic
=
[
int
(
part
)
for
part
in
uname
()
.
release
.
split
(
"."
)]
if
(
maj
,
min
,
mic
)
<
(
8
,
0
,
0
):
if
(
maj
,
min
,
mic
)
<
(
8
,
0
,
0
):
raise
unittest
.
SkipTest
(
"locale support broken for OS X < 10.4"
)
raise
unittest
.
SkipTest
(
"locale support broken for OS X < 10.4"
)
...
...
Lib/test/test_platform.py
View file @
8433243a
...
@@ -133,6 +133,12 @@ class PlatformTest(unittest.TestCase):
...
@@ -133,6 +133,12 @@ class PlatformTest(unittest.TestCase):
def
test_uname
(
self
):
def
test_uname
(
self
):
res
=
platform
.
uname
()
res
=
platform
.
uname
()
self
.
assertTrue
(
any
(
res
))
self
.
assertTrue
(
any
(
res
))
self
.
assertEqual
(
res
[
0
],
res
.
system
)
self
.
assertEqual
(
res
[
1
],
res
.
node
)
self
.
assertEqual
(
res
[
2
],
res
.
release
)
self
.
assertEqual
(
res
[
3
],
res
.
version
)
self
.
assertEqual
(
res
[
4
],
res
.
machine
)
self
.
assertEqual
(
res
[
5
],
res
.
processor
)
@
unittest
.
skipUnless
(
sys
.
platform
.
startswith
(
'win'
),
"windows only test"
)
@
unittest
.
skipUnless
(
sys
.
platform
.
startswith
(
'win'
),
"windows only test"
)
def
test_uname_win32_ARCHITEW6432
(
self
):
def
test_uname_win32_ARCHITEW6432
(
self
):
...
@@ -166,7 +172,7 @@ class PlatformTest(unittest.TestCase):
...
@@ -166,7 +172,7 @@ class PlatformTest(unittest.TestCase):
def
test_mac_ver
(
self
):
def
test_mac_ver
(
self
):
res
=
platform
.
mac_ver
()
res
=
platform
.
mac_ver
()
if
platform
.
uname
()
[
0
]
==
'Darwin'
:
if
platform
.
uname
()
.
system
==
'Darwin'
:
# We're on a MacOSX system, check that
# We're on a MacOSX system, check that
# the right version information is returned
# the right version information is returned
fd
=
os
.
popen
(
'sw_vers'
,
'r'
)
fd
=
os
.
popen
(
'sw_vers'
,
'r'
)
...
...
Misc/NEWS
View file @
8433243a
...
@@ -59,9 +59,8 @@ Core and Builtins
...
@@ -59,9 +59,8 @@ Core and Builtins
Library
Library
-------
-------
-
Support
Mageia
Linux
in
the
platform
module
.
-
Issue
#
15164
:
Change
return
value
of
platform
.
uname
()
from
a
plain
tuple
to
a
collections
.
namedtuple
.
-
Issue
#
11678
:
Support
Arch
linux
in
the
platform
module
.
-
Issue
#
15118
:
Change
return
value
of
os
.
uname
()
and
os
.
times
()
from
-
Issue
#
15118
:
Change
return
value
of
os
.
uname
()
and
os
.
times
()
from
plain
tuples
to
immutable
iterable
objects
with
named
attributes
plain
tuples
to
immutable
iterable
objects
with
named
attributes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment