aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-12-08 10:18:50 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-12-08 10:21:06 +1300
commitb2695dbc6a170cb21771b001059efa7dc5201722 (patch)
tree0552610c1e33707bca30630dff58a9784791c4c8
parenta617e3b5f717b95d1ffc8c87dd70712e36445be9 (diff)
downloadmitmproxy-b2695dbc6a170cb21771b001059efa7dc5201722.tar.gz
mitmproxy-b2695dbc6a170cb21771b001059efa7dc5201722.tar.bz2
mitmproxy-b2695dbc6a170cb21771b001059efa7dc5201722.zip
Minor tweaks
-rw-r--r--mitmproxy/optmanager.py13
-rw-r--r--mitmproxy/tools/cmdline.py1
-rw-r--r--test/mitmproxy/addons/test_dumper.py24
-rw-r--r--test/mitmproxy/test_optmanager.py2
4 files changed, 21 insertions, 19 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 081836ce..e497c3b6 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -180,12 +180,13 @@ class OptManager(metaclass=_DefaultsMeta):
Save to path. If the destination file exists, modify it in-place.
"""
if os.path.exists(path) and os.path.isfile(path):
- data = open(path, "r").read()
+ with open(path, "r") as f:
+ data = f.read()
else:
data = ""
data = self.serialize(data, defaults)
- fp = open(path, "w")
- fp.write(data)
+ with open(path, "w") as f:
+ f.write(data)
def serialize(self, text, defaults=False):
"""
@@ -228,8 +229,7 @@ class OptManager(metaclass=_DefaultsMeta):
this object. May raise OptionsError if the config file is invalid.
"""
data = self._load(text)
- for k, v in data.items():
- setattr(self, k, v)
+ self.update(**data)
def load_paths(self, *paths):
"""
@@ -240,7 +240,8 @@ class OptManager(metaclass=_DefaultsMeta):
for p in paths:
p = os.path.expanduser(p)
if os.path.exists(p) and os.path.isfile(p):
- txt = open(p, "r").read()
+ with open(p, "r") as f:
+ txt = f.read()
self.load(txt)
def __repr__(self):
diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py
index 1cdde727..925491d7 100644
--- a/mitmproxy/tools/cmdline.py
+++ b/mitmproxy/tools/cmdline.py
@@ -513,6 +513,7 @@ def proxy_ssl_options(parser):
'as the first entry. Can be passed multiple times.')
group.add_argument(
"--ciphers-client", action="store",
+ type=str, dest="ciphers_client",
help="Set supported ciphers for client connections. (OpenSSL Syntax)"
)
group.add_argument(
diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py
index f87df329..760efa08 100644
--- a/test/mitmproxy/addons/test_dumper.py
+++ b/test/mitmproxy/addons/test_dumper.py
@@ -31,37 +31,37 @@ def test_simple():
sio = io.StringIO()
d = dumper.Dumper(sio)
with taddons.context(options=dump.Options()) as ctx:
- ctx.configure(d, flow_detail = 0)
+ ctx.configure(d, flow_detail=0)
d.response(tflow.tflow(resp=True))
assert not sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 1)
+ ctx.configure(d, flow_detail=1)
d.response(tflow.tflow(resp=True))
assert sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 1)
+ ctx.configure(d, flow_detail=1)
d.error(tflow.tflow(err=True))
assert sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
d.response(tflow.tflow(resp=True))
assert sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
d.response(tflow.tflow(resp=True))
assert "<<" in sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
d.response(tflow.tflow(err=True))
assert "<<" in sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
flow = tflow.tflow()
flow.request = tutils.treq()
flow.request.stickycookie = True
@@ -74,7 +74,7 @@ def test_simple():
assert sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
flow = tflow.tflow(resp=tutils.tresp(content=b"{"))
flow.response.headers["content-type"] = "application/json"
flow.response.status_code = 400
@@ -82,7 +82,7 @@ def test_simple():
assert sio.getvalue()
sio.truncate(0)
- ctx.configure(d, flow_detail = 4)
+ ctx.configure(d, flow_detail=4)
flow = tflow.tflow()
flow.request.content = None
flow.response = http.HTTPResponse.wrap(tutils.tresp())
@@ -100,7 +100,7 @@ def test_echo_body():
sio = io.StringIO()
d = dumper.Dumper(sio)
with taddons.context(options=dump.Options()) as ctx:
- ctx.configure(d, flow_detail = 3)
+ ctx.configure(d, flow_detail=3)
d._echo_message(f.response)
t = sio.getvalue()
assert "cut off" in t
@@ -110,7 +110,7 @@ def test_echo_request_line():
sio = io.StringIO()
d = dumper.Dumper(sio)
with taddons.context(options=dump.Options()) as ctx:
- ctx.configure(d, flow_detail = 3, showhost = True)
+ ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
f.request.is_replay = True
d._echo_request_line(f)
@@ -146,7 +146,7 @@ def test_tcp():
sio = io.StringIO()
d = dumper.Dumper(sio)
with taddons.context(options=dump.Options()) as ctx:
- ctx.configure(d, flow_detail = 3, showhost = True)
+ ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.ttcpflow(client_conn=True, server_conn=True)
d.tcp_message(f)
assert "it's me" in sio.getvalue()
diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py
index 0c98daea..c6eb2534 100644
--- a/test/mitmproxy/test_optmanager.py
+++ b/test/mitmproxy/test_optmanager.py
@@ -15,7 +15,7 @@ class TO(optmanager.OptManager):
class TD(optmanager.OptManager):
- def __init__(self, one="done", two="dtwo", three="error"):
+ def __init__(self, *, one="done", two="dtwo", three="error"):
self.one = one
self.two = two
self.three = three