mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Merge pull request #935 from mitmproxy/coding-style
Improve Coding Style
This commit is contained in:
commit
ea0ba6d143
@ -13,7 +13,6 @@ from .. import version
|
|||||||
from .flow import Flow
|
from .flow import Flow
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MessageMixin(object):
|
class MessageMixin(object):
|
||||||
|
|
||||||
def get_decoded_content(self):
|
def get_decoded_content(self):
|
||||||
|
@ -242,7 +242,6 @@ class HttpLayer(Layer):
|
|||||||
self.send_response(response)
|
self.send_response(response)
|
||||||
except (NetlibException, H2Error):
|
except (NetlibException, H2Error):
|
||||||
self.log(traceback.format_exc(), "debug")
|
self.log(traceback.format_exc(), "debug")
|
||||||
pass
|
|
||||||
|
|
||||||
def change_upstream_proxy_server(self, address):
|
def change_upstream_proxy_server(self, address):
|
||||||
# Make set_upstream_proxy_server always available,
|
# Make set_upstream_proxy_server always available,
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
from __future__ import (absolute_import, print_function, division)
|
from __future__ import (absolute_import, print_function, division)
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from netlib import tcp
|
|
||||||
from netlib.http import http1
|
from netlib.http import http1
|
||||||
|
|
||||||
from .http import _HttpTransmissionLayer, HttpLayer
|
from .http import _HttpTransmissionLayer, HttpLayer
|
||||||
from .. import utils
|
|
||||||
from ..models import HTTPRequest, HTTPResponse
|
from ..models import HTTPRequest, HTTPResponse
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ from .base import Layer
|
|||||||
from .http import _HttpTransmissionLayer, HttpLayer
|
from .http import _HttpTransmissionLayer, HttpLayer
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from ..models import HTTPRequest, HTTPResponse
|
from ..models import HTTPRequest, HTTPResponse
|
||||||
from ..exceptions import HttpProtocolException
|
|
||||||
from ..exceptions import ProtocolException
|
|
||||||
|
|
||||||
|
|
||||||
class SafeH2Connection(H2Connection):
|
class SafeH2Connection(H2Connection):
|
||||||
@ -234,7 +232,6 @@ class Http2Layer(Layer):
|
|||||||
stream.zombie = time.time()
|
stream.zombie = time.time()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
frame, _ = hyperframe.frame.Frame.parse_frame_header(raw_frame[:9])
|
frame, _ = hyperframe.frame.Frame.parse_frame_header(raw_frame[:9])
|
||||||
|
|
||||||
if is_server:
|
if is_server:
|
||||||
|
@ -419,7 +419,7 @@ class TlsLayer(Layer):
|
|||||||
try:
|
try:
|
||||||
self.ctx.connect()
|
self.ctx.connect()
|
||||||
self._establish_tls_with_server()
|
self._establish_tls_with_server()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
self._establish_tls_with_client()
|
self._establish_tls_with_client()
|
||||||
except:
|
except:
|
||||||
|
@ -3,6 +3,7 @@ from netlib.utils import Serializable
|
|||||||
|
|
||||||
|
|
||||||
class StateObject(Serializable):
|
class StateObject(Serializable):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
An object with serializable state.
|
An object with serializable state.
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ class APIError(tornado.web.HTTPError):
|
|||||||
|
|
||||||
|
|
||||||
class BasicAuth(object):
|
class BasicAuth(object):
|
||||||
|
|
||||||
def set_auth_headers(self):
|
def set_auth_headers(self):
|
||||||
self.set_status(401)
|
self.set_status(401)
|
||||||
self.set_header('WWW-Authenticate', 'Basic realm=MITMWeb')
|
self.set_header('WWW-Authenticate', 'Basic realm=MITMWeb')
|
||||||
|
@ -6,21 +6,6 @@ if os.name == "nt":
|
|||||||
import libmproxy.console.help as help
|
import libmproxy.console.help as help
|
||||||
|
|
||||||
|
|
||||||
class DummyLoop:
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.widget = None
|
|
||||||
|
|
||||||
|
|
||||||
class DummyMaster:
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.loop = DummyLoop()
|
|
||||||
|
|
||||||
def make_view(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestHelp:
|
class TestHelp:
|
||||||
|
|
||||||
def test_helptext(self):
|
def test_helptext(self):
|
||||||
@ -28,7 +13,6 @@ class TestHelp:
|
|||||||
assert h.helptext()
|
assert h.helptext()
|
||||||
|
|
||||||
def test_keypress(self):
|
def test_keypress(self):
|
||||||
master = DummyMaster()
|
|
||||||
h = help.HelpView([1, 2, 3])
|
h = help.HelpView([1, 2, 3])
|
||||||
assert not h.keypress((0, 0), "q")
|
assert not h.keypress((0, 0), "q")
|
||||||
assert not h.keypress((0, 0), "?")
|
assert not h.keypress((0, 0), "?")
|
||||||
|
@ -209,7 +209,6 @@ class TestMatching:
|
|||||||
|
|
||||||
def test_method(self):
|
def test_method(self):
|
||||||
q = self.req()
|
q = self.req()
|
||||||
s = self.resp()
|
|
||||||
assert self.q("~m get", q)
|
assert self.q("~m get", q)
|
||||||
assert not self.q("~m post", q)
|
assert not self.q("~m post", q)
|
||||||
|
|
||||||
@ -218,7 +217,6 @@ class TestMatching:
|
|||||||
|
|
||||||
def test_domain(self):
|
def test_domain(self):
|
||||||
q = self.req()
|
q = self.req()
|
||||||
s = self.resp()
|
|
||||||
assert self.q("~d host", q)
|
assert self.q("~d host", q)
|
||||||
assert not self.q("~d none", q)
|
assert not self.q("~d none", q)
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ class TestFlow(object):
|
|||||||
|
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
f = tutils.tflow(resp=True)
|
f = tutils.tflow(resp=True)
|
||||||
a0 = f.get_state()
|
f.get_state()
|
||||||
f2 = f.copy()
|
f2 = f.copy()
|
||||||
a = f.get_state()
|
a = f.get_state()
|
||||||
b = f2.get_state()
|
b = f2.get_state()
|
||||||
@ -532,7 +532,6 @@ class TestState:
|
|||||||
assert c.flow_count() == 2
|
assert c.flow_count() == 2
|
||||||
assert c.active_flow_count() == 1
|
assert c.active_flow_count() == 1
|
||||||
|
|
||||||
_ = HTTPResponse.wrap(netlib.tutils.tresp())
|
|
||||||
assert not c.update_flow(None)
|
assert not c.update_flow(None)
|
||||||
assert c.active_flow_count() == 1
|
assert c.active_flow_count() == 1
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from netlib.exceptions import HttpSyntaxException
|
|
||||||
from netlib.http import http1
|
from netlib.http import http1
|
||||||
from netlib.tcp import TCPClient
|
from netlib.tcp import TCPClient
|
||||||
from netlib.tutils import treq, raises
|
from netlib.tutils import treq
|
||||||
from . import tutils, tservers
|
from . import tutils, tservers
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,8 @@ import pytest
|
|||||||
import traceback
|
import traceback
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import sys
|
|
||||||
|
|
||||||
from libmproxy.proxy.config import ProxyConfig
|
from libmproxy.proxy.config import ProxyConfig
|
||||||
from libmproxy.proxy.server import ProxyServer
|
|
||||||
from libmproxy.cmdline import APP_HOST, APP_PORT
|
from libmproxy.cmdline import APP_HOST, APP_PORT
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -24,9 +22,7 @@ from netlib import tservers as netlib_tservers
|
|||||||
from netlib.utils import http2_read_raw_frame
|
from netlib.utils import http2_read_raw_frame
|
||||||
|
|
||||||
import h2
|
import h2
|
||||||
from hyperframe.frame import Frame
|
|
||||||
|
|
||||||
from libmproxy import utils
|
|
||||||
from . import tservers
|
from . import tservers
|
||||||
|
|
||||||
requires_alpn = pytest.mark.skipif(
|
requires_alpn = pytest.mark.skipif(
|
||||||
|
Loading…
Reference in New Issue
Block a user