Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Side by Side Diff: Lib/uuid.py

Issue 11508: Virtual Interfaces cause uuid._find_mac to raise a ValueError under Linux
Patch Set: Created 9 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 r"""UUID objects (universally unique identifiers) according to RFC 4122. 1 r"""UUID objects (universally unique identifiers) according to RFC 4122.
2 2
3 This module provides immutable UUID objects (class UUID) and the functions 3 This module provides immutable UUID objects (class UUID) and the functions
4 uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 4 uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5
5 UUIDs as specified in RFC 4122. 5 UUIDs as specified in RFC 4122.
6 6
7 If all you want is a unique ID, you should probably call uuid1() or uuid4(). 7 If all you want is a unique ID, you should probably call uuid1() or uuid4().
8 Note that uuid1() may compromise privacy since it creates a UUID containing 8 Note that uuid1() may compromise privacy since it creates a UUID containing
9 the computer's network address. uuid4() creates a random UUID. 9 the computer's network address. uuid4() creates a random UUID.
10 10
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 try: 321 try:
322 # LC_ALL to get English output, 2>/dev/null to 322 # LC_ALL to get English output, 2>/dev/null to
323 # prevent output on stderr 323 # prevent output on stderr
324 cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) 324 cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
325 with os.popen(cmd) as pipe: 325 with os.popen(cmd) as pipe:
326 for line in pipe: 326 for line in pipe:
327 words = line.lower().split() 327 words = line.lower().split()
328 for i in range(len(words)): 328 for i in range(len(words)):
329 if words[i] in hw_identifiers: 329 if words[i] in hw_identifiers:
330 return int( 330 try:
331 words[get_index(i)].replace(':', ''), 16) 331 return int(
332 words[get_index(i)].replace(':', ''), 16)
333 # Virtual interfaces, such as those provided by
334 # VPNs, do not have a colon-delimited MAC address
335 # as expected, but a 16-byte HWAddr separated by
336 # dashes. These should be ignored in favor of a
337 # real MAC address
338 except ValueError:
storchaka 2013/10/27 14:09:20 Perhaps we should catch IndexError too.
kfrazier 2013/10/31 03:36:29 It might be appropriate to catch it, but I don't k
storchaka 2013/11/09 21:08:31 If a line ends with 'hwaddr' or 'ether'.
339 continue
332 except IOError: 340 except IOError:
333 continue 341 continue
334 return None 342 return None
335 343
336 def _ifconfig_getnode(): 344 def _ifconfig_getnode():
337 """Get the hardware address on Unix by running ifconfig.""" 345 """Get the hardware address on Unix by running ifconfig."""
338 346
339 # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes. 347 # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes.
340 for args in ('', '-a', '-av'): 348 for args in ('', '-a', '-av'):
341 mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1) 349 mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1)
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 from hashlib import sha1 580 from hashlib import sha1
573 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest() 581 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
574 return UUID(bytes=hash[:16], version=5) 582 return UUID(bytes=hash[:16], version=5)
575 583
576 # The following standard UUIDs are for use with uuid3() or uuid5(). 584 # The following standard UUIDs are for use with uuid3() or uuid5().
577 585
578 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8') 586 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
579 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8') 587 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
580 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8') 588 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
581 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8') 589 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
OLDNEW
« Lib/test/test_uuid.py ('K') | « Lib/test/test_uuid.py ('k') | Misc/ACKS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+