]> granicus.if.org Git - python/commitdiff
Merged revisions 77735 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Mon, 25 Jan 2010 03:35:04 +0000 (03:35 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 25 Jan 2010 03:35:04 +0000 (03:35 +0000)
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
........

Lib/platform.py
Lib/test/test_platform.py
Misc/ACKS
Misc/NEWS

index 90ad93de2bbd33936ec243b8533e38782d5483bb..1852f30d0ea431bead282fd2beb8ebd874a61f64 100755 (executable)
@@ -247,6 +247,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:
@@ -264,8 +270,6 @@ def _parse_release_file(firstline):
         version = l[0]
         if len(l) > 1:
             id = l[1]
-        else:
-            id = ''
     return '', version, id
 
 def _test_parse_release_file():
index 9056d47f14efcb10c623815eeb992e65d6669da2..c3fd32322d61fc2da28d33bf86b60104909eaa32 100644 (file)
@@ -131,6 +131,24 @@ class PlatformTest(unittest.TestCase):
             executable = executable + '.exe'
         res = platform.libc_ver(sys.executable)
 
+    def test_parse_release_file(self):
+
+        for input, output in (
+            # Examples of release file contents:
+            ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')),
+            ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')),
+            ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')),
+            ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')),
+            ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')),
+            ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')),
+            ('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)
+
+
 def test_main():
     test_support.run_unittest(
         PlatformTest
index f1470ba8071e03bffd205d4dc8a513555d562219..9239daa2be686485109df9e0016340aa7acdf75a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -336,6 +336,7 @@ Jeremy Hylton
 Gerhard Häring
 Mihai Ibanescu
 Lars Immisch
+Meador Inge
 Tony Ingraldi
 John Interrante
 Bob Ippolito
index b1a5ff54f005295d2689dc29a1f54db14a3fee1f..14e2be93b4de6490c48e713535733f6e3107e571 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -53,6 +53,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