diff --git a/netlib/http.py b/netlib/http.py index 9c72c601b..acd9d85e3 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -260,15 +260,15 @@ def read_response(rfile, method, body_size_limit): if len(parts) == 2: # handle missing message gracefully parts.append("") if not len(parts) == 3: - raise HttpError(502, "Invalid server response: %s."%line) + raise HttpError(502, "Invalid server response: %s"%repr(line)) proto, code, msg = parts httpversion = parse_http_protocol(proto) if httpversion is None: - raise HttpError(502, "Invalid HTTP version: %s."%httpversion) + raise HttpError(502, "Invalid HTTP version: %s"%repr(httpversion)) try: code = int(code) except ValueError: - raise HttpError(502, "Invalid server response: %s."%line) + raise HttpError(502, "Invalid server response: %s"%repr(line)) headers = read_headers(rfile) if code >= 100 and code <= 199: return read_response(rfile, method, body_size_limit) diff --git a/netlib/tcp.py b/netlib/tcp.py index b3fc22125..bb0a00b90 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -50,6 +50,8 @@ class FileLike: class TCPClient: + rbufsize = -1 + wbufsize = -1 def __init__(self, host, port): self.host, self.port = host, port self.connection, self.rfile, self.wfile = None, None, None @@ -78,7 +80,8 @@ class TCPClient: addr = socket.gethostbyname(self.host) connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) connection.connect((addr, self.port)) - self.rfile, self.wfile = connection.makefile('rb'), connection.makefile('wb') + self.rfile = connection.makefile('rb', self.rbufsize) + self.wfile = connection.makefile('wb', self.wbufsize) except socket.error, err: raise NetLibError('Error connecting to "%s": %s' % (self.host, err)) self.connection = connection