diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-11-05 14:48:35 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-11-05 14:48:35 (GMT) |
commit | 69cd87b5fa284a6ec386d42aa3bcf8e0174ca35b (patch) | |
tree | 6a115b7a45194386df95e786c6853a01a5a91ef0 /Lib/uuid.py | |
parent | a277ec4ad97e68ab4136955dfb9962bc387a3044 (diff) | |
download | cpython-69cd87b5fa284a6ec386d42aa3bcf8e0174ca35b.zip cpython-69cd87b5fa284a6ec386d42aa3bcf8e0174ca35b.tar.gz cpython-69cd87b5fa284a6ec386d42aa3bcf8e0174ca35b.tar.bz2 |
Shift the pipe-using code into an else block, then close the pipe
in finally. Removes two ResourceWarnings.
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r-- | Lib/uuid.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py index df51464..5684ad7 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -373,10 +373,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. |