diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 15:08:35 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 15:08:35 +1300 |
commit | 5a68d21e8c87e05f2ad0c18e6c7c505f5e9fc93d (patch) | |
tree | 12dff67cc2871d1e10c337e0eeaa6477cd888f3e | |
parent | 7c32d4ea2a435484e83aa459831f74ca483d8e3c (diff) | |
download | mitmproxy-5a68d21e8c87e05f2ad0c18e6c7c505f5e9fc93d.tar.gz mitmproxy-5a68d21e8c87e05f2ad0c18e6c7c505f5e9fc93d.tar.bz2 mitmproxy-5a68d21e8c87e05f2ad0c18e6c7c505f5e9fc93d.zip |
Remove flow module entirely, move contents to top level
mitmproxy.flow.io -> mitmproxy.io
mitmproxy.flow.export -> mitmproxy.export
23 files changed, 51 insertions, 53 deletions
diff --git a/examples/flowbasic b/examples/flowbasic index bac98916..cb1e4ea4 100755 --- a/examples/flowbasic +++ b/examples/flowbasic @@ -8,7 +8,7 @@ Note that request and response messages are not automatically replied to, so we need to implement handlers to do this. """ -from mitmproxy import flow, controller, options +from mitmproxy import controller, options, master from mitmproxy.proxy import ProxyServer, ProxyConfig @@ -37,7 +37,6 @@ class MyMaster(master.Master): opts = options.Options(cadir="~/.mitmproxy/") config = ProxyConfig(opts) -state = state.State() server = ProxyServer(config) -m = MyMaster(opts, server, state) +m = MyMaster(opts, server) m.run() diff --git a/examples/flowwriter.py b/examples/flowwriter.py index df2e5a40..afce85aa 100644 --- a/examples/flowwriter.py +++ b/examples/flowwriter.py @@ -1,7 +1,6 @@ import random import sys - -from mitmproxy.flow import FlowWriter +from mimtproxy import io class Writer: @@ -10,7 +9,7 @@ class Writer: f = sys.stdout else: f = open(path, "wb") - self.w = FlowWriter(f) + self.w = io.FlowWriter(f) def response(self, flow): if random.choice([True, False]): diff --git a/examples/read_dumpfile b/examples/read_dumpfile index b1001c3d..e0e9064a 100644 --- a/examples/read_dumpfile +++ b/examples/read_dumpfile @@ -9,7 +9,7 @@ import pprint import sys with open(sys.argv[1], "rb") as logfile: - freader = flow.FlowReader(logfile) + freader = io.FlowReader(logfile) pp = pprint.PrettyPrinter(indent=4) try: for f in freader.stream(): diff --git a/mitmproxy/addons/clientplayback.py b/mitmproxy/addons/clientplayback.py index 75ef2ffd..848d07c3 100644 --- a/mitmproxy/addons/clientplayback.py +++ b/mitmproxy/addons/clientplayback.py @@ -1,4 +1,7 @@ -from mitmproxy import exceptions, flow, ctx +from mitmproxy import exceptions +from mitmproxy import ctx +from mitmproxy import io + class ClientPlayback: @@ -21,7 +24,7 @@ class ClientPlayback: if options.client_replay: ctx.log.info(options.client_replay) try: - flows = flow.read_flows_from_paths(options.client_replay) + flows = io.read_flows_from_paths(options.client_replay) except exceptions.FlowReadException as e: raise exceptions.OptionsError(str(e)) self.load(flows) diff --git a/mitmproxy/addons/filestreamer.py b/mitmproxy/addons/filestreamer.py index b1643b21..552d936f 100644 --- a/mitmproxy/addons/filestreamer.py +++ b/mitmproxy/addons/filestreamer.py @@ -2,7 +2,7 @@ import os.path from mitmproxy import exceptions from mitmproxy import flowfilter -from mitmproxy.flow import io +from mitmproxy import io class FileStreamer: diff --git a/mitmproxy/addons/serverplayback.py b/mitmproxy/addons/serverplayback.py index 383e2754..1161ce23 100644 --- a/mitmproxy/addons/serverplayback.py +++ b/mitmproxy/addons/serverplayback.py @@ -2,7 +2,9 @@ import urllib import hashlib from netlib import strutils -from mitmproxy import exceptions, flow, ctx +from mitmproxy import exceptions +from mitmproxy import ctx +from mitmproxy import io class ServerPlayback: @@ -91,7 +93,7 @@ class ServerPlayback: self.clear() if options.server_replay: try: - flows = flow.read_flows_from_paths(options.server_replay) + flows = io.read_flows_from_paths(options.server_replay) except exceptions.FlowReadException as e: raise exceptions.OptionsError(str(e)) self.load(flows) diff --git a/mitmproxy/console/common.py b/mitmproxy/console/common.py index 5e335c71..91253668 100644 --- a/mitmproxy/console/common.py +++ b/mitmproxy/console/common.py @@ -9,7 +9,7 @@ import urwid.util import netlib from mitmproxy import utils from mitmproxy.console import signals -from mitmproxy.flow import export +from mitmproxy import export from netlib import human try: diff --git a/mitmproxy/console/flowlist.py b/mitmproxy/console/flowlist.py index ba555647..09a5d027 100644 --- a/mitmproxy/console/flowlist.py +++ b/mitmproxy/console/flowlist.py @@ -4,7 +4,7 @@ import netlib.http.url from mitmproxy import exceptions from mitmproxy.console import common from mitmproxy.console import signals -from mitmproxy.flow import export +from mitmproxy import export def _mkhelp(): diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py index b8f91bdb..19afcdbc 100644 --- a/mitmproxy/console/flowview.py +++ b/mitmproxy/console/flowview.py @@ -15,7 +15,7 @@ from mitmproxy.console import grideditor from mitmproxy.console import searchable from mitmproxy.console import signals from mitmproxy.console import tabs -from mitmproxy.flow import export +from mitmproxy import export from netlib.http import Headers from netlib.http import status_codes diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 46dd8254..4921373f 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -19,7 +19,7 @@ from mitmproxy import contentviews from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import master -from mitmproxy import flow +from mitmproxy import io from mitmproxy import flowfilter from mitmproxy import utils from mitmproxy.addons import state @@ -346,7 +346,7 @@ class ConsoleMaster(master.Master): - a list of flows, otherwise. """ try: - return flow.read_flows_from_paths(path) + return io.read_flows_from_paths(path) except exceptions.FlowReadException as e: signals.status_message.send(message=str(e)) @@ -580,7 +580,7 @@ class ConsoleMaster(master.Master): path = os.path.expanduser(path) try: f = open(path, "wb") - fw = flow.FlowWriter(f) + fw = io.FlowWriter(f) for i in flows: fw.add(i) f.close() diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index e8b3126f..47f69303 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -3,8 +3,8 @@ from typing import Optional from mitmproxy import controller from mitmproxy import exceptions -from mitmproxy import flow from mitmproxy import addons +from mitmproxy import io from mitmproxy import options from mitmproxy import master from mitmproxy.addons import dumper, termlog @@ -68,7 +68,7 @@ class DumpMaster(master.Master): or raises a DumpError if that fails. """ try: - return flow.read_flows_from_paths(paths) + return io.read_flows_from_paths(paths) except exceptions.FlowReadException as e: raise DumpError(str(e)) diff --git a/mitmproxy/flow/export.py b/mitmproxy/export.py index e5f4d34a..e5f4d34a 100644 --- a/mitmproxy/flow/export.py +++ b/mitmproxy/export.py diff --git a/mitmproxy/flow/__init__.py b/mitmproxy/flow/__init__.py deleted file mode 100644 index 69e3ed08..00000000 --- a/mitmproxy/flow/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -from mitmproxy.flow import export -from mitmproxy.flow.io import FlowWriter, FilteredFlowWriter, FlowReader, read_flows_from_paths - -__all__ = [ - "export", - "FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths", -] diff --git a/mitmproxy/flow/io.py b/mitmproxy/io.py index e2a6472c..c1b7168b 100644 --- a/mitmproxy/flow/io.py +++ b/mitmproxy/io.py @@ -4,7 +4,7 @@ from mitmproxy import exceptions from mitmproxy import flowfilter from mitmproxy import models from mitmproxy.contrib import tnetstring -from mitmproxy.flow import io_compat +from mitmproxy import io_compat class FlowWriter: diff --git a/mitmproxy/flow/io_compat.py b/mitmproxy/io_compat.py index fc190e2f..fc190e2f 100644 --- a/mitmproxy/flow/io_compat.py +++ b/mitmproxy/io_compat.py diff --git a/mitmproxy/master.py b/mitmproxy/master.py index aa9892e5..dd98c04c 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -11,7 +11,7 @@ from mitmproxy import events from mitmproxy import exceptions from mitmproxy import models from mitmproxy import log -from mitmproxy.flow import io +from mitmproxy import io from mitmproxy.protocol import http_replay from netlib import basethread from netlib import http diff --git a/mitmproxy/web/app.py b/mitmproxy/web/app.py index a81d04be..c45b32a9 100644 --- a/mitmproxy/web/app.py +++ b/mitmproxy/web/app.py @@ -9,11 +9,11 @@ import hashlib import tornado.websocket import tornado.web from io import BytesIO -from mitmproxy.flow import FlowWriter, FlowReader from mitmproxy import flowfilter from mitmproxy import models from mitmproxy import contentviews +from mitmproxy import io from netlib import version @@ -193,7 +193,7 @@ class DumpFlows(RequestHandler): self.set_header("Content-Type", "application/octet-stream") bio = BytesIO() - fw = FlowWriter(bio) + fw = io.FlowWriter(bio) for f in self.state.flows: fw.add(f) @@ -205,7 +205,7 @@ class DumpFlows(RequestHandler): content = self.request.files.values()[0][0].body bio = BytesIO(content) - self.state.load_flows(FlowReader(bio).stream()) + self.state.load_flows(io.FlowReader(bio).stream()) bio.close() diff --git a/test/mitmproxy/addons/test_filestreamer.py b/test/mitmproxy/addons/test_filestreamer.py index a85fcd0c..64208f84 100644 --- a/test/mitmproxy/addons/test_filestreamer.py +++ b/test/mitmproxy/addons/test_filestreamer.py @@ -4,7 +4,7 @@ import os.path from mitmproxy.addons import filestreamer from mitmproxy import master -from mitmproxy.flow import io +from mitmproxy import io from mitmproxy import options from mitmproxy import proxy diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py index 915f9501..f82eec40 100644 --- a/test/mitmproxy/mastertest.py +++ b/test/mitmproxy/mastertest.py @@ -4,7 +4,7 @@ from . import tutils import netlib.tutils from mitmproxy import master -from mitmproxy import flow, proxy, models, options +from mitmproxy import io, proxy, models, options class TestMaster: @@ -33,7 +33,7 @@ class MasterTest: def flowfile(self, path): f = open(path, "wb") - fw = flow.FlowWriter(f) + fw = io.FlowWriter(f) t = tutils.tflow(resp=True) fw.add(t) f.close() diff --git a/test/mitmproxy/test_dump.py b/test/mitmproxy/test_dump.py index a81fbd27..c062a068 100644 --- a/test/mitmproxy/test_dump.py +++ b/test/mitmproxy/test_dump.py @@ -1,7 +1,8 @@ import os import io -from mitmproxy import dump, flow, exceptions, proxy +import mitmproxy.io +from mitmproxy import dump, exceptions, proxy from . import tutils, mastertest @@ -127,7 +128,7 @@ class TestDumpMaster(mastertest.MasterTest): self.dummy_cycle( self.mkmaster(None, outfile=(p, "wb"), verbosity=0), 1, b"" ) - assert len(list(flow.FlowReader(open(p, "rb")).stream())) == 1 + assert len(list(mitmproxy.io.FlowReader(open(p, "rb")).stream())) == 1 def test_write_append(self): with tutils.tmpdir() as d: @@ -140,7 +141,7 @@ class TestDumpMaster(mastertest.MasterTest): self.mkmaster(None, outfile=(p, "ab"), verbosity=0), 1, b"" ) - assert len(list(flow.FlowReader(open(p, "rb")).stream())) == 2 + assert len(list(mitmproxy.io.FlowReader(open(p, "rb")).stream())) == 2 def test_write_err(self): tutils.raises( diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 86cd7d16..d33d395b 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -3,7 +3,8 @@ import io import netlib.utils from netlib.http import Headers -from mitmproxy import flowfilter, flow, options +import mitmproxy.io +from mitmproxy import flowfilter, options from mitmproxy.addons import state from mitmproxy.contrib import tnetstring from mitmproxy.exceptions import FlowReadException, Kill @@ -329,7 +330,7 @@ class TestSerialize: def _treader(self): sio = io.BytesIO() - w = flow.FlowWriter(sio) + w = mitmproxy.io.FlowWriter(sio) for i in range(3): f = tutils.tflow(resp=True) w.add(f) @@ -342,18 +343,18 @@ class TestSerialize: w.add(f) sio.seek(0) - return flow.FlowReader(sio) + return mitmproxy.io.FlowReader(sio) def test_roundtrip(self): sio = io.BytesIO() f = tutils.tflow() f.marked = True f.request.content = bytes(bytearray(range(256))) - w = flow.FlowWriter(sio) + w = mitmproxy.io.FlowWriter(sio) w.add(f) sio.seek(0) - r = flow.FlowReader(sio) + r = mitmproxy.io.FlowReader(sio) l = list(r.stream()) assert len(l) == 1 @@ -386,7 +387,7 @@ class TestSerialize: def test_filter(self): sio = io.BytesIO() flt = flowfilter.parse("~c 200") - w = flow.FilteredFlowWriter(sio, flt) + w = mitmproxy.io.FilteredFlowWriter(sio, flt) f = tutils.tflow(resp=True) f.response.status_code = 200 @@ -397,14 +398,14 @@ class TestSerialize: w.add(f) sio.seek(0) - r = flow.FlowReader(sio) + r = mitmproxy.io.FlowReader(sio) assert len(list(r.stream())) def test_error(self): sio = io.BytesIO() sio.write(b"bogus") sio.seek(0) - r = flow.FlowReader(sio) + r = mitmproxy.io.FlowReader(sio) tutils.raises(FlowReadException, list, r.stream()) f = FlowReadException("foo") @@ -418,7 +419,7 @@ class TestSerialize: tnetstring.dump(d, sio) sio.seek(0) - r = flow.FlowReader(sio) + r = mitmproxy.io.FlowReader(sio) tutils.raises("version", list, r.stream()) diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py index 920f538b..aafd5a1c 100644 --- a/test/mitmproxy/test_flow_export.py +++ b/test/mitmproxy/test_flow_export.py @@ -2,7 +2,7 @@ import re import netlib.tutils from netlib.http import Headers -from mitmproxy.flow import export # heh +from mitmproxy import export # heh from . import tutils diff --git a/test/mitmproxy/test_flow_format_compat.py b/test/mitmproxy/test_flow_format_compat.py index cc80db81..4997aff9 100644 --- a/test/mitmproxy/test_flow_format_compat.py +++ b/test/mitmproxy/test_flow_format_compat.py @@ -1,11 +1,11 @@ -from mitmproxy.flow import FlowReader -from mitmproxy.exceptions import FlowReadException +from mitmproxy import io +from mitmproxy import exceptions from . import tutils def test_load(): with open(tutils.test_data.path("data/dumpfile-011"), "rb") as f: - flow_reader = FlowReader(f) + flow_reader = io.FlowReader(f) flows = list(flow_reader.stream()) assert len(flows) == 1 assert flows[0].request.url == "https://example.com/" @@ -13,6 +13,6 @@ def test_load(): def test_cannot_convert(): with open(tutils.test_data.path("data/dumpfile-010"), "rb") as f: - flow_reader = FlowReader(f) - with tutils.raises(FlowReadException): + flow_reader = io.FlowReader(f) + with tutils.raises(exceptions.FlowReadException): list(flow_reader.stream()) |