diff -r c10ea224392d Lib/uuid.py --- a/Lib/uuid.py Sat Dec 14 20:34:33 2013 +0200 +++ b/Lib/uuid.py Sun Dec 15 21:42:39 2013 +0200 @@ -291,35 +291,45 @@ version = property(get_version) +def _is_executable(fn): + import os + return (os.path.exists(fn) and os.access(fn, os.F_OK | os.X_OK) + and not os.path.isdir(fn)) + def _find_mac(command, args, hw_identifiers, get_index): 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) - if not os.path.exists(executable): - continue + if (os.path.exists(executable) and + os.access(executable, os.F_OK | os.X_OK) and + not os.path.isdir(executable)): + break + else: + 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 IOError: - continue - 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 IOError: + return None def _ifconfig_getnode(): """Get the hardware address on Unix by running ifconfig.""" diff -r c10ea224392d Misc/NEWS --- a/Misc/NEWS Sat Dec 14 20:34:33 2013 +0200 +++ b/Misc/NEWS Sun Dec 15 21:42:39 2013 +0200 @@ -23,6 +23,9 @@ Library ------- +- Issue #19855: uuid.get_node() on Unix now correctly works with executables + located not only in /sbin or /usr/sbin directories. + - Issue #19623: Fixed writing to unseekable files in the aifc module. Fixed writing 'ulaw' (lower case) compressed AIFC files.