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

Function _find_mac_near_keyword

Lib/uuid.py:474–506  ·  view source on GitHub ↗

Searches a command's output for a MAC address near a keyword. Each line of words in the output is case-insensitively searched for any of the given keywords. Upon a match, get_word_index is invoked to pick a word from the line, given the index of the match. For example, lambda i: 0

(command, args, keywords, get_word_index)

Source from the content-addressed store, hash-verified

472
473
474def _find_mac_near_keyword(command, args, keywords, get_word_index):
475 """Searches a command's output for a MAC address near a keyword.
476
477 Each line of words in the output is case-insensitively searched for
478 any of the given keywords. Upon a match, get_word_index is invoked
479 to pick a word from the line, given the index of the match. For
480 example, lambda i: 0 would get the first word on the line, while
481 lambda i: i - 1 would get the word preceding the keyword.
482 """
483 stdout = _get_command_stdout(command, args)
484 if stdout is None:
485 return None
486
487 first_local_mac = None
488 for line in stdout:
489 words = line.lower().rstrip().split()
490 for i in range(len(words)):
491 if words[i] in keywords:
492 try:
493 word = words[get_word_index(i)]
494 mac = int(word.replace(_MAC_DELIM, b''), 16)
495 except (ValueError, IndexError):
496 # Virtual interfaces, such as those provided by
497 # VPNs, do not have a colon-delimited MAC address
498 # as expected, but a 16-byte HWAddr separated by
499 # dashes. These should be ignored in favor of a
500 # real MAC address
501 pass
502 else:
503 if _is_universal(mac):
504 return mac
505 first_local_mac = first_local_mac or mac
506 return first_local_mac or None
507
508
509def _parse_mac(word):

Callers 4

_ifconfig_getnodeFunction · 0.85
_ip_getnodeFunction · 0.85
_arp_getnodeFunction · 0.85
_lanscan_getnodeFunction · 0.85

Calls 6

_get_command_stdoutFunction · 0.85
_is_universalFunction · 0.85
splitMethod · 0.45
rstripMethod · 0.45
lowerMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…