Martin Panter added the comment:
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")
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12319>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com