diff options
| -rw-r--r-- | examples/read_dumpfile | 5 | ||||
| -rw-r--r-- | mitmproxy/console/__init__.py | 9 | ||||
| -rw-r--r-- | mitmproxy/dump.py | 6 | ||||
| -rw-r--r-- | mitmproxy/exceptions.py | 4 | ||||
| -rw-r--r-- | mitmproxy/flow.py | 20 | ||||
| -rw-r--r-- | mitmproxy/web/__init__.py | 5 | ||||
| -rw-r--r-- | test/mitmproxy/test_flow.py | 10 | ||||
| -rw-r--r-- | test/mitmproxy/test_flow_format_compat.py | 4 | 
8 files changed, 31 insertions, 32 deletions
| diff --git a/examples/read_dumpfile b/examples/read_dumpfile index 39f18e3d..b1001c3d 100644 --- a/examples/read_dumpfile +++ b/examples/read_dumpfile @@ -4,6 +4,7 @@  #  from mitmproxy import flow +from mitmproxy.exceptions import FlowReadException  import pprint  import sys @@ -16,5 +17,5 @@ with open(sys.argv[1], "rb") as logfile:              print(f.request.host)              pp.pprint(f.get_state())              print("") -    except flow.FlowReadError as v: -        print("Flow file corrupted. Stopped loading.") +    except FlowReadException as e: +        print("Flow file corrupted: {}".format(e)) diff --git a/mitmproxy/console/__init__.py b/mitmproxy/console/__init__.py index 32e4d33c..5b980572 100644 --- a/mitmproxy/console/__init__.py +++ b/mitmproxy/console/__init__.py @@ -16,9 +16,10 @@ import weakref  from netlib import tcp -from .. import controller, flow, script, contentviews +from .. import flow, script, contentviews  from . import flowlist, flowview, help, window, signals, options  from . import grideditor, palettes, statusbar, palettepicker +from ..exceptions import FlowReadException  EVENTLOG_SIZE = 500 @@ -357,7 +358,7 @@ class ConsoleMaster(flow.FlowMaster):          """          try:              return flow.read_flows_from_paths(path) -        except flow.FlowReadError as e: +        except FlowReadException as e:              signals.status_message.send(message=e.strerror)      def client_playback_path(self, path): @@ -641,8 +642,8 @@ class ConsoleMaster(flow.FlowMaster):          reterr = None          try:              flow.FlowMaster.load_flows_file(self, path) -        except flow.FlowReadError as v: -            reterr = str(v) +        except FlowReadException as e: +            reterr = str(e)          signals.flowlist_change.send(self)          return reterr diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index 636e5a7d..98d9bd5e 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -7,7 +7,7 @@ import itertools  from netlib import tcp  import netlib.utils  from . import flow, filt, contentviews -from .exceptions import ContentViewException +from .exceptions import ContentViewException, FlowReadException  class DumpError(Exception): @@ -132,7 +132,7 @@ class DumpMaster(flow.FlowMaster):          if options.rfile:              try:                  self.load_flows_file(options.rfile) -            except flow.FlowReadError as v: +            except FlowReadException as v:                  self.add_event("Flow file corrupted.", "error")                  raise DumpError(v) @@ -146,7 +146,7 @@ class DumpMaster(flow.FlowMaster):          """          try:              return flow.read_flows_from_paths(paths) -        except flow.FlowReadError as e: +        except FlowReadException as e:              raise DumpError(e.strerror)      def add_event(self, e, level="info"): diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index d600f2e3..86bf75ae 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -60,3 +60,7 @@ class ReplayException(ProxyException):  class ScriptException(ProxyException):      pass + + +class FlowReadException(ProxyException): +    pass
\ No newline at end of file diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 82e3fa06..2bed4e1a 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -20,7 +20,7 @@ from . import controller, tnetstring, filt, script, version, flow_format_compat  from .onboarding import app  from .proxy.config import HostMatcher  from .protocol.http_replay import RequestReplayThread -from .exceptions import Kill +from .exceptions import Kill, FlowReadException  from .models import ClientConnection, ServerConnection, HTTPFlow, HTTPRequest  from collections import defaultdict @@ -913,7 +913,7 @@ class FlowMaster(controller.ServerMaster):                      freader = FlowReader(f)                      return self.load_flows(freader)          except IOError as v: -            raise FlowReadError(v.strerror) +            raise FlowReadException(v.strerror)      def process_new_request(self, f):          if self.stickycookie_state: @@ -1114,7 +1114,8 @@ def read_flows_from_paths(paths):      From a performance perspective, streaming would be advisable -      however, if there's an error with one of the files, we want it to be raised immediately. -    If an error occurs, a FlowReadError will be raised. +    Raises: +        FlowReadException, if any error occurs.      """      try:          flows = [] @@ -1123,7 +1124,7 @@ def read_flows_from_paths(paths):              with open(path, "rb") as f:                  flows.extend(FlowReader(f).stream())      except IOError as e: -        raise FlowReadError(e.strerror) +        raise FlowReadException(e.strerror)      return flows @@ -1137,13 +1138,6 @@ class FlowWriter:          tnetstring.dump(d, self.fo) -class FlowReadError(Exception): - -    @property -    def strerror(self): -        return self.args[0] - -  class FlowReader:      def __init__(self, fo): @@ -1169,7 +1163,7 @@ class FlowReader:                  try:                      data = flow_format_compat.migrate_flow(data)                  except ValueError as e: -                    raise FlowReadError(str(e)) +                    raise FlowReadException(str(e))                  if can_tell:                      off = self.fo.tell()                  yield HTTPFlow.from_state(data) @@ -1177,7 +1171,7 @@ class FlowReader:              # Error is due to EOF              if can_tell and self.fo.tell() == off and self.fo.read() == '':                  return -            raise FlowReadError("Invalid data format.") +            raise FlowReadException("Invalid data format.")  class FilteredFlowWriter: diff --git a/mitmproxy/web/__init__.py b/mitmproxy/web/__init__.py index 4ad0b082..62468d95 100644 --- a/mitmproxy/web/__init__.py +++ b/mitmproxy/web/__init__.py @@ -6,7 +6,8 @@ import sys  from netlib.http import authentication -from .. import controller, flow +from .. import flow +from ..exceptions import FlowReadException  from . import app @@ -155,7 +156,7 @@ class WebMaster(flow.FlowMaster):          if options.rfile:              try:                  self.load_flows_file(options.rfile) -            except flow.FlowReadError as v: +            except FlowReadException as v:                  self.add_event(                      "Could not read flow file: %s" % v,                      "error" diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 8729cc77..1d69a3f8 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -1,8 +1,5 @@ -from six.moves import queue -import time  import os.path  from six.moves import cStringIO as StringIO -import email.utils  import mock @@ -10,6 +7,7 @@ import netlib.utils  from netlib import odict  from netlib.http import Headers  from mitmproxy import filt, controller, tnetstring, flow +from mitmproxy.exceptions import FlowReadException  from mitmproxy.models import Error  from mitmproxy.models import Flow  from mitmproxy.models import HTTPFlow @@ -727,10 +725,10 @@ class TestSerialize:          sio.write("bogus")          sio.seek(0)          r = flow.FlowReader(sio) -        tutils.raises(flow.FlowReadError, list, r.stream()) +        tutils.raises(FlowReadException, list, r.stream()) -        f = flow.FlowReadError("foo") -        assert f.strerror == "foo" +        f = FlowReadException("foo") +        assert str(f) == "foo"      def test_versioncheck(self):          f = tutils.tflow() diff --git a/test/mitmproxy/test_flow_format_compat.py b/test/mitmproxy/test_flow_format_compat.py index 7a0694e1..2c477cc2 100644 --- a/test/mitmproxy/test_flow_format_compat.py +++ b/test/mitmproxy/test_flow_format_compat.py @@ -1,4 +1,4 @@ -from mitmproxy.flow import FlowReader, FlowReadError +from mitmproxy.flow import FlowReader, FlowReadException  from . import tutils @@ -13,5 +13,5 @@ def test_load():  def test_cannot_convert():      with open(tutils.test_data.path("data/dumpfile-012"), "rb") as f:          flow_reader = FlowReader(f) -        with tutils.raises(FlowReadError): +        with tutils.raises(FlowReadException):              list(flow_reader.stream()) | 
