diff --git a/Lib/platform.py b/Lib/platform.py index 0a525871a85..570f327a806 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -261,6 +261,12 @@ _supported_dists = ( def _parse_release_file(firstline): + # Default to empty 'version' and 'id' strings. Both defaults are used + # when 'firstline' is empty. 'id' defaults to empty when an id can not + # be deduced. + version = '' + id = '' + # Parse the first line m = _lsb_release_version.match(firstline) if m is not None: @@ -278,8 +284,6 @@ def _parse_release_file(firstline): version = l[0] if len(l) > 1: id = l[1] - else: - id = '' return '', version, id def linux_distribution(distname='', version='', id='', diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 9b752343aec..af371856862 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -191,6 +191,7 @@ class PlatformTest(unittest.TestCase): ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')), ('CentOS release 4', ('CentOS', '4', None)), ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')), + ('', ('', '', '')), # If there's nothing there. ): self.assertEqual(platform._parse_release_file(input), output) diff --git a/Misc/ACKS b/Misc/ACKS index f0c667a57c8..27348e907d9 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -357,6 +357,7 @@ Jeremy Hylton Gerhard Häring Mihai Ibanescu Lars Immisch +Meador Inge Tony Ingraldi John Interrante Bob Ippolito diff --git a/Misc/NEWS b/Misc/NEWS index f5275b8cc4d..da9cf121a94 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -229,6 +229,9 @@ C-API Library ------- +- Issue #7773: Fix an UnboundLocalError in platform.linux_distribution() when + the release file is empty. + - Issue #7561: Fix crashes when using bytearray objects with the posix module.