Пример #1
0
    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)
Пример #2
0
 def __init__(self, mapping=None, verbatim=False, sorted=False, **kwargs):
     if isinstance(mapping, (str, bytes)):
         mapping = lib.parse_qsl(mapping)
     super().__init__(mapping)
     self.update(kwargs)
     self.use_verbatim = verbatim
     self.sorted = sorted