Esempio n. 1
0
        def send(self, strng):
            """
            A copy of httplib.HTTPConnection.send(), with these fixes:

            * We fix the problem that the connection gets closed upon error
              32 (EPIPE), by not doing that (If the connection gets closed,
              getresponse() fails). This problem was reported as Python issue
              #5542, and the same fix we do here was integrated into Python
              2.7 and 3.1 or 3.2, but not into Python 2.6 (so we still need
              our fix here).

            * Ensure that the data are bytes, not unicode.
              TODO 2016-05 AM: Ensuring bytes at this level can only be a
                               quick fix. Figure out a better approach.
            """
            if self.sock is None:
                if self.auto_open:
                    self.connect()
                else:
                    raise httplib.NotConnected()
            if self.debuglevel > 0:
                print("send: %r" % strng)
            blocksize = 8192
            if hasattr(strng, 'read') and not isinstance(strng, array):
                if self.debuglevel > 0:
                    print("sendIng a read()able")
                data = strng.read(blocksize)
                while data:
                    self.sock.sendall(_ensure_bytes(data))
                    data = strng.read(blocksize)
            else:
                self.sock.sendall(_ensure_bytes(strng))
Esempio n. 2
0
        def send(self, strng):
            """
            A copy of `httplib.HTTPConnection.send()`, with these fixes:

            * We fix the problem that the connection gets closed upon error
              32 (EPIPE), by not doing that (If the connection gets closed,
              getresponse() fails). This problem was reported as Python issue
              #5542, and the same fix we do here was integrated into Python
              2.7 and 3.1 or 3.2.

            * Ensure that the data are bytes, not unicode.
            """
            # NOTE: The attributes come from the httplib mixins in the
            # subclasses so the disable=no-member hides worthless warnings.
            if self.sock is None:  # pylint: disable=no-member
                if self.auto_open:  # pylint: disable=no-member
                    self.connect()  # pylint: disable=no-member
                else:
                    # We raise the same httplib exception the original function
                    # raises. Our caller will handle it.
                    raise httplib.NotConnected()
            if self.debuglevel > 0:  # pylint: disable=no-member
                print(_format("send: {0!A}", strng))
            blocksize = 8192
            if hasattr(strng, 'read') and not isinstance(strng, list):
                if self.debuglevel > 0:  # pylint: disable=no-member
                    print("sendIng a read()able")
                data = strng.read(blocksize)
                while data:
                    # pylint: disable=no-member
                    self.sock.sendall(_ensure_bytes(data))
                    data = strng.read(blocksize)
            else:
                # For unknown reasons, the pylint disable must be on same line:
                self.sock.sendall(_ensure_bytes(strng))  # noqa: E501 pylint: disable=no-member
Esempio n. 3
0
        def send(self, strng):
            """ Same as httplib.HTTPConnection.send(), except we don't
            check for sigpipe and close the connection.  If the connection
            gets closed, getresponse() fails.
            """

            if self.sock is None:
                if self.auto_open:
                    self.connect()
                else:
                    raise httplib.NotConnected()
            strng = _ensure_bytes(strng)
            if self.debuglevel > 0:
                print("send: %r" % strng)
            self.sock.sendall(strng)