[New-bugs-announce] [issue3243] Support iterable bodies in httplib

Chris AtLee report at bugs.python.org
Mon Jun 30 20:02:18 CEST 2008


New submission from Chris AtLee <chris at atlee.ca>:

httplib should support requests whose bodies are iterable objects.  This
would facilitate doing large file uploads via HTTP since you wouldn't
have to load the entire file into memory to create the request string.

Index: Lib/httplib.py
===================================================================
--- Lib/httplib.py      (revision 64600)
+++ Lib/httplib.py      (working copy)
@@ -688,7 +688,12 @@
        self.__state = _CS_IDLE

    def send(self, str):
-        """Send `str' to the server."""
+        """Send `str` to the server.
+
+        ``str`` can be a string object, a file-like object that supports
+        a .read() method, or an iterable object that supports a .next()
+        method.
+        """
        if self.sock is None:
            if self.auto_open:
                self.connect()
@@ -710,6 +715,10 @@
                while data:
                    self.sock.sendall(data)
                    data=str.read(blocksize)
+            elif hasattr(str,'next'):
+                if self.debuglevel > 0: print "sendIng an iterable"
+                for data in str:
+                    self.sock.sendall(data)
            else:
                self.sock.sendall(str)
        except socket.error, v:

----------
components: Library (Lib)
messages: 69014
nosy: catlee
severity: normal
status: open
title: Support iterable bodies in httplib
type: feature request
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3243>
_______________________________________


More information about the New-bugs-announce mailing list