parameters: (self, connection_factory, url, data)
docstring: Make an HTTP connection using connection_class.
  
          This is an internal method that should be called from
          open_http() or open_https().
  
          Arguments:
          - connection_factory should take a host name and return an
            HTTPConnection instance.
          - url is the url to retrieval or a host, relative-path pair.
          - data is payload for a POST request or None.
docstring_summary: Make an HTTP connection using connection_class.
docstring_tokens: Make an HTTP connection using connection_class .
function: def _open_generic_http(self, connection_factory, url, data):
          """Make an HTTP connection using connection_class.
  
          This is an internal method that should be called from
          open_http() or open_https().
  
          Arguments:
          - connection_factory should take a host name and return an
            HTTPConnection instance.
          - url is the url to retrieval or a host, relative-path pair.
          - data is payload for a POST request or None.
          """
  
          user_passwd = None
          proxy_passwd= None
          if isinstance(url, str):
              host, selector = splithost(url)
              if host:
                  user_passwd, host = splituser(host)
                  host = unquote(host)
              realhost = host
          else:
              host, selector = url
              # check whether the proxy contains authorization information
              proxy_passwd, host = splituser(host)
              # now we proceed with the url we want to obtain
              urltype, rest = splittype(selector)
              url = rest
              user_passwd = None
              if urltype.lower() != 'http':
                  realhost = None
              else:
                  realhost, rest = splithost(rest)
                  if realhost:
                      user_passwd, realhost = splituser(realhost)
                  if user_passwd:
                      selector = "%s://%s%s" % (urltype, realhost, rest)
                  if proxy_bypass(realhost):
                      host = realhost
  
          if not host: raise OSError('http error', 'no host given')
  
          if proxy_passwd:
              proxy_passwd = unquote(proxy_passwd)
              proxy_auth = base64.b64encode(proxy_passwd.encode()).decode('ascii')
          else:
              proxy_auth = None
  
          if user_passwd:
              user_passwd = unquote(user_passwd)
              auth = base64.b64encode(user_passwd.encode()).decode('ascii')
          else:
              auth = None
          http_conn = connection_factory(host)
          headers = {}
          if proxy_auth:
              headers["Proxy-Authorization"] = "Basic %s" % proxy_auth
          if auth:
              headers["Authorization"] =  "Basic %s" % auth
          if realhost:
              headers["Host"] = realhost
  
          # Add Connection:close as we don't support persistent connections yet.
          # This helps in closing the socket and avoiding ResourceWarning
  
          headers["Connection"] = "close"
  
          for header, value in self.addheaders:
              headers[header] = value
  
          if data is not None:
              headers["Content-Type"] = "application/x-www-form-urlencoded"
              http_conn.request("POST", selector, data, headers)
          else:
              http_conn.request("GET", selector, headers=headers)
  
          try:
              response = http_conn.getresponse()
          except http.client.BadStatusLine:
              # something went wrong with the HTTP status line
              raise URLError("http protocol error: bad status line")
  
          # According to RFC 2616, "2xx" code indicates that the client's
          # request was successfully received, understood, and accepted.
          if 200 <= response.status < 300:
              return addinfourl(response, response.msg, "http:" + url,
                                response.status)
          else:
              return self.http_error(
                  url, response.fp,
                  response.status, response.reason, response.msg, data)
function_tokens: def _open_generic_http ( self , connection_factory , url , data ) : user_passwd = None proxy_passwd = None if isinstance ( url , str ) : host , selector = splithost ( url ) if host : user_passwd , host = splituser ( host ) host = unquote ( host ) realhost = host else : host , selector = url # check whether the proxy contains authorization information proxy_passwd , host = splituser ( host ) # now we proceed with the url we want to obtain urltype , rest = splittype ( selector ) url = rest user_passwd = None if urltype . lower ( ) != 'http' : realhost = None else : realhost , rest = splithost ( rest ) if realhost : user_passwd , realhost = splituser ( realhost ) if user_passwd : selector = "%s://%s%s" % ( urltype , realhost , rest ) if proxy_bypass ( realhost ) : host = realhost if not host : raise OSError ( 'http error' , 'no host given' ) if proxy_passwd : proxy_passwd = unquote ( proxy_passwd ) proxy_auth = base64 . b64encode ( proxy_passwd . encode ( ) ) . decode ( 'ascii' ) else : proxy_auth = None if user_passwd : user_passwd = unquote ( user_passwd ) auth = base64 . b64encode ( user_passwd . encode ( ) ) . decode ( 'ascii' ) else : auth = None http_conn = connection_factory ( host ) headers = { } if proxy_auth : headers [ "Proxy-Authorization" ] = "Basic %s" % proxy_auth if auth : headers [ "Authorization" ] = "Basic %s" % auth if realhost : headers [ "Host" ] = realhost # Add Connection:close as we don't support persistent connections yet. # This helps in closing the socket and avoiding ResourceWarning headers [ "Connection" ] = "close" for header , value in self . addheaders : headers [ header ] = value if data is not None : headers [ "Content-Type" ] = "application/x-www-form-urlencoded" http_conn . request ( "POST" , selector , data , headers ) else : http_conn . request ( "GET" , selector , headers = headers ) try : response = http_conn . getresponse ( ) except http . client . BadStatusLine : # something went wrong with the HTTP status line raise URLError ( "http protocol error: bad status line" ) # According to RFC 2616, "2xx" code indicates that the client's # request was successfully received, understood, and accepted. if 200 <= response . status < 300 : return addinfourl ( response , response . msg , "http:" + url , response . status ) else : return self . http_error ( url , response . fp , response . status , response . reason , response . msg , data )