aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/test/tools/inspect_dumpfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'mitmproxy/test/tools/inspect_dumpfile.py')
-rw-r--r--mitmproxy/test/tools/inspect_dumpfile.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/mitmproxy/test/tools/inspect_dumpfile.py b/mitmproxy/test/tools/inspect_dumpfile.py
new file mode 100644
index 00000000..d15e9e8a
--- /dev/null
+++ b/mitmproxy/test/tools/inspect_dumpfile.py
@@ -0,0 +1,33 @@
+from pprint import pprint
+
+import click
+
+from libmproxy import tnetstring
+
+
+def read_tnetstring(input):
+ # tnetstring throw a ValueError on EOF, which is hard to catch
+ # because they raise ValueErrors for a couple of other reasons.
+ # Check for EOF to avoid this.
+ if not input.read(1):
+ return None
+ else:
+ input.seek(-1, 1)
+ return tnetstring.load(input)
+
+
+@click.command()
+@click.argument("input", type=click.File('rb'))
+def inspect(input):
+ """
+ pretty-print a dumpfile
+ """
+ while True:
+ data = read_tnetstring(input)
+ if not data:
+ break
+ pprint(data)
+
+
+if __name__ == "__main__":
+ inspect()