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

Delta Between Two Patch Sets: Lib/uuid.py

Issue 11508: Virtual Interfaces cause uuid._find_mac to raise a ValueError under Linux
Left Patch Set: Created 8 years, 10 months ago
Right Patch Set: Created 8 years, 10 months 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_uuid.py ('k') | Misc/ACKS » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 try: 330 try:
331 return int( 331 return int(
332 words[get_index(i)].replace(':', ''), 16) 332 words[get_index(i)].replace(':', ''), 16)
333 # Virtual interfaces, such as those provided by 333 # Virtual interfaces, such as those provided by
334 # VPNs, do not have a colon-delimited MAC address 334 # VPNs, do not have a colon-delimited MAC address
335 # as expected, but a 16-byte HWAddr separated by 335 # as expected, but a 16-byte HWAddr separated by
336 # dashes. These should be ignored in favor of a 336 # dashes. These should be ignored in favor of a
337 # real MAC address 337 # real MAC address
338 except ValueError: 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 339 continue
340 except IOError: 340 except IOError:
341 continue 341 continue
342 return None 342 return None
343 343
344 def _ifconfig_getnode(): 344 def _ifconfig_getnode():
345 """Get the hardware address on Unix by running ifconfig.""" 345 """Get the hardware address on Unix by running ifconfig."""
346 346
347 # 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.
348 for args in ('', '-a', '-av'): 348 for args in ('', '-a', '-av'):
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 from hashlib import sha1 580 from hashlib import sha1
581 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest() 581 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
582 return UUID(bytes=hash[:16], version=5) 582 return UUID(bytes=hash[:16], version=5)
583 583
584 # The following standard UUIDs are for use with uuid3() or uuid5(). 584 # The following standard UUIDs are for use with uuid3() or uuid5().
585 585
586 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8') 586 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
587 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8') 587 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
588 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8') 588 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
589 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8') 589 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
LEFTRIGHT

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