]> granicus.if.org Git - python/commitdiff
Merged revisions 86192 via svnmerge from
authorBrian Curtin <brian.curtin@gmail.com>
Fri, 5 Nov 2010 14:56:16 +0000 (14:56 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Fri, 5 Nov 2010 14:56:16 +0000 (14:56 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86192 | brian.curtin | 2010-11-05 09:48:35 -0500 (Fri, 05 Nov 2010) | 3 lines

  Shift the pipe-using code into an else block, then close the pipe
  in finally. Removes two ResourceWarnings.
........

Lib/uuid.py

index 4f8d539a90fe9558a268f822985d343e52859041..fdd0c5cbec08c26c2e86aaad4460a44badefb661 100644 (file)
@@ -353,10 +353,13 @@ def _ipconfig_getnode():
             pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
         except IOError:
             continue
-        for line in pipe:
-            value = line.split(':')[-1].strip().lower()
-            if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
-                return int(value.replace('-', ''), 16)
+        else:
+            for line in pipe:
+                value = line.split(':')[-1].strip().lower()
+                if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
+                    return int(value.replace('-', ''), 16)
+        finally:
+            pipe.close()
 
 def _netbios_getnode():
     """Get the hardware address on Windows using NetBIOS calls.