mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
Merge pull request #3787 from itaisod/console-command-quotes
Fix console command quotes issues
This commit is contained in:
commit
b020a11c1a
@ -103,7 +103,7 @@ class Command:
|
||||
except TypeError:
|
||||
expected = f'Expected: {str(self.signature.parameters)}'
|
||||
received = f'Received: {str(args)}'
|
||||
raise exceptions.CommandError(f"Command argument mismatch: \n\t{expected}\n\t{received}")
|
||||
raise exceptions.CommandError(f"Command argument mismatch: \n {expected}\n {received}")
|
||||
|
||||
for name, value in bound_arguments.arguments.items():
|
||||
convert_to = self.signature.parameters[name].annotation
|
||||
@ -241,7 +241,7 @@ class CommandManager:
|
||||
raise exceptions.CommandError("Unknown command: %s" % command_name)
|
||||
return self.commands[command_name].func(*args)
|
||||
|
||||
def _call_strings(self, command_name: str, args: typing.Sequence[str]) -> typing.Any:
|
||||
def call_strings(self, command_name: str, args: typing.Sequence[str]) -> typing.Any:
|
||||
"""
|
||||
Call a command using a list of string arguments. May raise CommandError.
|
||||
"""
|
||||
@ -262,7 +262,7 @@ class CommandManager:
|
||||
for part in parts
|
||||
if part.type != mitmproxy.types.Space
|
||||
]
|
||||
return self._call_strings(command_name, args)
|
||||
return self.call_strings(command_name, args)
|
||||
|
||||
def dump(self, out=sys.stdout) -> None:
|
||||
cmds = list(self.commands.values())
|
||||
@ -284,7 +284,7 @@ def parsearg(manager: CommandManager, spec: str, argtype: type) -> typing.Any:
|
||||
try:
|
||||
return t.parse(manager, argtype, spec)
|
||||
except exceptions.TypeError as e:
|
||||
raise exceptions.CommandError from e
|
||||
raise exceptions.CommandError(str(e)) from e
|
||||
|
||||
|
||||
def command(name: typing.Optional[str] = None):
|
||||
|
@ -2,6 +2,7 @@ import typing
|
||||
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy import flow
|
||||
from mitmproxy import ctx
|
||||
|
||||
from mitmproxy.tools.console import overlay
|
||||
from mitmproxy.tools.console import signals
|
||||
@ -15,8 +16,8 @@ class CommandExecutor:
|
||||
if cmd.strip():
|
||||
try:
|
||||
ret = self.master.commands.execute(cmd)
|
||||
except exceptions.CommandError as v:
|
||||
signals.status_message.send(message=str(v))
|
||||
except exceptions.CommandError as e:
|
||||
ctx.log.error(str(e))
|
||||
else:
|
||||
if ret:
|
||||
if type(ret) == typing.Sequence[flow.Flow]:
|
||||
|
@ -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" % 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,11 @@ 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))
|
||||
ctx.log.error(str(e))
|
||||
|
||||
self.master.overlay(
|
||||
overlay.Chooser(self.master, prompt, choices, "", callback)
|
||||
@ -276,12 +275,11 @@ class ConsoleAddon:
|
||||
|
||||
def callback(opt):
|
||||
# We're now outside of the call context...
|
||||
repl = " ".join(command_lexer.quote(x) for x in args)
|
||||
repl = repl.replace("{choice}", opt)
|
||||
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:
|
||||
signals.status_message.send(message=str(e))
|
||||
ctx.log.error(str(e))
|
||||
|
||||
self.master.overlay(
|
||||
overlay.Chooser(self.master, prompt, choices, "", callback)
|
||||
@ -454,8 +452,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 " % flow_part
|
||||
self.master.commands.call_strings(
|
||||
"console.command",
|
||||
["flow.set", "@focus", flow_part]
|
||||
)
|
||||
|
||||
def _grideditor(self):
|
||||
@ -539,10 +538,12 @@ class ConsoleAddon:
|
||||
raise exceptions.CommandError("Invalid flowview mode.")
|
||||
|
||||
try:
|
||||
cmd = 'view.settings.setval @focus flowview_mode_%s %s' % (idx, 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:
|
||||
signals.status_message.send(message=str(e))
|
||||
ctx.log.error(str(e))
|
||||
|
||||
@command.command("console.flowview.mode.options")
|
||||
def flowview_mode_options(self) -> typing.Sequence[str]:
|
||||
@ -561,8 +562,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, 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]:
|
||||
|
@ -134,7 +134,7 @@ class _IntType(_BaseType):
|
||||
try:
|
||||
return int(s)
|
||||
except ValueError as e:
|
||||
raise exceptions.TypeError from e
|
||||
raise exceptions.TypeError(str(e)) from e
|
||||
|
||||
def is_valid(self, manager: "CommandManager", typ: typing.Any, val: typing.Any) -> bool:
|
||||
return isinstance(val, int)
|
||||
@ -328,7 +328,7 @@ class _FlowType(_BaseFlowType):
|
||||
try:
|
||||
flows = manager.execute("view.flows.resolve %s" % (s))
|
||||
except exceptions.CommandError as e:
|
||||
raise exceptions.TypeError from e
|
||||
raise exceptions.TypeError(str(e)) from e
|
||||
if len(flows) != 1:
|
||||
raise exceptions.TypeError(
|
||||
"Command requires one flow, specification matched %s." % len(flows)
|
||||
@ -347,7 +347,7 @@ class _FlowsType(_BaseFlowType):
|
||||
try:
|
||||
return manager.execute("view.flows.resolve %s" % (s))
|
||||
except exceptions.CommandError as e:
|
||||
raise exceptions.TypeError from e
|
||||
raise exceptions.TypeError(str(e)) from e
|
||||
|
||||
def is_valid(self, manager: "CommandManager", typ: typing.Any, val: typing.Any) -> bool:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user