Exemple #1
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> flow.Flow:
     try:
         flows = manager.execute("view.flows.resolve %s" % (s))
     except exceptions.CommandError as e:
         raise exceptions.TypeError(str(e)) from e
     if len(flows) != 1:
         raise exceptions.TypeError(
             "Command requires one flow, specification matched %s." %
             len(flows))
     return flows[0]
Exemple #2
0
def loads(b: bytes, typ="http") -> typing.Union[HTTPFlow]:
    if typ != 'http':
        raise exceptions.TypeError("Flow types different than HTTP not supported yet!")
    else:
        p = http_pb2.HTTPFlow()
        p.ParseFromString(b)
        return load_http(p)
Exemple #3
0
 def parse(self, manager: _CommandStub, t: type, s: str) -> flow.Flow:
     flows = manager.call_args("view.resolve", [s])
     if len(flows) != 1:
         raise exceptions.TypeError(
             "Command requires one flow, specification matched %s." % len(flows)
         )
     return flows[0]
Exemple #4
0
def dumps(f: flow.Flow) -> bytes:
    if f.type != "http":
        raise exceptions.TypeError(
            "Flow types different than HTTP not supported yet!")
    else:
        p = dump_http(f)
        return p.SerializeToString()
Exemple #5
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> bool:
     if s == "true":
         return True
     elif s == "false":
         return False
     else:
         raise exceptions.TypeError(
             "Booleans are 'true' or 'false', got %s" % s)
Exemple #6
0
 def parse(self, manager: "CommandManager", t: Choice, s: str) -> str:
     if s not in ALL_MARKERS:
         raise exceptions.TypeError("Invalid choice.")
     if s == 'true':
         return ":default:"
     elif s == 'false':
         return ""
     return s
Exemple #7
0
 def parse(self, manager: _CommandBase, t: type, s: str) -> flow.Flow:
     try:
         flows = manager.call_strings("view.flows.resolve", [s])
     except exceptions.CommandError as e:
         raise exceptions.TypeError from e
     if len(flows) != 1:
         raise exceptions.TypeError(
             "Command requires one flow, specification matched %s." % len(flows)
         )
     return flows[0]
Exemple #8
0
 def parse(self, manager: "CommandManager", t: Choice, s: str) -> str:
     opts = manager.execute(t.options_command)
     if s not in opts:
         raise exceptions.TypeError("Invalid choice.")
     return s
Exemple #9
0
 def parse(self, manager: "CommandManager", t: type,
           s: str) -> typing.Any:  # pragma: no cover
     raise exceptions.TypeError("data cannot be passed as argument")
Exemple #10
0
 def completion(self, manager: "CommandManager", t: type,
                s: str) -> typing.Sequence[str]:  # pragma: no cover
     raise exceptions.TypeError("data cannot be passed as argument")
Exemple #11
0
 def parse(self, manager: "CommandManager", t: type,
           s: str) -> typing.Sequence[flow.Flow]:
     try:
         return manager.execute("view.flows.resolve %s" % (s))
     except exceptions.CommandError as e:
         raise exceptions.TypeError(str(e)) from e
Exemple #12
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> str:
     if s not in manager.commands:
         raise exceptions.TypeError("Unknown command: %s" % s)
     return s
Exemple #13
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> int:
     try:
         return int(s)
     except ValueError as e:
         raise exceptions.TypeError(str(e)) from e
Exemple #14
0
 def parse(self, manager: _CommandStub, t: Choice, s: str) -> str:
     opts = manager.call(t.options_command)
     if s not in opts:
         raise exceptions.TypeError("Invalid choice.")
     return s
Exemple #15
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> bytes:
     try:
         return strutils.escaped_str_to_bytes(s)
     except ValueError as e:
         raise exceptions.TypeError(str(e))
Exemple #16
0
 def parse(self, manager: "CommandManager", t: type, s: str) -> str:
     try:
         return self.escape_sequences.sub(self._unescape, s)
     except ValueError as e:
         raise exceptions.TypeError(f"Invalid str: {e}") from e