summaryrefslogtreecommitdiff
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-23 11:09:20 -0700
committerGitHub <noreply@github.com>2021-04-23 19:09:20 +0100
commit52e9031fbd23c10668badc2a72ee5c203d6902c7 (patch)
tree6eb7dea78539f430d18e84c87e2f7245a0bc70b7 /Lib/platform.py
parent04bcfe001cdf6290cb78fa4884002e5301e14c93 (diff)
downloadcpython-git-52e9031fbd23c10668badc2a72ee5c203d6902c7.tar.gz
bpo-43284: Update platform.win32_ver to use _syscmd_ver instead of sys.getwindowsversion() (GH-25500)
The sys module uses the kernel32.dll version number, which can vary from the "actual" Windows version. Since the best option for getting the version is WMI (which is expensive), we switch back to launching cmd.exe (which is also expensive, but a lot less code on our part). sys.getwindowsversion() is not updated to avoid launching executables from that module. (cherry picked from commit 2a3f4899c63806439e5bcea0c30f7e6a6295a763) Co-authored-by: Shreyan Avigyan <shreyan.avigyan@gmail.com>
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 6258827d0e..0bce4381cc 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -239,11 +239,9 @@ def _norm_version(version, build=''):
if build:
l.append(build)
try:
- ints = map(int, l)
+ strings = list(map(str, map(int, l)))
except ValueError:
strings = l
- else:
- strings = list(map(str, ints))
version = '.'.join(strings[:3])
return version
@@ -365,17 +363,20 @@ def win32_ver(release='', version='', csd='', ptype=''):
return release, version, csd, ptype
winver = getwindowsversion()
- maj, min, build = winver.platform_version or winver[:3]
- version = '{0}.{1}.{2}'.format(maj, min, build)
+ try:
+ major, minor, build = map(int, _syscmd_ver()[2].split('.'))
+ except ValueError:
+ major, minor, build = winver.platform_version or winver[:3]
+ version = '{0}.{1}.{2}'.format(major, minor, build)
- release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
- _WIN32_CLIENT_RELEASES.get((maj, None)) or
+ release = (_WIN32_CLIENT_RELEASES.get((major, minor)) or
+ _WIN32_CLIENT_RELEASES.get((major, None)) or
release)
# getwindowsversion() reflect the compatibility mode Python is
# running under, and so the service pack value is only going to be
# valid if the versions match.
- if winver[:2] == (maj, min):
+ if winver[:2] == (major, minor):
try:
csd = 'SP{}'.format(winver.service_pack_major)
except AttributeError:
@@ -384,8 +385,8 @@ def win32_ver(release='', version='', csd='', ptype=''):
# VER_NT_SERVER = 3
if getattr(winver, 'product_type', None) == 3:
- release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
- _WIN32_SERVER_RELEASES.get((maj, None)) or
+ release = (_WIN32_SERVER_RELEASES.get((major, minor)) or
+ _WIN32_SERVER_RELEASES.get((major, None)) or
release)
try: