aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/optmanager.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-09 13:52:58 +1300
committerAldo Cortesi <aldo@corte.si>2017-03-14 08:32:19 +1300
commit0c6663d0d5335e666598807c2e5d8f105803eac0 (patch)
treee6782b2e102aca959ad6e30739f816dbad89cbb9 /mitmproxy/optmanager.py
parentee65894d40f5a9f73125a8d3e73ba50540939e5b (diff)
downloadmitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.gz
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.tar.bz2
mitmproxy-0c6663d0d5335e666598807c2e5d8f105803eac0.zip
Enable custom options for addons
- Add an options parameter to the start() event. This is to be used by addons on startup to add custom options. - Add a running() event that is called once the proxy is up and running. - With the new paradigm we can't log during master __init__, so add a tiny termstatus addon to print proxy status to terminal once we're running.
Diffstat (limited to 'mitmproxy/optmanager.py')
-rw-r--r--mitmproxy/optmanager.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 9553bd32..698c9bb8 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -324,7 +324,15 @@ class OptManager:
options=options
)
- def set(self, spec):
+ def set(self, *spec):
+ vals = {}
+ for i in spec:
+ vals.update(self._setspec(i))
+ self.update(**vals)
+
+ def _setspec(self, spec):
+ d = {}
+
parts = spec.split("=", maxsplit=1)
if len(parts) == 1:
optname, optval = parts[0], None
@@ -333,14 +341,14 @@ class OptManager:
o = self._options[optname]
if o.typespec in (str, typing.Optional[str]):
- setattr(self, optname, optval)
+ d[optname] = optval
elif o.typespec in (int, typing.Optional[int]):
if optval:
try:
optval = int(optval)
except ValueError:
raise exceptions.OptionsError("Not an integer: %s" % optval)
- setattr(self, optname, optval)
+ d[optname] = optval
elif o.typespec == bool:
if not optval or optval == "true":
v = True
@@ -350,18 +358,15 @@ class OptManager:
raise exceptions.OptionsError(
"Boolean must be \"true\", \"false\", or have the value " "omitted (a synonym for \"true\")."
)
- setattr(self, optname, v)
+ d[optname] = v
elif o.typespec == typing.Sequence[str]:
if not optval:
- setattr(self, optname, [])
+ d[optname] = []
else:
- setattr(
- self,
- optname,
- getattr(self, optname) + [optval]
- )
+ d[optname] = getattr(self, optname) + [optval]
else: # pragma: no cover
raise NotImplementedError("Unsupported option type: %s", o.typespec)
+ return d
def make_parser(self, parser, optname, metavar=None, short=None):
o = self._options[optname]