MCPcopy Index your code
hub / github.com/python/cpython / _parse_mac

Function _parse_mac

Lib/uuid.py:509–534  ·  view source on GitHub ↗
(word)

Source from the content-addressed store, hash-verified

507
508
509def _parse_mac(word):
510 # Accept 'HH:HH:HH:HH:HH:HH' MAC address (ex: '52:54:00:9d:0e:67'),
511 # but reject IPv6 address (ex: 'fe80::5054:ff:fe9' or '123:2:3:4:5:6:7:8').
512 #
513 # Virtual interfaces, such as those provided by VPNs, do not have a
514 # colon-delimited MAC address as expected, but a 16-byte HWAddr separated
515 # by dashes. These should be ignored in favor of a real MAC address
516 parts = word.split(_MAC_DELIM)
517 if len(parts) != 6:
518 return
519 if _MAC_OMITS_LEADING_ZEROES:
520 # (Only) on AIX the macaddr value given is not prefixed by 0, e.g.
521 # en0 1500 link#2 fa.bc.de.f7.62.4 110854824 0 160133733 0 0
522 # not
523 # en0 1500 link#2 fa.bc.de.f7.62.04 110854824 0 160133733 0 0
524 if not all(1 <= len(part) <= 2 for part in parts):
525 return
526 hexstr = b''.join(part.rjust(2, b'0') for part in parts)
527 else:
528 if not all(len(part) == 2 for part in parts):
529 return
530 hexstr = b''.join(parts)
531 try:
532 return int(hexstr, 16)
533 except ValueError:
534 return
535
536
537def _find_mac_under_heading(command, args, heading):

Callers 1

_find_mac_under_headingFunction · 0.85

Calls 3

splitMethod · 0.45
joinMethod · 0.45
rjustMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…