Merged revisions 86192 via svnmerge from

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.
........
This commit is contained in:
Brian Curtin 2010-11-05 14:52:43 +00:00
parent eae40ba6f7
commit 18716a3a23
1 changed files with 7 additions and 4 deletions

View File

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