[Python-checkins] cpython (merge 3.3 -> default): Merge: #19855: uuid.get_node now looks on the PATH for executables on unix.
r.david.murray
python-checkins at python.org
Wed Dec 18 03:33:12 CET 2013
http://hg.python.org/cpython/rev/2e856fcb9084
changeset: 88037:2e856fcb9084
parent: 88035:26d92a21f6cf
parent: 88036:b0fbaed45956
user: R David Murray <rdmurray at bitdance.com>
date: Tue Dec 17 21:14:41 2013 -0500
summary:
Merge: #19855: uuid.get_node now looks on the PATH for executables on unix.
files:
Lib/uuid.py | 55 ++++++++++++++++++++--------------------
Misc/NEWS | 4 ++
2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/Lib/uuid.py b/Lib/uuid.py
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -312,34 +312,35 @@
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."""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,10 @@
Library
-------
+- Issue #19855: uuid.getnode() on Unix now looks on the PATH for the
+ executables used to find the mac address, with /sbin and /usr/sbin as
+ fallbacks.
+
- Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list