Commit a5a72a86 authored by R David Murray's avatar R David Murray

#19855: uuid.get_node now looks on the PATH for executables on unix.

Patch by Serhiy Storchaka.
parent e388e623
...@@ -293,15 +293,21 @@ class UUID(object): ...@@ -293,15 +293,21 @@ class UUID(object):
def _find_mac(command, args, hw_identifiers, get_index): def _find_mac(command, args, hw_identifiers, get_index):
import os import os
for dir in ['', '/sbin/', '/usr/sbin']: path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, command) executable = os.path.join(dir, command)
if not os.path.exists(executable): if (os.path.exists(executable) and
continue os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
return None
try: try:
# LC_ALL to get English output, 2>/dev/null to # LC_MESSAGES to get English output, 2>/dev/null to
# prevent output on stderr # prevent output on stderr
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) cmd = 'LC_MESSAGES=C %s %s 2>/dev/null' % (executable, args)
with os.popen(cmd) as pipe: with os.popen(cmd) as pipe:
for line in pipe: for line in pipe:
words = line.lower().split() words = line.lower().split()
...@@ -318,8 +324,7 @@ def _find_mac(command, args, hw_identifiers, get_index): ...@@ -318,8 +324,7 @@ def _find_mac(command, args, hw_identifiers, get_index):
# real MAC address # real MAC address
pass pass
except IOError: except IOError:
continue pass
return None
def _ifconfig_getnode(): def _ifconfig_getnode():
"""Get the hardware address on Unix by running ifconfig.""" """Get the hardware address on Unix by running ifconfig."""
......
...@@ -27,6 +27,10 @@ Core and Builtins ...@@ -27,6 +27,10 @@ Core and Builtins
Library 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. - Issue #20007: HTTPResponse.read(0) no more prematurely closes connection.
Original patch by Simon Sapin. Original patch by Simon Sapin.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment