diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/har_extractor.py | 8 | ||||
-rw-r--r-- | examples/stub.py | 9 |
2 files changed, 13 insertions, 4 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/examples/stub.py b/examples/stub.py index 10b34283..e5b4a39a 100644 --- a/examples/stub.py +++ b/examples/stub.py @@ -6,11 +6,18 @@ import mitmproxy def start(): """ - Called once on script startup, before any other events. + Called once on script startup before any other events """ mitmproxy.ctx.log("start") +def configure(options): + """ + Called once on script startup before any other events, and whenever options changes. + """ + mitmproxy.ctx.log("configure") + + def clientconnect(root_layer): """ Called when a client initiates a connection to the proxy. Note that a |