import socket from httplib.httpsocket import HTTPSocket, InvalidResponse class HTTPClient(HTTPSocket): """ Wrapper class for a socket. Represents a client which connects to a server. """ host: str def __init__(self, host: str): super().__init__(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) self.host = host def read_line(self): """ Reads the next line decoded as `httpsocket.FORMAT` @return: the decoded next line retrieved from the socket @raise InvalidResponse: If the next line couldn't be decoded, but was expected to """ try: return super().read_line() except UnicodeDecodeError: raise InvalidResponse("Unexpected decoding error")