From 4ca78604af2a8ddb596e2f4e95090dabc8495bfe Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 20 Mar 2017 12:50:09 +1300 Subject: [PATCH] Factor out an io module Include tnetstring - we've made enough changes that this no longer belongs in contrib. --- mitmproxy/io/__init__.py | 7 +++++++ mitmproxy/{io_compat.py => io/compat.py} | 0 mitmproxy/{ => io}/io.py | 6 +++--- mitmproxy/{contrib => io}/tnetstring.py | 0 test/mitmproxy/{test_io_compat.py => io/test_compat.py} | 0 test/mitmproxy/{ => io}/test_io.py | 0 test/mitmproxy/{contrib => io}/test_tnetstring.py | 2 +- test/mitmproxy/test_flow.py | 2 +- test/mitmproxy/test_websocket.py | 2 +- 9 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 mitmproxy/io/__init__.py rename mitmproxy/{io_compat.py => io/compat.py} (100%) rename mitmproxy/{ => io}/io.py (94%) rename mitmproxy/{contrib => io}/tnetstring.py (100%) rename test/mitmproxy/{test_io_compat.py => io/test_compat.py} (100%) rename test/mitmproxy/{ => io}/test_io.py (100%) rename test/mitmproxy/{contrib => io}/test_tnetstring.py (99%) diff --git a/mitmproxy/io/__init__.py b/mitmproxy/io/__init__.py new file mode 100644 index 000000000..a82f729fd --- /dev/null +++ b/mitmproxy/io/__init__.py @@ -0,0 +1,7 @@ + +from .io import FlowWriter, FlowReader, FilteredFlowWriter, read_flows_from_paths + + +__all__ = [ + "FlowWriter", "FlowReader", "FilteredFlowWriter", "read_flows_from_paths" +] \ No newline at end of file diff --git a/mitmproxy/io_compat.py b/mitmproxy/io/compat.py similarity index 100% rename from mitmproxy/io_compat.py rename to mitmproxy/io/compat.py diff --git a/mitmproxy/io.py b/mitmproxy/io/io.py similarity index 94% rename from mitmproxy/io.py rename to mitmproxy/io/io.py index 0f6c3f5c8..50e26f49e 100644 --- a/mitmproxy/io.py +++ b/mitmproxy/io/io.py @@ -7,9 +7,9 @@ from mitmproxy import flowfilter from mitmproxy import http from mitmproxy import tcp from mitmproxy import websocket -from mitmproxy.contrib import tnetstring -from mitmproxy import io_compat +from mitmproxy.io import compat +from mitmproxy.io import tnetstring FLOW_TYPES = dict( http=http.HTTPFlow, @@ -43,7 +43,7 @@ class FlowReader: tnetstring.load(self.fo), ) try: - mdata = io_compat.migrate_flow(loaded) + mdata = compat.migrate_flow(loaded) except ValueError as e: raise exceptions.FlowReadException(str(e)) if mdata["type"] not in FLOW_TYPES: diff --git a/mitmproxy/contrib/tnetstring.py b/mitmproxy/io/tnetstring.py similarity index 100% rename from mitmproxy/contrib/tnetstring.py rename to mitmproxy/io/tnetstring.py diff --git a/test/mitmproxy/test_io_compat.py b/test/mitmproxy/io/test_compat.py similarity index 100% rename from test/mitmproxy/test_io_compat.py rename to test/mitmproxy/io/test_compat.py diff --git a/test/mitmproxy/test_io.py b/test/mitmproxy/io/test_io.py similarity index 100% rename from test/mitmproxy/test_io.py rename to test/mitmproxy/io/test_io.py diff --git a/test/mitmproxy/contrib/test_tnetstring.py b/test/mitmproxy/io/test_tnetstring.py similarity index 99% rename from test/mitmproxy/contrib/test_tnetstring.py rename to test/mitmproxy/io/test_tnetstring.py index 05c4a7c93..f7141de04 100644 --- a/test/mitmproxy/contrib/test_tnetstring.py +++ b/test/mitmproxy/io/test_tnetstring.py @@ -4,7 +4,7 @@ import math import io import struct -from mitmproxy.contrib import tnetstring +from mitmproxy.io import tnetstring MAXINT = 2 ** (struct.Struct('i').size * 8 - 1) - 1 diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 630fc7e48..78f893c08 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -6,7 +6,7 @@ import mitmproxy.io from mitmproxy import flowfilter from mitmproxy import options from mitmproxy.proxy import config -from mitmproxy.contrib import tnetstring +from mitmproxy.io import tnetstring from mitmproxy.exceptions import FlowReadException from mitmproxy import flow from mitmproxy import http diff --git a/test/mitmproxy/test_websocket.py b/test/mitmproxy/test_websocket.py index 62f69e2da..7c53a4b0b 100644 --- a/test/mitmproxy/test_websocket.py +++ b/test/mitmproxy/test_websocket.py @@ -1,7 +1,7 @@ import io import pytest -from mitmproxy.contrib import tnetstring +from mitmproxy.io import tnetstring from mitmproxy import flowfilter from mitmproxy.test import tflow