diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-08-19 16:06:33 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-08-19 16:06:33 +0200 |
commit | 9920de1e153d4a85bbc4fa1dfd8fe5db45d56ab3 (patch) | |
tree | e6c9a5fd22a975d44c388fadeb3975f925f503f3 /netlib/tcp.py | |
parent | 6810fba54ef9c885215d5ff02534b93bb6868b2e (diff) | |
download | mitmproxy-9920de1e153d4a85bbc4fa1dfd8fe5db45d56ab3.tar.gz mitmproxy-9920de1e153d4a85bbc4fa1dfd8fe5db45d56ab3.tar.bz2 mitmproxy-9920de1e153d4a85bbc4fa1dfd8fe5db45d56ab3.zip |
tcp._Connection: clean up code, fix inheritance
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r-- | netlib/tcp.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py index c6638177..a0e2ab5e 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -399,6 +399,22 @@ def close_socket(sock): class _Connection(object): + rbufsize = -1 + wbufsize = -1 + + def __init__(self, connection): + if connection: + self.connection = connection + self.rfile = Reader(self.connection.makefile('rb', self.rbufsize)) + self.wfile = Writer(self.connection.makefile('wb', self.wbufsize)) + else: + self.connection = None + self.rfile = None + self.wfile = None + + self.ssl_established = False + self.finished = False + def get_current_cipher(self): if not self.ssl_established: return None @@ -510,16 +526,13 @@ class _Connection(object): class TCPClient(_Connection): - rbufsize = -1 - wbufsize = -1 def __init__(self, address, source_address=None): - self.connection, self.rfile, self.wfile = None, None, None + super(TCPClient, self).__init__(None) self.address = address self.source_address = Address.wrap( source_address) if source_address else None self.cert = None - self.ssl_established = False self.ssl_verification_error = None self.sni = None @@ -627,20 +640,12 @@ class BaseHandler(_Connection): """ The instantiator is expected to call the handle() and finish() methods. - """ - rbufsize = -1 - wbufsize = -1 def __init__(self, connection, address, server): - self.connection = connection + super(BaseHandler, self).__init__(connection) self.address = Address.wrap(address) self.server = server - self.rfile = Reader(self.connection.makefile('rb', self.rbufsize)) - self.wfile = Writer(self.connection.makefile('wb', self.wbufsize)) - - self.finished = False - self.ssl_established = False self.clientcert = None def create_ssl_context(self, |