Skip to content

Commit 70ddf3c

Browse files
CPython Developersyouknowone
CPython Developers
authored andcommitted
Update platform from CPython 3.11.5
1 parent 64c66e0 commit 70ddf3c

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

Lib/platform.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
If called from the command line, it prints the platform
77
information concatenated as single string to stdout. The output
8-
format is useable as part of a filename.
8+
format is usable as part of a filename.
99
1010
"""
1111
# This module is maintained by Marc-Andre Lemburg <mal@egenix.com>.
@@ -116,7 +116,6 @@
116116
import os
117117
import re
118118
import sys
119-
import subprocess
120119
import functools
121120
import itertools
122121

@@ -169,7 +168,7 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
169168
170169
Note that the function has intimate knowledge of how different
171170
libc versions add symbols to the executable and thus is probably
172-
only useable for executables compiled using gcc.
171+
only usable for executables compiled using gcc.
173172
174173
The file is read and scanned in chunks of chunksize bytes.
175174
@@ -187,12 +186,15 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
187186

188187
executable = sys.executable
189188

189+
if not executable:
190+
# sys.executable is not set.
191+
return lib, version
192+
190193
V = _comparable_version
191-
if hasattr(os.path, 'realpath'):
192-
# Python 2.2 introduced os.path.realpath(); it is used
193-
# here to work around problems with Cygwin not being
194-
# able to open symlinks for reading
195-
executable = os.path.realpath(executable)
194+
# We use os.path.realpath()
195+
# here to work around problems with Cygwin not being
196+
# able to open symlinks for reading
197+
executable = os.path.realpath(executable)
196198
with open(executable, 'rb') as f:
197199
binary = f.read(chunksize)
198200
pos = 0
@@ -283,6 +285,7 @@ def _syscmd_ver(system='', release='', version='',
283285
stdin=subprocess.DEVNULL,
284286
stderr=subprocess.DEVNULL,
285287
text=True,
288+
encoding="locale",
286289
shell=True)
287290
except (OSError, subprocess.CalledProcessError) as why:
288291
#print('Command %s failed: %s' % (cmd, why))
@@ -609,7 +612,10 @@ def _syscmd_file(target, default=''):
609612
# XXX Others too ?
610613
return default
611614

612-
import subprocess
615+
try:
616+
import subprocess
617+
except ImportError:
618+
return default
613619
target = _follow_symlinks(target)
614620
# "file" output is locale dependent: force the usage of the C locale
615621
# to get deterministic behavior.
@@ -748,11 +754,16 @@ def from_subprocess():
748754
"""
749755
Fall back to `uname -p`
750756
"""
757+
try:
758+
import subprocess
759+
except ImportError:
760+
return None
751761
try:
752762
return subprocess.check_output(
753763
['uname', '-p'],
754764
stderr=subprocess.DEVNULL,
755765
text=True,
766+
encoding="utf8",
756767
).strip()
757768
except (OSError, subprocess.CalledProcessError):
758769
pass
@@ -776,6 +787,8 @@ class uname_result(
776787
except when needed.
777788
"""
778789

790+
_fields = ('system', 'node', 'release', 'version', 'machine', 'processor')
791+
779792
@functools.cached_property
780793
def processor(self):
781794
return _unknown_as_blank(_Processor.get())
@@ -789,7 +802,7 @@ def __iter__(self):
789802
@classmethod
790803
def _make(cls, iterable):
791804
# override factory to affect length check
792-
num_fields = len(cls._fields)
805+
num_fields = len(cls._fields) - 1
793806
result = cls.__new__(cls, *iterable)
794807
if len(result) != num_fields + 1:
795808
msg = f'Expected {num_fields} arguments, got {len(result)}'
@@ -803,7 +816,7 @@ def __len__(self):
803816
return len(tuple(iter(self)))
804817

805818
def __reduce__(self):
806-
return uname_result, tuple(self)[:len(self._fields)]
819+
return uname_result, tuple(self)[:len(self._fields) - 1]
807820

808821

809822
_uname_cache = None

0 commit comments

Comments
 (0)