From e34c42c6ee235d650c5b6d8fb90f085845ff14cf Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Wed, 21 Apr 2021 14:52:05 +0530 Subject: [PATCH 01/10] Fix bpo-43284 --- Lib/platform.py | 5 ++++- .../next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst diff --git a/Lib/platform.py b/Lib/platform.py index d567dd1a6e1ad7..829150a64670c2 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -365,7 +365,10 @@ def win32_ver(release='', version='', csd='', ptype=''): return release, version, csd, ptype winver = getwindowsversion() - maj, min, build = winver.platform_version or winver[:3] + cmdwinver = _syscmd_ver()[2].split('.') + for x in range(3): + cmdwinver[x] = int(cmdwinver[x]) + maj, min, build = tuple(cmdwinver) or winver[:3] version = '{0}.{1}.{2}'.format(maj, min, build) release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or diff --git a/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst b/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst new file mode 100644 index 00000000000000..1a0826962054c1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst @@ -0,0 +1,6 @@ +platform.win32_ver derives the windows version from +sys.getwindowsversion().platform_version which in turn derives the version +from kernel32.dll (which can be of a different version than Windows itself). +Therefore change the platform.win32_ver to determine the version using the +platform's module _syscmd_ver private function to return an accurate +version. From 7203f2839fcb902746719ac61e4b208fd297322c Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Wed, 21 Apr 2021 21:32:44 +0530 Subject: [PATCH 02/10] Update sys module docs to recommend using platform module for achieving accurate OS version --- Doc/library/sys.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 721edd1495aa5b..f32fb1c8dcafb1 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -796,11 +796,16 @@ always available. Microsoft documentation on :c:func:`OSVERSIONINFOEX` for more information about these fields. - *platform_version* returns the accurate major version, minor version and + *platform_version* returns the major version, minor version and build number of the current operating system, rather than the version that is being emulated for the process. It is intended for use in logging rather than for feature detection. + .. note:: + *platform_version* derives the version from kernel32.dll which can be of + a different version than the OS version. Use :mod:`platform` module for achieving + accurate OS version. + .. availability:: Windows. .. versionchanged:: 3.2 From b4b396ae6522b14e2cfe7f891d28f505d146b0c4 Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Wed, 21 Apr 2021 21:40:11 +0530 Subject: [PATCH 03/10] Update news entry --- .../next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst b/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst index 1a0826962054c1..7e41016015efed 100644 --- a/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst +++ b/Misc/NEWS.d/next/Library/2021-04-21-14-50-57.bpo-43284.2QZn2T.rst @@ -2,5 +2,5 @@ platform.win32_ver derives the windows version from sys.getwindowsversion().platform_version which in turn derives the version from kernel32.dll (which can be of a different version than Windows itself). Therefore change the platform.win32_ver to determine the version using the -platform's module _syscmd_ver private function to return an accurate +platform module's _syscmd_ver private function to return an accurate version. From 936eb78d565e5902cfe1b89bd8814626da979505 Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Wed, 21 Apr 2021 23:27:23 +0530 Subject: [PATCH 04/10] Update sys.rst --- Doc/library/sys.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index f32fb1c8dcafb1..61f9d1fc99bdf4 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -802,6 +802,7 @@ always available. than for feature detection. .. note:: + *platform_version* derives the version from kernel32.dll which can be of a different version than the OS version. Use :mod:`platform` module for achieving accurate OS version. From df28d4bc3d123d9a7f0496bb1d03164d7572ff6a Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Wed, 21 Apr 2021 23:33:46 +0530 Subject: [PATCH 05/10] Update sys.rst --- Doc/library/sys.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 61f9d1fc99bdf4..820171f4497a3d 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -802,10 +802,8 @@ always available. than for feature detection. .. note:: - - *platform_version* derives the version from kernel32.dll which can be of - a different version than the OS version. Use :mod:`platform` module for achieving - accurate OS version. + *platform_version* derives the version from kernel32.dll which can be of a different + version than the OS version. Please use :mod:`platform` for achieving accurate OS version. .. availability:: Windows. From 654f4158f3093f5607ffc15486fafcf959f450c7 Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Thu, 22 Apr 2021 00:04:58 +0530 Subject: [PATCH 06/10] Update Lib/platform.py Co-authored-by: Eryk Sun --- Lib/platform.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index 829150a64670c2..72d8c37f2be573 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -365,10 +365,10 @@ def win32_ver(release='', version='', csd='', ptype=''): return release, version, csd, ptype winver = getwindowsversion() - cmdwinver = _syscmd_ver()[2].split('.') - for x in range(3): - cmdwinver[x] = int(cmdwinver[x]) - maj, min, build = tuple(cmdwinver) or winver[:3] + try: + maj, min, build = map(int, _syscmd_ver()[2].split('.')) + except ValueError: + maj, min, build = winver.platform_version or winver[:3] version = '{0}.{1}.{2}'.format(maj, min, build) release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or From 2891975143ecb75cc8928dbbbe0f9cd8ce7a42bd Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Thu, 22 Apr 2021 00:18:32 +0530 Subject: [PATCH 07/10] Update platform.py --- Lib/platform.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index 72d8c37f2be573..c38c7908ab1c5d 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -238,12 +238,7 @@ def _norm_version(version, build=''): l = version.split('.') if build: l.append(build) - try: - ints = map(int, l) - except ValueError: - strings = l - else: - strings = list(map(str, ints)) + strings = list(map(str, map(int, l))) version = '.'.join(strings[:3]) return version From 5328f59d82647ccbb8d51182427b0c2696b409ed Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Thu, 22 Apr 2021 00:22:37 +0530 Subject: [PATCH 08/10] Update Lib/platform.py Co-authored-by: Steve Dower --- Lib/platform.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/platform.py b/Lib/platform.py index c38c7908ab1c5d..766df6f220acbc 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -238,7 +238,10 @@ def _norm_version(version, build=''): l = version.split('.') if build: l.append(build) - strings = list(map(str, map(int, l))) + try: + strings = list(map(str, map(int, l))) + except ValueError: + strings = l version = '.'.join(strings[:3]) return version From 49ff667ab4e1a3184df22b17e4e177ddfe70b6a7 Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Thu, 22 Apr 2021 11:29:46 +0530 Subject: [PATCH 09/10] Update --- Doc/library/sys.rst | 3 ++- Lib/platform.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 820171f4497a3d..3016ac1d29159a 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -803,7 +803,8 @@ always available. .. note:: *platform_version* derives the version from kernel32.dll which can be of a different - version than the OS version. Please use :mod:`platform` for achieving accurate OS version. + version than the OS version. Please use :mod:`platform` module for achieving accurate + OS version. .. availability:: Windows. diff --git a/Lib/platform.py b/Lib/platform.py index 766df6f220acbc..d298a42edc8483 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -364,19 +364,19 @@ def win32_ver(release='', version='', csd='', ptype=''): winver = getwindowsversion() try: - maj, min, build = map(int, _syscmd_ver()[2].split('.')) + major, minor, build = map(int, _syscmd_ver()[2].split('.')) except ValueError: - maj, min, build = winver.platform_version or winver[:3] - version = '{0}.{1}.{2}'.format(maj, min, build) + 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: @@ -385,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: From 5d88afcc48411ab3f2b8070c265053f124b92e45 Mon Sep 17 00:00:00 2001 From: Shreyan Avigyan Date: Thu, 22 Apr 2021 11:37:49 +0530 Subject: [PATCH 10/10] Update sys.rst --- Doc/library/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 3016ac1d29159a..759c714b6c97a6 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -803,7 +803,7 @@ always available. .. note:: *platform_version* derives the version from kernel32.dll which can be of a different - version than the OS version. Please use :mod:`platform` module for achieving accurate + version than the OS version. Please use :mod:`platform` module for achieving accurate OS version. .. availability:: Windows.