summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-01-25 03:31:13 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-01-25 03:31:13 (GMT)
commita43f34cc2a7a55cea794ecb9bda2eea5c685d1f3 (patch)
treeb9d565fb57073f0ce30bbeceab1120dee77f09c4
parentaab24019777c5aee222b67e785a88c3e2909c5de (diff)
downloadcpython-a43f34cc2a7a55cea794ecb9bda2eea5c685d1f3.zip
cpython-a43f34cc2a7a55cea794ecb9bda2eea5c685d1f3.tar.gz
cpython-a43f34cc2a7a55cea794ecb9bda2eea5c685d1f3.tar.bz2
fix an UnboundLocalError when the release file is empty #7773
-rwxr-xr-xLib/platform.py8
-rw-r--r--Lib/test/test_platform.py1
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 11 insertions, 2 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 5df1e23..829d5f0 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -263,6 +263,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:
@@ -280,8 +286,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 bd3b234..b51225e 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -198,6 +198,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 f6df409..7c98382 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 f1ab688..3dac0ea 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,9 @@ Core and Builtins
Library
-------
+- Issue #7773: Fix an UnboundLocalError in platform.linux_distribution() when
+ the release file is empty.
+
- Issue #7748: Since unicode values are supported for some metadata options
in Distutils, the DistributionMetadata get_* methods will now return an utf-8
encoded string for them. This ensure that the upload and register commands