aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-15 15:01:35 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-15 15:01:35 +1200
commit917d51bd22ea75408bcf461b09b6cf78c44e1162 (patch)
tree05f6ed396c29f103aa4da3e731f8f3d366797d97
parent92a5076bd01b71e8ed709901d63de9ee37385c3b (diff)
downloadmitmproxy-917d51bd22ea75408bcf461b09b6cf78c44e1162.tar.gz
mitmproxy-917d51bd22ea75408bcf461b09b6cf78c44e1162.tar.bz2
mitmproxy-917d51bd22ea75408bcf461b09b6cf78c44e1162.zip
Fix HAR extractor
Thanks to @mhils
-rw-r--r--examples/har_extractor.py8
-rw-r--r--test/mitmproxy/test_examples.py7
2 files changed, 9 insertions, 6 deletions
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index 2a69b9af..90412ec0 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -2,7 +2,7 @@
This inline script utilizes harparser.HAR from
https://github.com/JustusW/harparser to generate a HAR log object.
"""
-import mitmproxy
+import mitmproxy.ctx
import six
import sys
import pytz
@@ -221,9 +221,11 @@ def done():
if context.dump_file == '-':
mitmproxy.ctx.log(pprint.pformat(json.loads(json_dump)))
elif context.dump_file.endswith('.zhar'):
- file(context.dump_file, "w").write(compressed_json_dump)
+ with open(context.dump_file, "wb") as f:
+ f.write(compressed_json_dump)
else:
- file(context.dump_file, "w").write(json_dump)
+ with open(context.dump_file, "wb") as f:
+ f.write(json_dump)
mitmproxy.ctx.log(
"HAR log finished with %s bytes (%s bytes compressed)" % (
len(json_dump), len(compressed_json_dump)
diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py
index ef97219c..f8646336 100644
--- a/test/mitmproxy/test_examples.py
+++ b/test/mitmproxy/test_examples.py
@@ -1,5 +1,6 @@
import json
+import six
import sys
import os.path
from mitmproxy.flow import master
@@ -112,7 +113,7 @@ class TestScripts(mastertest.MasterTest):
)
path = os.path.join(tdir, "file")
- m, sc = tscript("har_extractor.py", path)
+ m, sc = tscript("har_extractor.py", six.moves.shlex_quote(path))
f = tutils.tflow(
req=netutils.treq(**times),
resp=netutils.tresp(**times)
@@ -120,6 +121,6 @@ class TestScripts(mastertest.MasterTest):
self.invoke(m, "response", f)
m.addons.remove(sc)
- fp = open(path, "rb")
- test_data = json.load(fp)
+ with open(path, "rb") as f:
+ test_data = json.load(f)
assert len(test_data["log"]["pages"]) == 1