def write(self, buf):
"""
Write a chunk of data to the output stream in accordance with the
chunked transfer encoding protocol.
"""
try:
self.conn.send(hex(len(buf))[2:].encode('utf-8'))
self.conn.send(b'\r\n')
self.conn.send(buf)
self.conn.send(b'\r\n')
except Exception:
resp = self.conn.getresponse()
sys.stderr.write(
'Exception while sending HTTP chunk to %s, status was %s, '
'message was:\n%s\n' % (self.output_spec['url'], resp.status,
resp.read()))
self.conn.close()
self._closed = True
raise
评论列表
文章目录