summaryrefslogtreecommitdiffstats
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-12-18 02:14:41 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-12-18 02:14:41 (GMT)
commit0ce3e9d82bc88351979ba4e23655568c339b8acc (patch)
treebf0b0ad58f59eae47d01294c6e19d64f5ce890b4 /Lib/uuid.py
parent74940dc9287553536d73e140f5d1c5be139cf713 (diff)
parent4be1e24933db192b3cf95e102a46673bb3312dc3 (diff)
downloadcpython-0ce3e9d82bc88351979ba4e23655568c339b8acc.zip
cpython-0ce3e9d82bc88351979ba4e23655568c339b8acc.tar.gz
cpython-0ce3e9d82bc88351979ba4e23655568c339b8acc.tar.bz2
Merge: #19855: uuid.get_node now looks on the PATH for executables on unix.
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py55
1 files changed, 28 insertions, 27 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 385fb9b..694a8a9 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -312,34 +312,35 @@ class UUID(object):
return int((self.int >> 76) & 0xf)
def _find_mac(command, args, hw_identifiers, get_index):
- import os
- for dir in ['', '/sbin/', '/usr/sbin']:
- executable = os.path.join(dir, command)
- if not os.path.exists(executable):
- continue
+ import os, shutil
+ executable = shutil.which(command)
+ if executable is None:
+ path = os.pathsep.join(('/sbin', '/usr/sbin'))
+ executable = shutil.which(command, path=path)
+ if executable is None:
+ return None
- try:
- # 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)
- 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:
- try:
- return int(
- words[get_index(i)].replace(':', ''), 16)
- except (ValueError, IndexError):
- # Virtual interfaces, such as those provided by
- # VPNs, do not have a colon-delimited MAC address
- # as expected, but a 16-byte HWAddr separated by
- # dashes. These should be ignored in favor of a
- # real MAC address
- pass
- except OSError:
- continue
- return None
+ try:
+ # LC_MESSAGES to get English output, 2>/dev/null to
+ # prevent output on stderr
+ cmd = 'LC_MESSAGES=C %s %s 2>/dev/null' % (executable, args)
+ 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:
+ try:
+ return int(
+ words[get_index(i)].replace(':', ''), 16)
+ except (ValueError, IndexError):
+ # Virtual interfaces, such as those provided by
+ # VPNs, do not have a colon-delimited MAC address
+ # as expected, but a 16-byte HWAddr separated by
+ # dashes. These should be ignored in favor of a
+ # real MAC address
+ pass
+ except OSError:
+ pass
def _ifconfig_getnode():
"""Get the hardware address on Unix by running ifconfig."""