aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/command.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2019-11-18 22:03:51 +0100
committerMaximilian Hils <git@maximilianhils.com>2019-11-18 22:03:51 +0100
commit74f5fa6a7736f116416c242b159e6b0525e6fe5b (patch)
tree0c90e441aea082e91ee9b864f3c98363e1232927 /mitmproxy/command.py
parent7bf06f8ae04697305731ec89a43ebea6da4376b8 (diff)
downloadmitmproxy-74f5fa6a7736f116416c242b159e6b0525e6fe5b.tar.gz
mitmproxy-74f5fa6a7736f116416c242b159e6b0525e6fe5b.tar.bz2
mitmproxy-74f5fa6a7736f116416c242b159e6b0525e6fe5b.zip
wip
Diffstat (limited to 'mitmproxy/command.py')
-rw-r--r--mitmproxy/command.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index 00238f46..7203fe42 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -3,6 +3,7 @@
"""
import functools
import inspect
+import re
import sys
import textwrap
import types
@@ -284,13 +285,27 @@ class CommandManager:
def unquote(x: str) -> str:
- if x.startswith("'") and x.endswith("'"):
- return x[1:-1]
- if x.startswith('"') and x.endswith('"'):
- return x[1:-1]
+ quoted = (
+ (x.startswith('"') and x.endswith('"'))
+ or
+ (x.startswith("'") and x.endswith("'"))
+ )
+ if quoted:
+ x = x[1:-1]
+ # not sure if this is the right place, but pypyarsing doesn't process escape sequences.
+ x = re.sub(r"\\(.)", r"\g<1>", x)
+ return x
return x
+def quote(val: str) -> str:
+ if not val:
+ return '""'
+ if all(ws not in val for ws in " \r\n\t"):
+ return val
+ return repr(val)
+
+
def parsearg(manager: CommandManager, spec: str, argtype: type) -> typing.Any:
"""
Convert a string to a argument to the appropriate type.
@@ -304,14 +319,14 @@ def parsearg(manager: CommandManager, spec: str, argtype: type) -> typing.Any:
raise exceptions.CommandError from e
-def command(name: typing.Optional[str]):
+def command(name: typing.Optional[str] = None):
def decorator(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
verify_arg_signature(function, args, kwargs)
return function(*args, **kwargs)
- wrapper.__dict__["command_name"] = name or function.__name__
+ wrapper.__dict__["command_name"] = name or function.__name__.replace("_", ".")
return wrapper
return decorator