aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-06-24 10:18:00 +0800
committerMatthew Shao <me@matshao.com>2017-06-24 10:18:00 +0800
commit18633262201b33fb0c36381fbc65febf21313eb7 (patch)
tree2087e959a6d4821627ff8ae530586552153a9cf3
parentc7ce7f84e6283fa08e87ee5ee35fd6053a2ab615 (diff)
downloadmitmproxy-18633262201b33fb0c36381fbc65febf21313eb7.tar.gz
mitmproxy-18633262201b33fb0c36381fbc65febf21313eb7.tar.bz2
mitmproxy-18633262201b33fb0c36381fbc65febf21313eb7.zip
Minor Update for /options API of mitmweb.
-rw-r--r--mitmproxy/optmanager.py11
-rw-r--r--mitmproxy/utils/typecheck.py4
-rw-r--r--test/mitmproxy/tools/web/test_app.py1
-rw-r--r--test/mitmproxy/utils/test_typecheck.py4
4 files changed, 7 insertions, 13 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 4a455282..ed1310aa 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -401,18 +401,11 @@ def dump_defaults(opts):
if o.choices:
txt += " Valid values are %s." % ", ".join(repr(c) for c in o.choices)
else:
- if o.typespec in (str, int, bool):
- t = o.typespec.__name__
- elif o.typespec == typing.Optional[str]:
- t = "optional str"
- elif o.typespec == typing.Sequence[str]:
- t = "sequence of str"
- else: # pragma: no cover
- raise NotImplementedError
+ t = typecheck.typespec_to_str(o.typespec)
txt += " Type %s." % t
txt = "\n".join(textwrap.wrap(txt))
- s.yaml_set_comment_before_after_key(k, before = "\n" + txt)
+ s.yaml_set_comment_before_after_key(k, before="\n" + txt)
return ruamel.yaml.round_trip_dump(s)
diff --git a/mitmproxy/utils/typecheck.py b/mitmproxy/utils/typecheck.py
index ed58182d..87a0e804 100644
--- a/mitmproxy/utils/typecheck.py
+++ b/mitmproxy/utils/typecheck.py
@@ -104,9 +104,9 @@ def typespec_to_str(typespec: typing.Any) -> str:
if typespec in (str, int, bool):
t = typespec.__name__
elif typespec == typing.Optional[str]:
- t = 'Union'
+ t = 'optional str'
elif typespec == typing.Sequence[str]:
- t = 'Sequence'
+ t = 'sequence of str'
else:
raise NotImplementedError
return t
diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py
index 401f9fe6..e6d563e7 100644
--- a/test/mitmproxy/tools/web/test_app.py
+++ b/test/mitmproxy/tools/web/test_app.py
@@ -261,6 +261,7 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
def test_option_update(self):
assert self.put_json("/options", {"anticache": True}).code == 200
assert self.put_json("/options", {"wtf": True}).code == 400
+ assert self.put_json("/options", {"anticache": "foo"}).code == 400
def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f:
diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py
index 8e4198da..66b1884e 100644
--- a/test/mitmproxy/utils/test_typecheck.py
+++ b/test/mitmproxy/utils/test_typecheck.py
@@ -115,7 +115,7 @@ def test_check_command_type():
def test_typesec_to_str():
assert(typecheck.typespec_to_str(str)) == "str"
- assert(typecheck.typespec_to_str(typing.Sequence[str])) == "Sequence"
- assert(typecheck.typespec_to_str(typing.Optional[str])) == "Union"
+ assert(typecheck.typespec_to_str(typing.Sequence[str])) == "sequence of str"
+ assert(typecheck.typespec_to_str(typing.Optional[str])) == "optional str"
with pytest.raises(NotImplementedError):
typecheck.typespec_to_str(dict)