Message239119
I left a few comments on Reitveld, mainly about the documentation and API design.
However I understand Rolf specifically wanted chunked encoding to work with the existing urlopen() framework, at least after constructing a separate opener object. I think that should be practical with the existing HTTPConnection implementation. Here is some pseudocode of how I might write a urlopen() handler class, and an encoder class that should be usable for both clients and servers:
class ChunkedHandler(...):
def http_request(...):
# Like AbstractHTTPHandler, but don’t force Content-Length
def default_open(...):
# Like AbstractHTTPHandler, but instead of calling h.request():
encoder = ChunkedEncoder(h.send)
h.putrequest(req.get_method(), req.selector)
for item in headers:
h.putheader(*item)
h.putheader("Transfer-Encoding", encoder.encoding)
h.endheaders()
shutil.copyfileobj(req.data, writer)
encoder.close()
class ChunkedEncoder(io.BufferedIOBase):
# Hook output() up to either http.client.HTTPConnection.send()
# or http.server.BaseHTTPRequestHandler.wfile.write()
encoding = "chunked"
def write(self, b):
self.output("{:X}\r\n".format(len(b)).encode("ascii"))
self.output(b)
self.output(b"\r\n")
def close(self):
self.output(b"0\r\n\r\n") |
|
Date |
User |
Action |
Args |
2015-03-24 13:18:37 | martin.panter | set | recipients:
+ martin.panter, orsenthil, pitrou, harobed, petri.lehtinen, piotr.dobrogost, demian.brecht, whitemice, Rotkraut |
2015-03-24 13:18:37 | martin.panter | set | messageid: <1427203117.33.0.00237083789501.issue12319@psf.upfronthosting.co.za> |
2015-03-24 13:18:37 | martin.panter | link | issue12319 messages |
2015-03-24 13:18:36 | martin.panter | create | |
|