aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorHenrique <typoon@gmail.com>2019-11-16 17:01:47 -0500
committerHenrique <typoon@gmail.com>2019-11-16 17:01:47 -0500
commit7779eef572e8deeae895ea6d700265e6f9b432c8 (patch)
tree76763b3f6c98629d94376a12887608aef6a8f151 /mitmproxy
parent373cc945c0fb15d0713166019ae0132f07c469e2 (diff)
downloadmitmproxy-7779eef572e8deeae895ea6d700265e6f9b432c8.tar.gz
mitmproxy-7779eef572e8deeae895ea6d700265e6f9b432c8.tar.bz2
mitmproxy-7779eef572e8deeae895ea6d700265e6f9b432c8.zip
Various changes to address PR comments
Made a change to make `CommandManager.execute` the main entry point for executing commands and made `call_strings` into a private method.
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/command.py15
-rw-r--r--mitmproxy/tools/console/consoleaddons.py19
-rw-r--r--mitmproxy/types.py6
3 files changed, 17 insertions, 23 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index 32a9c9c1..609e288c 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -128,10 +128,10 @@ class CommandManager(mitmproxy.types._CommandBase):
self.commands: typing.Dict[str, Command] = {}
self.regex = pyparsing.QuotedString("\"", escChar='\\', unquoteResults=False) |\
- pyparsing.QuotedString("'", escChar='\\', unquoteResults=False) |\
- pyparsing.Combine(pyparsing.Literal('"') + pyparsing.Word(pyparsing.printables + " ") + pyparsing.StringEnd()) |\
- pyparsing.Word(pyparsing.printables) |\
- pyparsing.Word(" \r\n\t")
+ pyparsing.QuotedString("'", escChar='\\', unquoteResults=False) |\
+ pyparsing.Combine(pyparsing.Literal('"') + pyparsing.Word(pyparsing.printables + " ") + pyparsing.StringEnd()) |\
+ pyparsing.Word(pyparsing.printables) |\
+ pyparsing.Word(" \r\n\t")
self.regex = self.regex.leaveWhitespace()
def collect_commands(self, addon):
@@ -220,7 +220,7 @@ class CommandManager(mitmproxy.types._CommandBase):
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:
+ def _call_strings(self, path: str, args: typing.Sequence[str]) -> typing.Any:
"""
Call a command using a list of string arguments. May raise CommandError.
"""
@@ -236,12 +236,13 @@ class CommandManager(mitmproxy.types._CommandBase):
parts, _ = self.parse_partial(cmdstr)
params = []
for p in parts:
- params.append(p.value)
+ if p.value.strip() != '':
+ params.append(p.value)
if len(parts) == 0:
raise exceptions.CommandError("Invalid command: %s" % cmdstr)
- return self.call_strings(params[0], params[1:])
+ return self._call_strings(params[0], params[1:])
def dump(self, out=sys.stdout) -> None:
cmds = list(self.commands.values())
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
index 9f595b42..967c2a35 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -271,7 +271,7 @@ class ConsoleAddon:
command, then invoke another command with all occurrences of {choice}
replaced by the choice the user made.
"""
- choices = ctx.master.commands.call_strings(choicecmd, [])
+ choices = ctx.master.commands.execute(choicecmd)
def callback(opt):
# We're now outside of the call context...
@@ -535,10 +535,8 @@ class ConsoleAddon:
raise exceptions.CommandError("Invalid flowview mode.")
try:
- self.master.commands.call_strings(
- "view.settings.setval",
- ["@focus", "flowview_mode_%s" % idx, mode]
- )
+ cmd = 'view.settings.setval @focus flowview_mode_%s %s' % (idx, mode)
+ self.master.commands.execute(cmd)
except exceptions.CommandError as e:
signals.status_message.send(message=str(e))
@@ -558,14 +556,9 @@ class ConsoleAddon:
if not fv:
raise exceptions.CommandError("Not viewing a flow.")
idx = fv.body.tab_offset
- return self.master.commands.call_strings(
- "view.settings.getval",
- [
- "@focus",
- "flowview_mode_%s" % idx,
- self.master.options.console_default_contentview,
- ]
- )
+
+ cmd = 'view.settings.getval @focus flowview_mode_%s %s' % (idx, self.master.options.console_default_contentview)
+ return self.master.commands.execute(cmd)
@command.command("console.key.contexts")
def key_contexts(self) -> typing.Sequence[str]:
diff --git a/mitmproxy/types.py b/mitmproxy/types.py
index 0634e4d7..b48aef84 100644
--- a/mitmproxy/types.py
+++ b/mitmproxy/types.py
@@ -47,7 +47,7 @@ class Choice:
class _CommandBase:
commands: typing.MutableMapping[str, typing.Any] = {}
- def call_strings(self, path: str, args: typing.Sequence[str]) -> typing.Any:
+ def _call_strings(self, path: str, args: typing.Sequence[str]) -> typing.Any:
raise NotImplementedError
def execute(self, cmd: str) -> typing.Any:
@@ -337,7 +337,7 @@ class _FlowType(_BaseFlowType):
def parse(self, manager: _CommandBase, t: type, s: str) -> flow.Flow:
try:
- flows = manager.call_strings("view.flows.resolve", [s])
+ flows = manager.execute("view.flows.resolve %s" % (s))
except exceptions.CommandError as e:
raise exceptions.TypeError from e
if len(flows) != 1:
@@ -356,7 +356,7 @@ class _FlowsType(_BaseFlowType):
def parse(self, manager: _CommandBase, t: type, s: str) -> typing.Sequence[flow.Flow]:
try:
- return manager.call_strings("view.flows.resolve", [s])
+ return manager.execute("view.flows.resolve %s" % (s))
except exceptions.CommandError as e:
raise exceptions.TypeError from e