mitmproxy: fix most flake8 offenses

This commit is contained in:
Thomas Kriechbaumer 2016-05-28 22:39:30 +02:00
parent e4045dc7f8
commit 7971dce223
12 changed files with 36 additions and 19 deletions

View File

@ -6,6 +6,7 @@ from .exceptions import Kill
class Master(object):
"""
The master handles mitmproxy's main event loop.
"""
@ -48,6 +49,7 @@ class Master(object):
class ServerMaster(Master):
"""
The ServerMaster adds server thread support to the master.
"""
@ -74,6 +76,7 @@ class ServerMaster(Master):
class ServerThread(threading.Thread):
def __init__(self, server):
self.server = server
super(ServerThread, self).__init__()
@ -85,6 +88,7 @@ class ServerThread(threading.Thread):
class Channel(object):
"""
The only way for the proxy server to communicate with the master
is to use the channel it has been given.
@ -126,6 +130,7 @@ class Channel(object):
class DummyReply(object):
"""
A reply object that does nothing. Useful when we need an object to seem
like it has a channel, and during testing.
@ -143,6 +148,7 @@ NO_REPLY = object()
class Reply(object):
"""
Messages sent through a channel are decorated with a "reply" attribute.
This object is used to respond to the message through the return

View File

@ -13,6 +13,7 @@ import sys
class ProxyException(Exception):
"""
Base class for all exceptions thrown by mitmproxy.
"""
@ -22,6 +23,7 @@ class ProxyException(Exception):
class Kill(ProxyException):
"""
Signal that both client and server connection(s) should be killed immediately.
"""
@ -37,6 +39,7 @@ class TlsProtocolException(ProtocolException):
class ClientHandshakeException(TlsProtocolException):
def __init__(self, message, server):
super(ClientHandshakeException, self).__init__(message)
self.server = server
@ -67,6 +70,7 @@ class ReplayException(ProxyException):
class ScriptException(ProxyException):
@classmethod
def from_exception_context(cls, cut_tb=1):
"""

View File

@ -38,6 +38,7 @@ import pyparsing as pp
class _Token(object):
def dump(self, indent=0, fp=sys.stdout):
print("{spacing}{name}{expr}".format(
spacing="\t" * indent,

View File

@ -8,6 +8,7 @@ import re
from six.moves.urllib.parse import quote
from six.moves.urllib.parse import quote_plus
def curl_command(flow):
data = "curl "
@ -124,13 +125,12 @@ def locust_code(flow):
max_wait = 3000
""").strip()
components = map(lambda x: quote(x, safe=""), flow.request.path_components)
file_name = "_".join(components)
name = re.sub('\W|^(?=\d)', '_', file_name)
url = flow.request.scheme + "://" + flow.request.host + "/" + "/".join(components)
if name == "" or name is None:
new_name = "_".join([str(flow.request.host) , str(flow.request.timestamp_start)])
new_name = "_".join([str(flow.request.host), str(flow.request.timestamp_start)])
name = re.sub('\W|^(?=\d)', '_', new_name)
args = ""
headers = ""

View File

@ -10,6 +10,7 @@ from .. import stateobject, utils
class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
"""
A client connection
@ -21,6 +22,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
timestamp_ssl_setup: TLS established timestamp
timestamp_end: Connection end timestamp
"""
def __init__(self, client_connection, address, server):
# Eventually, this object is restored from state. We don't have a
# connection then.
@ -101,6 +103,7 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject):
class ServerConnection(tcp.TCPClient, stateobject.StateObject):
"""
A server connection
@ -117,6 +120,7 @@ class ServerConnection(tcp.TCPClient, stateobject.StateObject):
timestamp_ssl_setup: TLS established timestamp
timestamp_end: Connection end timestamp
"""
def __init__(self, address, source_address=None):
tcp.TCPClient.__init__(self, address, source_address)

View File

@ -72,9 +72,9 @@ class HTTPRequest(MessageMixin, Request):
def get_state(self):
state = super(HTTPRequest, self).get_state()
state.update(
stickycookie = self.stickycookie,
stickyauth = self.stickyauth,
is_replay = self.is_replay,
stickycookie=self.stickycookie,
stickyauth=self.stickyauth,
is_replay=self.is_replay,
)
return state
@ -109,6 +109,7 @@ class HTTPRequest(MessageMixin, Request):
class HTTPResponse(MessageMixin, Response):
"""
A mitmproxy HTTP response.
This is a very thin wrapper on top of :py:class:`netlib.http.Response` and
@ -124,7 +125,7 @@ class HTTPResponse(MessageMixin, Response):
content,
timestamp_start=None,
timestamp_end=None,
is_replay = False
is_replay=False
):
Response.__init__(
self,

View File

@ -6,6 +6,7 @@ from .flow import Flow
class TCPMessage(Serializable):
def __init__(self, from_client, content, timestamp=None):
self.content = content
self.from_client = from_client
@ -33,6 +34,7 @@ class TCPMessage(Serializable):
class TCPFlow(Flow):
"""
A TCPFlow is a simplified representation of a TCP session.
"""

View File

@ -62,7 +62,7 @@ class RequestReplayThread(threading.Thread):
)
r.first_line_format = "relative"
else:
r.first_line_format= "absolute"
r.first_line_format = "absolute"
else:
server_address = (r.host, r.port)
server = ServerConnection(server_address, (self.config.host, 0))

View File

@ -312,6 +312,7 @@ class TlsClientHello(object):
class TlsLayer(Layer):
"""
The TLS layer implements transparent TLS connections.
@ -482,7 +483,7 @@ class TlsLayer(Layer):
dhparams=self.config.certstore.dhparams,
chain_file=chain_file,
alpn_select_callback=self.__alpn_select_callback,
extra_chain_certs = extra_certs,
extra_chain_certs=extra_certs,
)
# Some TLS clients will not fail the handshake,
# but will immediately throw an "unexpected eof" error on the first read.

View File

@ -58,7 +58,7 @@ class ProxyConfig:
body_size_limit=None,
mode="regular",
upstream_server=None,
upstream_auth = None,
upstream_auth=None,
authenticator=None,
ignore_hosts=tuple(),
tcp_hosts=tuple(),

View File

@ -68,6 +68,7 @@ like so::
"""
import six
from collections import deque
__ver_major__ = 0
__ver_minor__ = 2
@ -77,9 +78,6 @@ __version__ = "%d.%d.%d%s" % (
__ver_major__, __ver_minor__, __ver_patch__, __ver_sub__)
from collections import deque
def dumps(value, encoding=None):
"""dumps(object,encoding=None) -> string