Mercurial > cpython-lru_cache-weakref
diff Lib/http/client.py @ 67046:6f56b247a7cd
Issue3243 - Support iterable bodies in httplib. Patch contributions by Xuanji Li and Chris AtLee.
| author | Senthil Kumaran <orsenthil@gmail.com> |
|---|---|
| date | Sun, 19 Dec 2010 10:49:52 +0000 |
| parents | 0b94635ed2f6 |
| children | 968db3e5b1d8 |
line wrap: on
line diff
--- a/Lib/http/client.py Sun Dec 19 10:30:28 2010 +0000 +++ b/Lib/http/client.py Sun Dec 19 10:49:52 2010 +0000 @@ -71,6 +71,7 @@ import io import os import socket +import collections from urllib.parse import urlsplit import warnings @@ -730,7 +731,11 @@ self.__state = _CS_IDLE def send(self, data): - """Send `data' to the server.""" + """Send `data' to the server. + ``data`` can be a string object, a bytes object, an array object, a + file-like object that supports a .read() method, or an iterable object. + """ + if self.sock is None: if self.auto_open: self.connect() @@ -762,8 +767,16 @@ if encode: datablock = datablock.encode("iso-8859-1") self.sock.sendall(datablock) - else: + + try: self.sock.sendall(data) + except TypeError: + if isinstance(data, collections.Iterable): + for d in data: + self.sock.sendall(d) + else: + raise TypeError("data should be byte-like object\ + or an iterable, got %r " % type(it)) def _output(self, s): """Add a line of output to the current request buffer.
