aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/command.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-12-19 11:20:57 +1300
committerAldo Cortesi <aldo@corte.si>2017-12-19 11:22:03 +1300
commit843bad187cfe40c9714c6deb5170d055021a462e (patch)
treeac211f5a1f1f21cf89ae4887a490e470e5fe444b /mitmproxy/command.py
parent6563feaf059f9c829ba6b57d312a0f1dbfb84e33 (diff)
downloadmitmproxy-843bad187cfe40c9714c6deb5170d055021a462e.tar.gz
mitmproxy-843bad187cfe40c9714c6deb5170d055021a462e.tar.bz2
mitmproxy-843bad187cfe40c9714c6deb5170d055021a462e.zip
types: add validation to partial parser
Diffstat (limited to 'mitmproxy/command.py')
-rw-r--r--mitmproxy/command.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index f978b25b..b645798d 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -110,7 +110,11 @@ class Command:
ParseResult = typing.NamedTuple(
"ParseResult",
- [("value", str), ("type", typing.Type)],
+ [
+ ("value", str),
+ ("type", typing.Type),
+ ("valid", bool),
+ ],
)
@@ -161,13 +165,29 @@ class CommandManager(mitmproxy.types._CommandBase):
params.extend(self.commands[parts[i]].paramtypes)
elif params:
typ = params.pop(0)
- # FIXME: Do we need to check that Arg is positional?
if typ == mitmproxy.types.Cmd and params and params[0] == mitmproxy.types.Arg:
if parts[i] in self.commands:
params[:] = self.commands[parts[i]].paramtypes
else:
typ = str
- parse.append(ParseResult(value=parts[i], type=typ))
+
+ to = mitmproxy.types.CommandTypes.get(typ, None)
+ valid = False
+ if to:
+ try:
+ to.parse(self, typ, parts[i])
+ except exceptions.TypeError:
+ valid = False
+ else:
+ valid = True
+
+ parse.append(
+ ParseResult(
+ value=parts[i],
+ type=typ,
+ valid=valid,
+ )
+ )
return parse
def call_args(self, path: str, args: typing.Sequence[str]) -> typing.Any: