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

Function _find_mac_under_heading

Lib/uuid.py:537–570  ·  view source on GitHub ↗

Looks for a MAC address under a heading in a command's output. The first line of words in the output is searched for the given heading. Words at the same word index as the heading in subsequent lines are then examined to see if they look like MAC addresses.

(command, args, heading)

Source from the content-addressed store, hash-verified

535
536
537def _find_mac_under_heading(command, args, heading):
538 """Looks for a MAC address under a heading in a command's output.
539
540 The first line of words in the output is searched for the given
541 heading. Words at the same word index as the heading in subsequent
542 lines are then examined to see if they look like MAC addresses.
543 """
544 stdout = _get_command_stdout(command, args)
545 if stdout is None:
546 return None
547
548 keywords = stdout.readline().rstrip().split()
549 try:
550 column_index = keywords.index(heading)
551 except ValueError:
552 return None
553
554 first_local_mac = None
555 for line in stdout:
556 words = line.rstrip().split()
557 try:
558 word = words[column_index]
559 except IndexError:
560 continue
561
562 mac = _parse_mac(word)
563 if mac is None:
564 continue
565 if _is_universal(mac):
566 return mac
567 if first_local_mac is None:
568 first_local_mac = mac
569
570 return first_local_mac
571
572
573# The following functions call external programs to 'get' a macaddr value to

Callers 1

_netstat_getnodeFunction · 0.85

Calls 7

_get_command_stdoutFunction · 0.85
_parse_macFunction · 0.85
_is_universalFunction · 0.85
splitMethod · 0.45
rstripMethod · 0.45
readlineMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…