aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/dump.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2016-06-01 16:26:55 +1200
committerAldo Cortesi <aldo@corte.si>2016-06-01 16:26:55 +1200
commit92b24c66530fa9aba804a72e46dd8f34d0f23206 (patch)
tree50b7f496602784e7d3e146ea51f6037697f07dc2 /mitmproxy/dump.py
parent1dd078beb23aa0b483f945eed39c0136984f81a6 (diff)
parent137ee28bd6f9676ab1efc44354eda24077540023 (diff)
downloadmitmproxy-92b24c66530fa9aba804a72e46dd8f34d0f23206.tar.gz
mitmproxy-92b24c66530fa9aba804a72e46dd8f34d0f23206.tar.bz2
mitmproxy-92b24c66530fa9aba804a72e46dd8f34d0f23206.zip
Merge pull request #1183 from mitmproxy/module-imports
use module-level imports only
Diffstat (limited to 'mitmproxy/dump.py')
-rw-r--r--mitmproxy/dump.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py
index 0f54b4d4..f5d6725c 100644
--- a/mitmproxy/dump.py
+++ b/mitmproxy/dump.py
@@ -1,13 +1,19 @@
-from __future__ import absolute_import, print_function
-import traceback
+from __future__ import absolute_import, print_function, division
+
+import itertools
import sys
+import traceback
+
import click
-import itertools
-from netlib import tcp, human
-from netlib.utils import bytes_to_escaped_str
-from . import flow, filt, contentviews, controller
-from .exceptions import ContentViewException, FlowReadException, ScriptException
+from mitmproxy import contentviews
+from mitmproxy import controller
+from mitmproxy import exceptions
+from mitmproxy import filt
+from mitmproxy import flow
+from netlib import human
+from netlib import tcp
+from netlib import utils
class DumpError(Exception):
@@ -127,13 +133,13 @@ class DumpMaster(flow.FlowMaster):
for command in scripts:
try:
self.load_script(command, use_reloader=True)
- except ScriptException as e:
+ except exceptions.ScriptException as e:
raise DumpError(str(e))
if options.rfile:
try:
self.load_flows_file(options.rfile)
- except FlowReadException as v:
+ except exceptions.FlowReadException as v:
self.add_event("Flow file corrupted.", "error")
raise DumpError(v)
@@ -147,7 +153,7 @@ class DumpMaster(flow.FlowMaster):
"""
try:
return flow.read_flows_from_paths(paths)
- except FlowReadException as e:
+ except exceptions.FlowReadException as e:
raise DumpError(str(e))
def add_event(self, e, level="info"):
@@ -175,8 +181,8 @@ class DumpMaster(flow.FlowMaster):
if self.o.flow_detail >= 2:
headers = "\r\n".join(
"{}: {}".format(
- click.style(bytes_to_escaped_str(k), fg="blue", bold=True),
- click.style(bytes_to_escaped_str(v), fg="blue"))
+ click.style(utils.bytes_to_escaped_str(k), fg="blue", bold=True),
+ click.style(utils.bytes_to_escaped_str(v), fg="blue"))
for k, v in message.headers.fields
)
self.echo(headers, indent=4)
@@ -192,7 +198,7 @@ class DumpMaster(flow.FlowMaster):
message.content,
headers=message.headers
)
- except ContentViewException:
+ except exceptions.ContentViewException:
s = "Content viewer failed: \n" + traceback.format_exc()
self.add_event(s, "debug")
type, lines = contentviews.get_content_view(
@@ -238,7 +244,7 @@ class DumpMaster(flow.FlowMaster):
stickycookie = ""
if flow.client_conn:
- client = click.style(bytes_to_escaped_str(flow.client_conn.address.host), bold=True)
+ client = click.style(utils.bytes_to_escaped_str(flow.client_conn.address.host), bold=True)
else:
client = click.style("[replay]", fg="yellow", bold=True)
@@ -247,12 +253,12 @@ class DumpMaster(flow.FlowMaster):
GET="green",
DELETE="red"
).get(method.upper(), "magenta")
- method = click.style(bytes_to_escaped_str(method), fg=method_color, bold=True)
+ method = click.style(utils.bytes_to_escaped_str(method), fg=method_color, bold=True)
if self.showhost:
url = flow.request.pretty_url
else:
url = flow.request.url
- url = click.style(bytes_to_escaped_str(url), bold=True)
+ url = click.style(utils.bytes_to_escaped_str(url), bold=True)
httpversion = ""
if flow.request.http_version not in ("HTTP/1.1", "HTTP/1.0"):
@@ -282,7 +288,7 @@ class DumpMaster(flow.FlowMaster):
elif 400 <= code < 600:
code_color = "red"
code = click.style(str(code), fg=code_color, bold=True, blink=(code == 418))
- reason = click.style(bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True)
+ reason = click.style(utils.bytes_to_escaped_str(flow.response.reason), fg=code_color, bold=True)
if flow.response.content is None:
size = "(content missing)"