From c048ae1d5b652ad4778917e624ace217e1ecfd91 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 7 Jul 2016 18:37:33 -0700 Subject: remove context from all scripts --- examples/har_extractor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'examples/har_extractor.py') diff --git a/examples/har_extractor.py b/examples/har_extractor.py index a5c05519..b136bd40 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -54,7 +54,13 @@ class _HARLog(HAR.log): return self.__page_list__ -def start(context): +class Context(object): + pass + +context = Context() + + +def start(): """ On start we create a HARLog instance. You will have to adapt this to suit your actual needs of HAR generation. As it will probably be @@ -79,7 +85,7 @@ def start(context): context.seen_server = set() -def response(context, flow): +def response(flow): """ Called when a server response has been received. At the time of this message both a request and a response are present and completely done. @@ -201,7 +207,7 @@ def response(context, flow): context.HARLog.add(entry) -def done(context): +def done(): """ Called once on script shutdown, after any other events. """ -- cgit v1.2.3 From 7c67faa8da39f428d1860bccae806137943b66a6 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 7 Jul 2016 23:50:55 -0700 Subject: remove script contexts --- examples/har_extractor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'examples/har_extractor.py') diff --git a/examples/har_extractor.py b/examples/har_extractor.py index b136bd40..208a2fa8 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -2,6 +2,7 @@ This inline script utilizes harparser.HAR from https://github.com/JustusW/harparser to generate a HAR log object. """ +import mitmproxy import six import sys import pytz @@ -218,17 +219,17 @@ def done(): compressed_json_dump = context.HARLog.compress() if context.dump_file == '-': - context.log(pprint.pformat(json.loads(json_dump))) + mitmproxy.log(pprint.pformat(json.loads(json_dump))) elif context.dump_file.endswith('.zhar'): file(context.dump_file, "w").write(compressed_json_dump) else: file(context.dump_file, "w").write(json_dump) - context.log( + mitmproxy.log( "HAR log finished with %s bytes (%s bytes compressed)" % ( len(json_dump), len(compressed_json_dump) ) ) - context.log( + mitmproxy.log( "Compression rate is %s%%" % str( 100. * len(compressed_json_dump) / len(json_dump) ) -- cgit v1.2.3 From 5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 8 Jul 2016 19:57:57 -0700 Subject: move script context to mitmproxy.ctx --- examples/har_extractor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/har_extractor.py') diff --git a/examples/har_extractor.py b/examples/har_extractor.py index 208a2fa8..2a69b9af 100644 --- a/examples/har_extractor.py +++ b/examples/har_extractor.py @@ -219,17 +219,17 @@ def done(): compressed_json_dump = context.HARLog.compress() if context.dump_file == '-': - mitmproxy.log(pprint.pformat(json.loads(json_dump))) + mitmproxy.ctx.log(pprint.pformat(json.loads(json_dump))) elif context.dump_file.endswith('.zhar'): file(context.dump_file, "w").write(compressed_json_dump) else: file(context.dump_file, "w").write(json_dump) - mitmproxy.log( + mitmproxy.ctx.log( "HAR log finished with %s bytes (%s bytes compressed)" % ( len(json_dump), len(compressed_json_dump) ) ) - mitmproxy.log( + mitmproxy.ctx.log( "Compression rate is %s%%" % str( 100. * len(compressed_json_dump) / len(json_dump) ) -- cgit v1.2.3