[Python-checkins] r86192 - python/branches/py3k/Lib/uuid.py

brian.curtin python-checkins at python.org
Fri Nov 5 15:48:35 CET 2010


Author: brian.curtin
Date: Fri Nov  5 15:48:35 2010
New Revision: 86192

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


Modified:
   python/branches/py3k/Lib/uuid.py

Modified: python/branches/py3k/Lib/uuid.py
==============================================================================
--- python/branches/py3k/Lib/uuid.py	(original)
+++ python/branches/py3k/Lib/uuid.py	Fri Nov  5 15:48:35 2010
@@ -373,10 +373,13 @@
             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.


More information about the Python-checkins mailing list