def __init__(self, url=None, authority=None, scheme=None, host=None, port=None, #username=None, #password=None, path=None, query=None, query_string=None, fragment=None, verbatim=False, **kwargs ): url = url or '' # Split the url into scheme, port, host, query and path _scheme, netloc, self.path, _query_string, self.fragment = lib.urlsplit(url, True) # Create a netlocation object self.authority = authority or self.Authority(host or netloc, scheme=_scheme or scheme, port=port) # Override path if explicitly passed if path is not None: self.path = path # Override fragment if explicitly passed if fragment is not None: self.fragment = fragment # Create the query dictionary, flag wether to encode parameters # verbatim self.query = Query(verbatim=verbatim) # Populate it from parameters with following precedence (least first): # 1. `url` if _query_string is not None: self.query.update(lib.parse_qsl(_query_string)) # 2. `query_string` if query_string is not None: self.query.update(lib.parse_qsl(query_string)) # 3. `query` if query is not None: self.query.update(query) # 4. `kwargs self.query.update(kwargs)
def __init__(self, host='', port=None, scheme=None, #username=None, #password=None, ): # Split the url into scheme, port, host, query and path _scheme, netloc, _, _, _ = lib.urlsplit(host, True) # Set the connection on self to extract parameters and enable requests. # split the netlocation into userinfo and hostinfo userinfo, _, hostinfo = netloc.rpartition('@') #_username, _, _password = userinfo.partition(':') _host, _, _port = hostinfo.partition(':') self.scheme = scheme or _scheme or 'http' self.host = _host #XXX automatic port for default schemes could be desirable self.port = port or _port