(self, http_class, req, **http_conn_args)
return r
Return an HTTPResponse object for the request, using http_class.

        http_class must implement the HTTPConnection API from http.client.
Return an HTTPResponse object for the request, using http_class.
Return an HTTPResponse object for the request using http_class .
def do_open(self, http_class, req, **http_conn_args):
        """Return an HTTPResponse object for the request, using http_class.

        http_class must implement the HTTPConnection API from http.client.
        """
        host = req.host
        if not host:
            raise URLError('no host given')

        # will parse host:port
        h = http_class(host, timeout=req.timeout, **http_conn_args)
        h.set_debuglevel(self._debuglevel)

        headers = dict(req.unredirected_hdrs)
        headers.update({k: v for k, v in req.headers.items()
                        if k not in headers})

        # TODO(jhylton): Should this be redesigned to handle
        # persistent connections?

        # We want to make an HTTP/1.1 request, but the addinfourl
        # class isn't prepared to deal with a persistent connection.
        # It will try to read all remaining data from the socket,
        # which will block while the server waits for the next request.
        # So make sure the connection gets closed after the (only)
        # request.
        headers["Connection"] = "close"
        headers = {name.title(): val for name, val in headers.items()}

        if req._tunnel_host:
            tunnel_headers = {}
            proxy_auth_hdr = "Proxy-Authorization"
            if proxy_auth_hdr in headers:
                tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
                # Proxy-Authorization should not be sent to origin
                # server.
                del headers[proxy_auth_hdr]
            h.set_tunnel(req._tunnel_host, headers=tunnel_headers)

        try:
            try:
                h.request(req.get_method(), req.selector, req.data, headers,
                          encode_chunked=req.has_header('Transfer-encoding'))
            except OSError as err: # timeout error
                raise URLError(err)
            r = h.getresponse()
        except:
            h.close()
            raise

        # If the server does not send us a 'Connection: close' header,
        # HTTPConnection assumes the socket should be left open. Manually
        # mark the socket to be closed when this response object goes away.
        if h.sock:
            h.sock.close()
            h.sock = None

        r.url = req.get_full_url()
        # This line replaces the .msg attribute of the HTTPResponse
        # with .headers, because urllib clients expect the response to
        # have the reason in .msg.  It would be good to mark this
        # attribute is deprecated and get then to use info() or
        # .headers.
        r.msg = r.reason
        return r
def do_open ( self , http_class , req , * * http_conn_args ) : host = req . host if not host : raise URLError ( 'no host given' ) # will parse host:port h = http_class ( host , timeout = req . timeout , * * http_conn_args ) h . set_debuglevel ( self . _debuglevel ) headers = dict ( req . unredirected_hdrs ) headers . update ( { k : v for k , v in req . headers . items ( ) if k not in headers } ) # TODO(jhylton): Should this be redesigned to handle # persistent connections? # We want to make an HTTP/1.1 request, but the addinfourl # class isn't prepared to deal with a persistent connection. # It will try to read all remaining data from the socket, # which will block while the server waits for the next request. # So make sure the connection gets closed after the (only) # request. headers [ "Connection" ] = "close" headers = { name . title ( ) : val for name , val in headers . items ( ) } if req . _tunnel_host : tunnel_headers = { } proxy_auth_hdr = "Proxy-Authorization" if proxy_auth_hdr in headers : tunnel_headers [ proxy_auth_hdr ] = headers [ proxy_auth_hdr ] # Proxy-Authorization should not be sent to origin # server. del headers [ proxy_auth_hdr ] h . set_tunnel ( req . _tunnel_host , headers = tunnel_headers ) try : try : h . request ( req . get_method ( ) , req . selector , req . data , headers , encode_chunked = req . has_header ( 'Transfer-encoding' ) ) except OSError as err : # timeout error raise URLError ( err ) r = h . getresponse ( ) except : h . close ( ) raise # If the server does not send us a 'Connection: close' header, # HTTPConnection assumes the socket should be left open. Manually # mark the socket to be closed when this response object goes away. if h . sock : h . sock . close ( ) h . sock = None r . url = req . get_full_url ( ) # This line replaces the .msg attribute of the HTTPResponse # with .headers, because urllib clients expect the response to # have the reason in .msg.  It would be good to mark this # attribute is deprecated and get then to use info() or # .headers. r . msg = r . reason return r