diff options
| author | Brian Curtin <brian.curtin@gmail.com> | 2010-10-31 01:16:45 (GMT) |
|---|---|---|
| committer | Brian Curtin <brian.curtin@gmail.com> | 2010-10-31 01:16:45 (GMT) |
| commit | c89b734d3223615c6bd062be506ddd1b3079db2d (patch) | |
| tree | 11dc5a757f1687d741a5d85935f28267371b0224 | |
| parent | 55b6251c9dcb86d1d4f837b0b521f65ab4a268fe (diff) | |
| download | cpython-c89b734d3223615c6bd062be506ddd1b3079db2d.zip cpython-c89b734d3223615c6bd062be506ddd1b3079db2d.tar.gz cpython-c89b734d3223615c6bd062be506ddd1b3079db2d.tar.bz2 | |
Merged revisions 86009 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r86009 | brian.curtin | 2010-10-30 20:10:58 -0500 (Sat, 30 Oct 2010) | 2 lines
Fix ResourceWarning for unclosed files (from os.popen)
........
| -rw-r--r-- | Lib/uuid.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py index 259f1bb..4f8d539 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -302,15 +302,15 @@ def _find_mac(command, args, hw_identifiers, get_index): # LC_ALL to get English output, 2>/dev/null to # prevent output on stderr cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) - pipe = os.popen(cmd) + with os.popen(cmd) as pipe: + for line in pipe: + words = line.lower().split() + for i in range(len(words)): + if words[i] in hw_identifiers: + return int( + words[get_index(i)].replace(':', ''), 16) except IOError: continue - - for line in pipe: - words = line.lower().split() - for i in range(len(words)): - if words[i] in hw_identifiers: - return int(words[get_index(i)].replace(':', ''), 16) return None def _ifconfig_getnode(): |
