# accepts iso-8859-1.
def __init__(self, sock, debuglevel=0, strict=0, method=None):
- # XXX If the response includes a content-length header, we
+ # If the response includes a content-length header, we
# need to make sure that the client doesn't read more than the
# specified number of bytes. If it does, it will block until
# the server times out and closes the connection. (The only
- # applies to HTTP/1.1 connections.) Since some clients access
- # self.fp directly rather than calling read(), this is a little
- # tricky.
- self.fp = sock.makefile("rb", 0)
+ # applies to HTTP/1.1 connections.) This will happen if a self.fp.read()
+ # is done (without a size) whether self.fp is buffered or not.
+ # So, no self.fp.read() by clients unless they know what they are doing.
+ self.fp = sock.makefile("rb")
self.debuglevel = debuglevel
self.strict = strict
self._method = method
self.verbose = verbose
- return self._parse_response(resp, None)
+ return self.parse_response(resp)
##
# Create parser.
# @return Response tuple and target method.
def parse_response(self, file):
- # compatibility interface
- return self._parse_response(file, None)
-
- ##
- # Parse response (alternate interface). This is similar to the
- # parse_response method, but also provides direct access to the
- # underlying socket object (where available).
- #
- # @param file Stream.
- # @param sock Socket handle (or None, if the socket object
- # could not be accessed).
- # @return Response tuple and target method.
-
- def _parse_response(self, file, sock):
# read response from input file/socket, and parse it
p, u = self.getparser()
while 1:
- if sock:
- response = sock.recv(1024)
- else:
- response = file.read(1024)
+ response = file.read(1024)
if not response:
break
if self.verbose: