aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/flow.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-02-16 14:33:04 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-02-16 14:33:04 +1300
commit0c6f846861f537e5ebf61a1c3ac536ca04fa5892 (patch)
tree5fbf3d92b4134ec32b3f0ea73e7d71333fa80e3d /libmproxy/flow.py
parent5692c7359c7c468e1ee35f9bdd3b7b92fd67592c (diff)
downloadmitmproxy-0c6f846861f537e5ebf61a1c3ac536ca04fa5892.tar.gz
mitmproxy-0c6f846861f537e5ebf61a1c3ac536ca04fa5892.tar.bz2
mitmproxy-0c6f846861f537e5ebf61a1c3ac536ca04fa5892.zip
First draft of the new serialization mechanism.
Diffstat (limited to 'libmproxy/flow.py')
-rw-r--r--libmproxy/flow.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index 9596d416..6031a009 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -2,9 +2,9 @@
This module provides more sophisticated flow tracking. These match requests
with their responses, and provide filtering and interception facilities.
"""
-import subprocess, base64, sys
+import subprocess, base64, sys, json
from contrib import bson
-import proxy, threading
+import proxy, threading, netstring
class RunException(Exception):
def __init__(self, msg, returncode, errout):
@@ -302,3 +302,30 @@ class State:
rt = ReplayThread(f, masterq)
rt.start()
#end nocover
+
+
+
+class FlowWriter:
+ def __init__(self, fo):
+ self.fo = fo
+ self.ns = netstring.FileEncoder(fo)
+
+ def add(self, flow):
+ d = flow.get_state()
+ s = json.dumps(d)
+ self.ns.write(s)
+
+
+class FlowReader:
+ def __init__(self, fo):
+ self.fo = fo
+ self.ns = netstring.decode_file(fo)
+
+ def stream(self):
+ """
+ Yields Flow objects from the dump.
+ """
+ for i in self.ns:
+ data = json.loads(i)
+ yield Flow.from_state(data)
+