diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-02-16 22:10:24 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-02-16 22:10:24 +1300 |
commit | 0dd1aa7cc7b15b3bedc3dc4da2fc15d5b726c10a (patch) | |
tree | cfc85cbeb31ac4f354a621c871b1f2b580ac79e5 /libmproxy/dump.py | |
parent | 692556cf20c3feca53b336415cdf8a87a6740651 (diff) | |
download | mitmproxy-0dd1aa7cc7b15b3bedc3dc4da2fc15d5b726c10a.tar.gz mitmproxy-0dd1aa7cc7b15b3bedc3dc4da2fc15d5b726c10a.tar.bz2 mitmproxy-0dd1aa7cc7b15b3bedc3dc4da2fc15d5b726c10a.zip |
Initial port of mitmdump to Flows.
Diffstat (limited to 'libmproxy/dump.py')
-rw-r--r-- | libmproxy/dump.py | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 1fe1c095..7eff4992 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,40 +1,52 @@ import sys -import controller +import flow -#begin nocover -class DumpMaster(controller.Master): - """ - A simple master that just dumps to screen. - """ - def __init__(self, server, verbosity): - self.verbosity = verbosity - controller.Master.__init__(self, server) +class DumpMaster(flow.FlowMaster): + def __init__(self, server, verbosity, outfile=sys.stderr): + self.verbosity, self.outfile = verbosity, outfile + flow.FlowMaster.__init__(self, server, flow.State()) - def run(self): - try: - return controller.Master.run(self) - except KeyboardInterrupt: - self.shutdown() + def handle_clientconnection(self, r): + flow.FlowMaster.handle_clientconnection(self, r) + r.ack() + + def handle_error(self, r): + flow.FlowMaster.handle_error(self, r) + r.ack() + + def handle_request(self, r): + flow.FlowMaster.handle_request(self, r) + r.ack() def handle_response(self, msg): + f = flow.FlowMaster.handle_response(self, msg) if 0 < self.verbosity < 3: - print >> sys.stderr, ">>", - print >> sys.stderr, msg.request.short() + print >> self.outfile, ">>", + print >> self.outfile, msg.request.short() if self.verbosity == 1: - print >> sys.stderr, "<<", - print >> sys.stderr, msg.short() + print >> self.outfile, "<<", + print >> self.outfile, msg.short() elif self.verbosity == 2: - print >> sys.stderr, "<<" + print >> self.outfile, "<<" for i in msg.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, "<<" elif self.verbosity == 3: - print >> sys.stderr, ">>" + print >> self.outfile, ">>" for i in msg.request.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, ">>" - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, ">>" + print >> self.outfile, "<<" for i in msg.assemble().splitlines(): - print >> sys.stderr, "\t", i - print >> sys.stderr, "<<" + print >> self.outfile, "\t", i + print >> self.outfile, "<<" msg.ack() + + +# begin nocover + def run(self): + try: + return flow.FlowMaster.run(self) + except KeyboardInterrupt: + self.shutdown() + |