diff options
author | Itai Sadan <itaisod@gmail.com> | 2020-01-18 11:22:54 +0200 |
---|---|---|
committer | Itai Sadan <itaisod@gmail.com> | 2020-01-18 11:22:54 +0200 |
commit | 046de4a39b40c7805136926abe349da760a9753f (patch) | |
tree | db657a0fc114ec7f014f38f906cc19821a6c1a01 /mitmproxy/tools | |
parent | 0afd0c933b7b5a3654cb6a9e27e8e24dbedcd789 (diff) | |
download | mitmproxy-046de4a39b40c7805136926abe349da760a9753f.tar.gz mitmproxy-046de4a39b40c7805136926abe349da760a9753f.tar.bz2 mitmproxy-046de4a39b40c7805136926abe349da760a9753f.zip |
Expose CommandManager.call_strings and use it in consoleaddons.py
This avoids the whole quote/unquote issue.
Diffstat (limited to 'mitmproxy/tools')
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 8e99566d..617ac5e5 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -160,7 +160,7 @@ class ConsoleAddon: fv = self.master.window.current("options") if not fv: raise exceptions.CommandError("Not viewing options.") - self.master.commands.execute("options.reset.one %s" % command_lexer.quote(fv.current_name())) + self.master.commands.call_strings("options.reset.one", [fv.current_name()]) @command.command("console.nav.start") def nav_start(self) -> None: @@ -248,12 +248,13 @@ class ConsoleAddon: def callback(opt): # We're now outside of the call context... - repl = cmd + " " + " ".join(args) - repl = repl.replace("{choice}", opt) + repl = [arg.replace("{choice}", opt) for arg in args] try: - self.master.commands.execute(repl) + self.master.commands.call_strings(cmd, repl) except exceptions.CommandError as e: - signals.status_message.send(message=str(e)) + msg = str(e) + ctx.log.error(msg) + signals.status_message.send(message=msg) self.master.overlay( overlay.Chooser(self.master, prompt, choices, "", callback) @@ -276,9 +277,9 @@ class ConsoleAddon: def callback(opt): # We're now outside of the call context... - repl = " ".join(command_lexer.quote(x.replace("{choice}", opt)) for x in args) + repl = [arg.replace("{choice}", opt) for arg in args] try: - self.master.commands.execute(subcmd + " " + repl) + self.master.commands.call_strings(subcmd, repl) except exceptions.CommandError as e: msg = str(e) ctx.log.error(msg) @@ -455,8 +456,9 @@ class ConsoleAddon: url = edited_url.rstrip(b"\n") flow.request.url = url.decode() elif flow_part in ["method", "status_code", "reason"]: - self.master.commands.execute( - "console.command flow.set @focus %s " % command_lexer.quote(flow_part) + self.master.commands.call_strings( + "console.command", + ["flow.set", "@focus", flow_part] ) def _grideditor(self): @@ -540,8 +542,10 @@ class ConsoleAddon: raise exceptions.CommandError("Invalid flowview mode.") try: - cmd = 'view.settings.setval @focus flowview_mode_%s %s' % (idx, command_lexer.quote(mode)) - self.master.commands.execute(cmd) + self.master.commands.call_strings( + "view.settings.setval", + ["@focus", "flowview_mode_%s" % (idx,), mode] + ) except exceptions.CommandError as e: msg = str(e) ctx.log.error(msg) @@ -564,8 +568,10 @@ class ConsoleAddon: raise exceptions.CommandError("Not viewing a flow.") idx = fv.body.tab_offset - cmd = 'view.settings.getval @focus flowview_mode_%s %s' % (idx, command_lexer.quote(self.master.options.console_default_contentview)) - return self.master.commands.execute(cmd) + return self.master.commands.call_strings( + "view.settings.getval", + ["@focus", "flowview_mode_%s" % (idx,), self.master.options.console_default_contentview] + ) @command.command("console.key.contexts") def key_contexts(self) -> typing.Sequence[str]: |