def _read_line(self):
line = self._rfile.readline()
if not line.endswith("\n"):
+ self.disconnect()
raise ConnectionError("Connection lost while reading line")
line = line.rstrip("\n")
if line.startswith(ERROR_PREFIX):
if sock is not None:
sock.close()
if err is not None:
- raise err
+ raise ConnectionError(str(err))
else:
raise ConnectionError("getaddrinfo returns an empty list")
raise
def disconnect(self):
- self._rfile.close()
- self._wfile.close()
- self._sock.close()
+ if isinstance(self._rfile, socket._fileobject):
+ print('closing r socket')
+ self._rfile.close()
+ if isinstance(self._wfile, socket._fileobject):
+ print('closing w socket')
+ self._wfile.close()
+ if isinstance(self._sock, socket.socket):
+ print('closing socket')
+ self._sock.close()
self._reset()
def fileno(self):