MCPcopy Index your code
hub / github.com/pyinvoke/invoke / _yield_result

Method _yield_result

invoke/context.py:535–563  ·  view source on GitHub ↗
(self, attname: str, command: str)

Source from the content-addressed store, hash-verified

533 # in Fabric 2; though Fabric could do its own sub-subclass in that case...)
534
535 def _yield_result(self, attname: str, command: str) -> Result:
536 try:
537 obj = getattr(self, attname)
538 # Dicts need to try direct lookup or regex matching
539 if isinstance(obj, dict):
540 try:
541 obj = obj[command]
542 except KeyError:
543 # TODO: could optimize by skipping this if not any regex
544 # objects in keys()?
545 for key, value in obj.items():
546 if hasattr(key, "match") and key.match(command):
547 obj = value
548 break
549 else:
550 # Nope, nothing did match.
551 raise KeyError
552 # Here, the value was either never a dict or has been extracted
553 # from one, so we can assume it's an iterable of Result objects due
554 # to work done by __init__.
555 result: Result = next(obj)
556 # Populate Result's command string with what matched unless
557 # explicitly given
558 if not result.command:
559 result.command = command
560 return result
561 except (AttributeError, IndexError, KeyError, StopIteration):
562 # raise_from(NotImplementedError(command), None)
563 raise NotImplementedError(command)
564
565 def run(self, command: str, *args: Any, **kwargs: Any) -> Result:
566 # TODO: perform more convenience stuff associating args/kwargs with the

Callers 2

runMethod · 0.95
sudoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected