summaryrefslogtreecommitdiffstats
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-10-31 01:10:58 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-10-31 01:10:58 (GMT)
commitbf0757137f01f570826ee016cb6a77b4ccc57e69 (patch)
tree7c5ad7301d057174094bd9ad97f914613dd83be5 /Lib/uuid.py
parenta9615d14de54d0595466b792a694d25b72f4e48b (diff)
downloadcpython-bf0757137f01f570826ee016cb6a77b4ccc57e69.zip
cpython-bf0757137f01f570826ee016cb6a77b4ccc57e69.tar.gz
cpython-bf0757137f01f570826ee016cb6a77b4ccc57e69.tar.bz2
Fix ResourceWarning for unclosed files (from os.popen)
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 6e687943..df51464 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -322,15 +322,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():