diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-06-24 19:54:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 19:54:04 +0200 |
commit | bde64746a91666a3ae8b693fed05bc29824b814c (patch) | |
tree | ff9899f1f61795e1299c76d36937d46b56745677 /mitmproxy/optmanager.py | |
parent | a0abc7b748425e450a51873749d8275265991622 (diff) | |
parent | 18633262201b33fb0c36381fbc65febf21313eb7 (diff) | |
download | mitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.tar.gz mitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.tar.bz2 mitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.zip |
Merge pull request #2395 from MatthewShao/mitmweb-options
[WIP] Add RESTful API for mitmweb option
Diffstat (limited to 'mitmproxy/optmanager.py')
-rw-r--r-- | mitmproxy/optmanager.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index 1680d346..68c2f975 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -401,21 +401,36 @@ 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) +def dump_dicts(opts): + """ + Dumps the options into a list of dict object. + + Return: A list like: [ { name: "anticache", type: "bool", default: false, value: true, help: "help text"} ] + """ + options_list = [] + for k in sorted(opts.keys()): + o = opts._options[k] + t = typecheck.typespec_to_str(o.typespec) + option = { + 'name': k, + 'type': t, + 'default': o.default, + 'value': o.current(), + 'help': o.help, + 'choices': o.choices + } + options_list.append(option) + return options_list + + def parse(text): if not text: return {} |