From: Benjamin Peterson Date: Mon, 25 Jan 2010 03:40:53 +0000 (+0000) Subject: Merged revisions 77737 via svnmerge from X-Git-Tag: v3.1.2rc1~146 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79e0b818c577656c8ecc3576b5f34976a4cdff48;p=python Merged revisions 77737 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77737 | benjamin.peterson | 2010-01-24 21:37:42 -0600 (Sun, 24 Jan 2010) | 9 lines Merged revisions 77735 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77735 | benjamin.peterson | 2010-01-24 21:31:13 -0600 (Sun, 24 Jan 2010) | 1 line fix an UnboundLocalError when the release file is empty #7773 ........ ................ --- diff --git a/Lib/platform.py b/Lib/platform.py index 737198fcbf..d5100a86c2 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -245,6 +245,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: @@ -262,8 +268,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 9b752343ae..af37185686 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 f32b46b6fe..3421585a16 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -347,6 +347,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 74a64f0e1e..befc61c323 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -73,6 +73,9 @@ Core and Builtins 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.