aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/command.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-12-15 11:42:26 +1300
committerAldo Cortesi <aldo@nullcube.com>2017-12-15 13:37:44 +1300
commit2cfe45428ae1df16d0f7a5cbb9a541a441b7413d (patch)
tree3116083e3deb49a9e79a2b5c8579db72e858c133 /mitmproxy/command.py
parent1c097813c16d530631562727cd9c2db0fae8755d (diff)
downloadmitmproxy-2cfe45428ae1df16d0f7a5cbb9a541a441b7413d.tar.gz
mitmproxy-2cfe45428ae1df16d0f7a5cbb9a541a441b7413d.tar.bz2
mitmproxy-2cfe45428ae1df16d0f7a5cbb9a541a441b7413d.zip
command: add command.Arg type
This type represents an argument to a command passed to another command. This improves help text, and will be used in the partial parser to expand subcommand types.
Diffstat (limited to 'mitmproxy/command.py')
-rw-r--r--mitmproxy/command.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index 7374a19a..087f7770 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -17,7 +17,8 @@ from mitmproxy import flow
def lexer(s):
# mypy mis-identifies shlex.shlex as abstract
- lex = shlex.shlex(s, punctuation_chars=True) # type: ignore
+ lex = shlex.shlex(s) # type: ignore
+ lex.wordchars += "."
lex.whitespace_split = True
lex.commenters = ''
return lex
@@ -36,6 +37,10 @@ class Cmd(str):
pass
+class Arg(str):
+ pass
+
+
def typename(t: type, ret: bool) -> str:
"""
Translates a type to an explanatory string. If ret is True, we're
@@ -157,7 +162,7 @@ class CommandManager:
Parse a possibly partial command. Return a sequence of (part, type) tuples.
"""
buf = io.StringIO(cmdstr)
- parts: typing.List[str] = []
+ parts = [] # type: typing.List[str]
lex = lexer(buf)
while 1:
remainder = cmdstr[buf.tell():]
@@ -174,8 +179,8 @@ class CommandManager:
elif cmdstr.endswith(" "):
parts.append("")
- parse: typing.List[ParseResult] = []
- params: typing.List[type] = []
+ parse = [] # type: typing.List[ParseResult]
+ params = [] # type: typing.List[type]
for i in range(len(parts)):
if i == 0:
params[:] = [Cmd]