fix chunked encoding.

This commit is contained in:
benoitc 2010-02-26 04:56:46 +01:00
parent 6badf22041
commit b6693a81aa
2 changed files with 14 additions and 20 deletions

View File

@ -148,17 +148,20 @@ class Parser(object):
chunk_size = int(chunk.pop(0), 16) chunk_size = int(chunk.pop(0), 16)
self.start_offset = i+2 self.start_offset = i+2
self.chunk_size = chunk_size self.chunk_size = chunk_size
if self.chunk_size == 0:
self._chunk_eof = True if self.start_offset:
return '', data[:self.start_offset] if self.chunk_size == 0:
else: self._chunk_eof = True
buf = data[self.start_offset:self.start_offset+self.chunk_size] ret = '', data[:self.start_offset]
end_offset = self.start_offset + self.chunk_size + 2
# we wait CRLF else return None
if len(data) >= end_offset:
ret = buf, data[end_offset:]
self.chunk_size = 0
return ret return ret
else:
buf = data[self.start_offset:self.start_offset+self.chunk_size]
end_offset = self.start_offset + self.chunk_size + 2
# we wait CRLF else return None
if len(data) >= end_offset:
ret = buf, data[end_offset:]
self.chunk_size = 0
return ret
return '', data return '', data
def trailing_header(self, data): def trailing_header(self, data):

View File

@ -92,16 +92,7 @@ def close(sock):
pass pass
def read_partial(sock, length): def read_partial(sock, length):
while True: return sock.recv(length)
try:
ret = select.select([sock.fileno()], [], [], 0)
if ret[0]: break
except select.error, e:
if e[0] == errno.EINTR:
continue
raise
data = sock.recv(length)
return data
def write(sock, data): def write(sock, data):
sock.sendall(data) sock.sendall(data)