diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-05-01 09:58:54 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-05-02 08:36:15 +1200 |
commit | 00d790fe84ec860f1de46330cda0e73884e07e2f (patch) | |
tree | ef584911a53eb08564710fa6ca2c1349166a1e98 /mitmproxy/command.py | |
parent | 09c36a8c7c8e5bd690c605e2097063b278489b66 (diff) | |
download | mitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.tar.gz mitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.tar.bz2 mitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.zip |
commands: clarify command call interface, fix web app replay
Diffstat (limited to 'mitmproxy/command.py')
-rw-r--r-- | mitmproxy/command.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py index 77494100..8f075525 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -204,7 +204,15 @@ class CommandManager(mitmproxy.types._CommandBase): return parse, remhelp - def call_args(self, path: str, args: typing.Sequence[str]) -> typing.Any: + def call(self, path: str, *args: typing.Sequence[typing.Any]) -> typing.Any: + """ + Call a command with native arguments. May raise CommandError. + """ + if path not in self.commands: + raise exceptions.CommandError("Unknown command: %s" % path) + return self.commands[path].func(*args) + + def call_strings(self, path: str, args: typing.Sequence[str]) -> typing.Any: """ Call a command using a list of string arguments. May raise CommandError. """ @@ -212,14 +220,14 @@ class CommandManager(mitmproxy.types._CommandBase): raise exceptions.CommandError("Unknown command: %s" % path) return self.commands[path].call(args) - def call(self, cmdstr: str): + def execute(self, cmdstr: str): """ - Call a command using a string. May raise CommandError. + Execute a command string. May raise CommandError. """ parts = list(lexer(cmdstr)) if not len(parts) >= 1: raise exceptions.CommandError("Invalid command: %s" % cmdstr) - return self.call_args(parts[0], parts[1:]) + return self.call_strings(parts[0], parts[1:]) def dump(self, out=sys.stdout) -> None: cmds = list(self.commands.values()) |