diff options
| -rw-r--r-- | examples/har_extractor.py | 8 | ||||
| -rw-r--r-- | test/mitmproxy/test_examples.py | 7 | 
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 | 
