diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-02-17 10:18:38 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-02-17 10:18:38 +1300 |
commit | f0f1fb4b556b048c5a8f93541bea751981136aba (patch) | |
tree | 453fab260c9066135d2a4d61909f886a1aa00ec6 /libmproxy/dump.py | |
parent | 7758385ac15e02d06c89db684fd75846a130c318 (diff) | |
download | mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.tar.gz mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.tar.bz2 mitmproxy-f0f1fb4b556b048c5a8f93541bea751981136aba.zip |
Add file writing to mitmdump.
Diffstat (limited to 'libmproxy/dump.py')
-rw-r--r-- | libmproxy/dump.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/libmproxy/dump.py b/libmproxy/dump.py index 76bf3ae2..e30c2422 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -1,6 +1,9 @@ -import sys +import sys, os import flow +class DumpError(Exception): pass + + class Options(object): __slots__ = [ "verbosity", @@ -9,6 +12,9 @@ class Options(object): def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) + for i in self.__slots__: + if not hasattr(self, i): + setattr(self, i, None) class DumpMaster(flow.FlowMaster): @@ -17,6 +23,14 @@ class DumpMaster(flow.FlowMaster): self.outfile = outfile self.o = options + if options.wfile: + path = os.path.expanduser(options.wfile) + try: + f = file(path, "wb") + self.fwriter = flow.FlowWriter(f) + except IOError, v: + raise DumpError(v.strerror) + def handle_clientconnection(self, r): flow.FlowMaster.handle_clientconnection(self, r) r.ack() @@ -56,6 +70,9 @@ class DumpMaster(flow.FlowMaster): msg.ack() self.state.delete_flow(f) + if self.o.wfile: + self.fwriter.add(f) + # begin nocover def run(self): |