From 1490d665fe785997ba3c1c9be001aa7b6744cb76 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 17 Nov 2020 19:11:28 +0100 Subject: [PATCH] lint! --- mitmproxy/addons/dumper.py | 13 +++++++------ mitmproxy/flow.py | 4 ++-- test/mitmproxy/addons/test_dumper.py | 11 +++++++++++ test/mitmproxy/utils/test_compat.py | 6 ++++++ 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 test/mitmproxy/utils/test_compat.py diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py index 729004976..38da91a47 100644 --- a/mitmproxy/addons/dumper.py +++ b/mitmproxy/addons/dumper.py @@ -181,19 +181,20 @@ class Dumper: replay_str = "" replay = "" - code = flow.response.status_code + assert flow.response + code_int = flow.response.status_code code_color = None - if 200 <= code < 300: + if 200 <= code_int < 300: code_color = "green" - elif 300 <= code < 400: + elif 300 <= code_int < 400: code_color = "magenta" - elif 400 <= code < 600: + elif 400 <= code_int < 600: code_color = "red" code = click.style( - str(code), + str(code_int), fg=code_color, bold=True, - blink=(code == 418) + blink=(code_int == 418), ) if not flow.response.is_http2: diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index b58fc0e4d..d02019ee1 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -2,8 +2,8 @@ import time import typing # noqa import uuid -from mitmproxy import connections -from mitmproxy import controller, exceptions # noqa +from mitmproxy import controller +from mitmproxy import exceptions from mitmproxy import stateobject from mitmproxy import version from mitmproxy.utils import compat diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index 1b1508ddb..eed76c0e7 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -236,3 +236,14 @@ def test_websocket(): f = tflow.twebsocketflow(client_conn=True, err=True) d.websocket_error(f) assert "Error in WebSocket" in sio_err.getvalue() + + +def test_http2(): + sio = io.StringIO() + sio_err = io.StringIO() + d = dumper.Dumper(sio, sio_err) + with taddons.context(d): + f = tflow.tflow(resp=True) + f.response.http_version = b"HTTP/2.0" + d.response(f) + assert "HTTP/2.0 200 OK" in sio.getvalue() diff --git a/test/mitmproxy/utils/test_compat.py b/test/mitmproxy/utils/test_compat.py new file mode 100644 index 000000000..aa805ffe0 --- /dev/null +++ b/test/mitmproxy/utils/test_compat.py @@ -0,0 +1,6 @@ +from mitmproxy.utils import compat + + +def test_simple(): + assert compat.Server + assert compat.Client