FlowReadError -> FlowReadException

This commit is contained in:
Maximilian Hils
2016-04-29 11:17:49 -07:00
parent c7a85d1b9e
commit 909d5ec87e
8 changed files with 31 additions and 32 deletions

View File

@@ -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))

View File

@@ -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

View File

@@ -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"):

View File

@@ -60,3 +60,7 @@ class ReplayException(ProxyException):
class ScriptException(ProxyException):
pass
class FlowReadException(ProxyException):
pass

View File

@@ -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:

View File

@@ -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"

View File

@@ -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()

View File

@@ -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())