]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[merge from 3.5] - Issue28010 - Make http.client.HTTPConnection.putrequest
authorSenthil Kumaran <senthil@uthcode.com>
Thu, 8 Sep 2016 21:29:23 +0000 (14:29 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Thu, 8 Sep 2016 21:29:23 +0000 (14:29 -0700)
                   documentation consistent with the code.

1  2 
Doc/library/http.client.rst
Lib/http/client.py

Simple merge
index a1c4ab948255b734876b2994dfb615da8eaa3b8d,352c1017adce88b682754e1a57fbdc59202deb04..ad8f4104f4fb74a08b6c728e22635a01f320939d
@@@ -1023,52 -930,13 +1023,53 @@@ class HTTPConnection
          self._buffer.extend((b"", b""))
          msg = b"\r\n".join(self._buffer)
          del self._buffer[:]
 -
          self.send(msg)
 +
          if message_body is not None:
 -            self.send(message_body)
 +
 +            # create a consistent interface to message_body
 +            if hasattr(message_body, 'read'):
 +                # Let file-like take precedence over byte-like.  This
 +                # is needed to allow the current position of mmap'ed
 +                # files to be taken into account.
 +                chunks = self._read_readable(message_body)
 +            else:
 +                try:
 +                    # this is solely to check to see if message_body
 +                    # implements the buffer API.  it /would/ be easier
 +                    # to capture if PyObject_CheckBuffer was exposed
 +                    # to Python.
 +                    memoryview(message_body)
 +                except TypeError:
 +                    try:
 +                        chunks = iter(message_body)
 +                    except TypeError:
 +                        raise TypeError("message_body should be a bytes-like "
 +                                        "object or an iterable, got %r"
 +                                        % type(message_body))
 +                else:
 +                    # the object implements the buffer interface and
 +                    # can be passed directly into socket methods
 +                    chunks = (message_body,)
 +
 +            for chunk in chunks:
 +                if not chunk:
 +                    if self.debuglevel > 0:
 +                        print('Zero length chunk ignored')
 +                    continue
 +
 +                if encode_chunked and self._http_vsn == 11:
 +                    # chunked encoding
 +                    chunk = f'{len(chunk):X}''\r\n'.encode('ascii') + chunk \
 +                        + b'\r\n'
 +                self.send(chunk)
 +
 +            if encode_chunked and self._http_vsn == 11:
 +                # end chunked transfer
 +                self.send(b'0\r\n\r\n')
  
-     def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
+     def putrequest(self, method, url, skip_host=False,
+                    skip_accept_encoding=False):
          """Send a request to the server.
  
          `method' specifies an HTTP request method, e.g. 'GET'.