MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get

Method get

pager_lib/getmac/getmac.py:474–522  ·  view source on GitHub ↗
(self, arg)

Source from the content-addressed store, hash-verified

472 return check_command("arp")
473
474 def get(self, arg): # type: (str) -> Optional[str]
475 if not arg:
476 return None
477
478 # Ensure output from testing command on first call isn't wasted
479 command_output = ""
480
481 # Test which arguments are valid to the command
482 # This will NOT test which regex is valid
483 if not self._args_tested:
484 for pair_to_test in self._args:
485 try:
486 cmd_args = [pair_to_test[0]]
487
488 # if True, then include IP as a command argument
489 if pair_to_test[1]:
490 cmd_args.append(arg)
491
492 command_output = _popen("arp", " ".join(cmd_args))
493 self._good_pair = pair_to_test
494 break
495 except CalledProcessError as ex:
496 if DEBUG:
497 log.debug(
498 "ArpVariousArgs pair test failed for (%s, %s): %s",
499 pair_to_test[0],
500 pair_to_test[1],
501 str(ex),
502 )
503
504 if not self._good_pair:
505 self.unusable = True
506 return None
507 self._args_tested = True
508
509 if not command_output:
510 # if True, then include IP as a command argument
511 cmd_args = [self._good_pair[0]]
512
513 if self._good_pair[1]:
514 cmd_args.append(arg)
515
516 command_output = _popen("arp", " ".join(cmd_args))
517
518 escaped = re.escape(arg)
519 _good_regex = (
520 self._regex_darwin if DARWIN or SOLARIS else self._regex_std
521 ) # type: str
522 return _search(r"\(" + escaped + _good_regex, command_output)
523
524
525class ArpExe(Method):

Callers

nothing calls this directly

Calls 5

_popenFunction · 0.85
_searchFunction · 0.85
appendMethod · 0.80
debugMethod · 0.80
escapeMethod · 0.80

Tested by

no test coverage detected