From e5b79a6d728584cceb918ffbf73c54ec55e948b5 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 22 Sep 2016 01:58:01 -0700 Subject: minor cleanup --- netlib/exceptions.py | 4 ---- netlib/tcp.py | 17 ++++++----------- 2 files changed, 6 insertions(+), 15 deletions(-) (limited to 'netlib') diff --git a/netlib/exceptions.py b/netlib/exceptions.py index 37651409..dec79c22 100644 --- a/netlib/exceptions.py +++ b/netlib/exceptions.py @@ -58,7 +58,3 @@ class InvalidCertificateException(TlsException): class Timeout(TcpException): pass - - -class ProtocolException(NetlibException): - pass diff --git a/netlib/tcp.py b/netlib/tcp.py index 2c55de85..eea10425 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -484,14 +484,12 @@ class _Connection(object): if not isinstance(self.connection, SSL.Connection): if not getattr(self.wfile, "closed", False): try: - if self.wfile: - self.wfile.flush() - self.wfile.close() + self.wfile.flush() + self.wfile.close() except exceptions.TcpDisconnect: pass - if self.rfile: - self.rfile.close() + self.rfile.close() else: try: self.connection.shutdown() @@ -731,11 +729,7 @@ class TCPClient(_Connection): def connect(self): try: - # Allow the socket to be manipulated by using the server_conn stub. - if not self.connection: - connection = socket.socket(self.address.family, socket.SOCK_STREAM) - else: - connection = self.connection + connection = socket.socket(self.address.family, socket.SOCK_STREAM) if self.spoof_source_address: try: @@ -744,7 +738,8 @@ class TCPClient(_Connection): connection.setsockopt(socket.SOL_IP, 19, 1) except socket.error as e: raise exceptions.TcpException( - "Failed to spoof the source address: " + e.strerror) + "Failed to spoof the source address: " + e.strerror + ) if self.source_address: connection.bind(self.source_address()) connection.connect(self.address()) -- cgit v1.2.3