diff -r c919a82b5a40 Lib/test/test_uuid.py --- a/Lib/test/test_uuid.py Mon Mar 14 10:56:33 2011 -0400 +++ b/Lib/test/test_uuid.py Mon Mar 14 17:21:28 2011 -0400 @@ -360,6 +360,39 @@ self.assertEqual(node1, node2) + def test__find_mac(self): + import os + + original_popen = os.popen + + class MockPopen(object): + data = [ + ('cscotun0 Link encap:UNSPEC HWaddr ' + '00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00'), + 'eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab', + ] + def __init__(self, cmd): + pass + def __enter__(self): + return self + def __exit__(self, exc_type, exc_value, traceback): + pass + def __iter__(self): + return iter(self.data) + + os.popen = MockPopen + + try: + mac = uuid._find_mac( + command='ifconfig', + args='', + hw_identifiers=['hwaddr'], + get_index=lambda x: x + 1, + ) + self.assertEqual(mac, 0x1234567890ab) + finally: + os.popen = original_popen + def test_uuid1(self): # uuid1 requires ctypes. try: diff -r c919a82b5a40 Lib/uuid.py --- a/Lib/uuid.py Mon Mar 14 10:56:33 2011 -0400 +++ b/Lib/uuid.py Mon Mar 14 17:21:28 2011 -0400 @@ -327,8 +327,16 @@ words = line.lower().split() for i in range(len(words)): if words[i] in hw_identifiers: - return int( - words[get_index(i)].replace(':', ''), 16) + try: + return int( + words[get_index(i)].replace(':', ''), 16) + # 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 + except ValueError: + continue except IOError: continue return None diff -r c919a82b5a40 Misc/ACKS --- a/Misc/ACKS Mon Mar 14 10:56:33 2011 -0400 +++ b/Misc/ACKS Mon Mar 14 17:21:28 2011 -0400 @@ -285,6 +285,7 @@ Doug Fort John Fouhy Martin Franklin +Kent Frazier Robin Friedrich Ivan Frohne Jim Fulton