summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-12-19 10:49:52 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-12-19 10:49:52 (GMT)
commit7bc0d872ddb023333acc05b7d038cdb74cfc047b (patch)
tree6225e5ecb0546a7826743510555c604751b238c7 /Lib/http
parent8a60e94802b04a838607b4aebba6fc8b70f7b87c (diff)
downloadcpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.zip
cpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.tar.gz
cpython-7bc0d872ddb023333acc05b7d038cdb74cfc047b.tar.bz2
Issue3243 - Support iterable bodies in httplib. Patch contributions by Xuanji Li and Chris AtLee.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 8ea75ce..8d62aa5 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -71,6 +71,7 @@ import email.message
import io
import os
import socket
+import collections
from urllib.parse import urlsplit
import warnings
@@ -730,7 +731,11 @@ class HTTPConnection:
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 @@ class HTTPConnection:
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.