
    @6iL                     n    d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZ  G d de      Zy	)
   )urlparse)Netloc)URLPathpath_encodepath_decode)DEFAULT_PORTS)QueryString)	text_typeuc                      e Zd ZdZd Zed        Zed        Zd Z	ed        Z
d Zed        Zd	 Zd
 Zed        Zd Zd Zed        Zd Zed        Zd Zd Zed        Zd Zd Zed        Zed        Zd Zed        Zed        Zed        Zd Z d Z!ed        Z"d Z#d  Z$ed!        Z%ed"        Z&ed#        Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.ed+        Z/d, Z0d- Z1d. Z2d/ Z3y0)1	URLObjecta  
    A URL.

    This class contains properties and methods for accessing and modifying the
    constituent components of a URL. :class:`URLObject` instances are
    immutable, as they derive from the built-in ``unicode``, and therefore all
    methods return *new* objects; you need to consider this when using
    :class:`URLObject` in your own code.

    >>> from urlobject import URLObject
    >>> u = URLObject("http://www.google.com/")
    >>> print(u)
    http://www.google.com/

    URL objects feature properties for directly accessing different parts of
    the URL: :attr:`.scheme`, :attr:`.netloc`, :attr:`.username`,
    :attr:`.password`, :attr:`.hostname`, :attr:`.port`, :attr:`.path`,
    :attr:`.query` and :attr:`.fragment`.

    All of these have a ``with_*`` method for adding/replacing them, and some
    have a ``without_*`` method for removing them altogether. The query string
    and path also have a variety of methods for doing more fine-grained
    inspection and manipulation.
    c                 2    t        d      t        |       fz  S )NzURLObject(%r))r   r
   selfs    V/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/urlobject/urlobject.py__repr__zURLObject.__repr__#   s    !Yt_$666    c                    t        j                  |      }|j                  j                  d      j	                  d      }t        |j                  j                  d      d      }t        |j                  j                  d      d      }t        |j                  j                  d      d      }|j                  ||||      } | t        j                  |            S )	u  
        Create a URL from an IRI, which may have non-ascii text it.

        This is probably how you should construct a URLObject if the input is
        from a user, since users tend to type addresses using their native
        character sets.

        The domain name will be encoded as per IDNA, and the whole IRI will be
        encoded to UTF-8 and URL-escaped, as per RFC 3987. The IRI is not
        checked for conformance with the IRI specification, so this may still
        accept invalid IRIs and produce invalid URLs.

        Beyond the IRI encoding rules, this also URL-quotes all special
        characters, so that a space character is replaced by %20, for example.
        The % character is *not* quoted, because users often copy/paste
        addresses that are already quoted, and we should not double-quote it.

        >>> print(URLObject.from_iri(u('https://éxample.com/påth')))
        https://xn--xample-9ua.com/p%C3%A5th
        idnaasciizutf-8z/%;)safez=&%%)netlocpathqueryfragment)r   urlsplitr   encodedecoder   r   r   r   _replace
urlunsplit)clsirisplitr   r   r   r   new_componentss           r   from_irizURLObject.from_iri&   s    0 !!#&$$V,33G<5::,,W5EBEKK..w7eDu~~44W=CHv-1.319 ( *
 8&&~677r   c                 @    t        j                  |       j                  S )zo
        This URL's scheme.

        >>> print(URLObject("http://www.google.com").scheme)
        http
        )r   r   schemer   s    r   r(   zURLObject.schemeJ   s       &---r   c                 &    | j                  |      S )a  
        Add or replace this URL's :attr:`.scheme`.

        >>> print(URLObject("http://www.google.com").with_scheme("ftp"))
        ftp://www.google.com
        >>> print(URLObject("//www.google.com").with_scheme("https"))
        https://www.google.com
        )r(   _URLObject__replace)r   r(   s     r   with_schemezURLObject.with_schemeT   s     ~~V~,,r   c                 R    t        t        j                  |       j                        S )a  
        The full network location of this URL.

        This value incorporates :attr:`.username`, :attr:`.password`,
        :attr:`.hostname` and :attr:`.port`.

        >>> print(URLObject("http://user:pass@www.google.com").netloc)
        user:pass@www.google.com
        )r   r   r   r   r   s    r   r   zURLObject.netloc_   s      h''-4455r   c                 &    | j                  |      S )z
        Add or replace this URL's :attr:`.netloc`.

        >>> print(URLObject("http://www.google.com/a/b/c").with_netloc("www.amazon.com"))
        http://www.amazon.com/a/b/c
        )r   r*   )r   r   s     r   with_netloczURLObject.with_netlocl   s     ~~V~,,r   c                 .    | j                   j                  S )z
        This URL's username, if any.

        >>> print(URLObject("http://user@www.google.com").username)
        user
        >>> print(URLObject("http://www.google.com").username)
        None
        )r   usernamer   s    r   r1   zURLObject.usernameu        {{###r   c                 V    | j                  | j                  j                  |            S )z
        Add or replace this URL's :attr:`.username`.

        >>> print(URLObject("http://user@www.google.com").with_username("user2"))
        http://user2@www.google.com
        )r/   r   with_username)r   r1   s     r   r4   zURLObject.with_username   $      9 9( CDDr   c                 T    | j                  | j                  j                               S )z
        Remove this URL's :attr:`.username`.

        >>> print(URLObject("http://user@www.google.com/").without_username())
        http://www.google.com/
        )r/   r   without_usernamer   s    r   r7   zURLObject.without_username   "      < < >??r   c                 .    | j                   j                  S )z
        This URL's password, if any.

        >>> print(URLObject("http://user:somepassword@www.google.com").password)
        somepassword
        >>> print(URLObject("http://user@www.google.com").password)
        None
        )r   passwordr   s    r   r:   zURLObject.password   r2   r   c                 V    | j                  | j                  j                  |            S )z
        Add or replace this URL's :attr:`.password`.

        >>> print(URLObject("http://user:somepassword@www.google.com").with_password("passwd"))
        http://user:passwd@www.google.com
        )r/   r   with_password)r   r:   s     r   r<   zURLObject.with_password   r5   r   c                 T    | j                  | j                  j                               S )z
        Remove this URL's :attr:`.password`.

        >>> print(URLObject("http://user:pwd@www.google.com").without_password())
        http://user@www.google.com
        )r/   r   without_passwordr   s    r   r>   zURLObject.without_password   r8   r   c                 .    | j                   j                  S )z}
        This URL's hostname.

        >>> print(URLObject("http://www.google.com").hostname)
        www.google.com
        )r   hostnamer   s    r   r@   zURLObject.hostname   s     {{###r   c                 V    | j                  | j                  j                  |            S )z
        Add or replace this URL's :attr:`.hostname`.

        >>> print(URLObject("http://www.google.com/a/b/c").with_hostname("cdn.amazon.com"))
        http://cdn.amazon.com/a/b/c
        )r/   r   with_hostname)r   r@   s     r   rB   zURLObject.with_hostname   r5   r   c                 .    | j                   j                  S )z
        This URL's port number, or ``None``.

        >>> URLObject("http://www.google.com:8080").port
        8080
        >>> print(URLObject("http://www.google.com").port)
        None
        )r   portr   s    r   rD   zURLObject.port   s     {{r   c                 V    | j                  | j                  j                  |            S )z
        Add or replace this URL's :attr:`.port`.

        >>> print(URLObject("http://www.google.com/a/b/c").with_port(8080))
        http://www.google.com:8080/a/b/c
        )r/   r   	with_portr   rD   s     r   rF   zURLObject.with_port   s$      5 5d ;<<r   c                 T    | j                  | j                  j                               S )z
        Remove this URL's :attr:`.port`.

        >>> print(URLObject("http://www.google.com:8080/a/b/c").without_port())
        http://www.google.com/a/b/c
        )r/   r   without_portr   s    r   rI   zURLObject.without_port   "      8 8 :;;r   c                 .    | j                   j                  S )a>  
        The username and password of this URL as a 2-tuple.

        >>> URLObject("http://user:password@www.google.com").auth
        ('user', 'password')
        >>> URLObject("http://user@www.google.com").auth
        ('user', None)
        >>> URLObject("http://www.google.com").auth
        (None, None)
        )r   authr   s    r   rL   zURLObject.auth   s     {{r   c                 R    | j                   | j                  j                  |       S )a  
        Add or replace this URL's :attr:`.username` and :attr:`.password`.

        With two arguments, this method adds/replaces both username and
        password. With one argument, it adds/replaces the username and removes
        any password.

        >>> print(URLObject("http://user:password@www.google.com").with_auth("otheruser", "otherpassword"))
        http://otheruser:otherpassword@www.google.com
        >>> print(URLObject("http://www.google.com").with_auth("user"))
        http://user@www.google.com
        )r/   r   	with_auth)r   rL   s     r   rN   zURLObject.with_auth   s'      5 5 5t <==r   c                 T    | j                  | j                  j                               S )z
        Remove any :attr:`.username` and :attr:`.password` on this URL.

        >>> print(URLObject("http://user:password@www.google.com/a/b/c").without_auth())
        http://www.google.com/a/b/c
        )r/   r   without_authr   s    r   rP   zURLObject.without_auth   rJ   r   c                     t        j                  |       j                  }||S t        j                  | j
                        S )a  
        The destination port number for this URL.

        If no port number is explicitly given in the URL, this will return the
        default port number for the scheme if one is known, or ``None``. The
        mapping of schemes to default ports is defined in
        :const:`urlobject.ports.DEFAULT_PORTS`.

        For URLs *with* explicit port numbers, this just returns the value of
        :attr:`.port`.

        >>> URLObject("https://www.google.com").default_port
        443
        >>> URLObject("http://www.google.com").default_port
        80
        >>> URLObject("http://www.google.com:126").default_port
        126
        )r   r   rD   r   getr(   rG   s     r   default_portzURLObject.default_port  s:    (   &++K  --r   c                 R    t        t        j                  |       j                        S )z
        This URL's path.

        >>> print(URLObject("http://www.google.com/a/b/c").path)
        /a/b/c
        >>> print(URLObject("http://www.google.com").path)
        <BLANKLINE>
        )r   r   r   r   r   s    r   r   zURLObject.path!  s      x((.3344r   c                 &    | j                  |      S )z
        Add or replace this URL's :attr:`.path`.

        >>> print(URLObject("http://www.google.com/a/b/c").with_path("c/b/a"))
        http://www.google.com/c/b/a
        )r   r*   )r   r   s     r   	with_pathzURLObject.with_path-  s     ~~4~((r   c                 $    | j                  d      S )z
        The root node of this URL.

        This is just a synonym for ``url.with_path('/')``.

        >>> print(URLObject("http://www.google.com/a/b/c").root)
        http://www.google.com/
        /)rV   r   s    r   rootzURLObject.root6  s     ~~c""r   c                 L    | j                  | j                  j                        S )z
        The direct parent node of this URL.

        >>> print(URLObject("http://www.google.com/a/b/c").parent)
        http://www.google.com/a/b/
        >>> print(URLObject("http://www.google.com/a/b/").parent)
        http://www.google.com/a/
        )rV   r   parentr   s    r   r[   zURLObject.parentB  s     ~~dii..//r   c                 .    | j                   j                  S )a  
        Whether this URL's :attr:`.path` is a leaf node or not.

        A leaf node is simply one without a trailing slash. Leaf-ness affects
        things like relative URL resolution (c.f. :meth:`.relative`) and
        server-side routing.

        >>> URLObject("http://www.google.com/a/b/c").is_leaf
        True
        >>> URLObject('http://www.google.com/a/').is_leaf
        False
        >>> URLObject('http://www.google.com').is_leaf
        False
        )r   is_leafr   s    r   r]   zURLObject.is_leafN  s      yy   r   c                 V    | j                  | j                  j                  |            S )zu
        >>> print(URLObject("http://www.google.com").add_path_segment("a"))
        http://www.google.com/a
        )rV   r   add_segment)r   segments     r   add_path_segmentzURLObject.add_path_segment`  s"    
 ~~dii33G<==r   c                 V    | j                  | j                  j                  |            S )zu
        >>> print(URLObject("http://www.google.com").add_path("a/b/c"))
        http://www.google.com/a/b/c
        )rV   r   add)r   partial_paths     r   add_pathzURLObject.add_pathg  s     
 ~~diimmL9::r   c                 R    t        t        j                  |       j                        S )z
        This URL's query string.

        >>> print(URLObject("http://www.google.com").query)
        <BLANKLINE>
        >>> print(URLObject("http://www.google.com?a=b").query)
        a=b
        )r	   r   r   r   r   s    r   r   zURLObject.queryn  s      8,,T28899r   c                 &    | j                  |      S )z
        Add or replace this URL's :attr:`.query` string.

        >>> print(URLObject("http://www.google.com").with_query("a=b"))
        http://www.google.com?a=b
        r   r*   )r   r   s     r   
with_queryzURLObject.with_queryz  s     ~~E~**r   c                 &    | j                  d      S )z
        Remove this URL's :attr:`.query` string.

        >>> print(URLObject("http://www.google.com?a=b&c=d").without_query())
        http://www.google.com
         rh   r*   r   s    r   without_queryzURLObject.without_query  s     ~~B~''r   c                 .    | j                   j                  S )a  
        This URL's :attr:`.query` as a list of name/value pairs.

        This attribute is read-only. Changes you make to the list will not
        propagate back to the URL.

        >>> URLObject("http://www.google.com?a=b&c=d").query_list
        [('a', 'b'), ('c', 'd')]
        )r   listr   s    r   
query_listzURLObject.query_list  s     zzr   c                 .    | j                   j                  S )a  
        This URL's :attr:`.query` as a dict mapping names to values.

        Each name will have only its last value associated with it. For all the
        values for a given key, see :attr:`.query_multi_dict`.

        >>> dictsort(URLObject("http://www.google.com?a=b&c=d").query_dict)
        {'a': 'b', 'c': 'd'}
        >>> dictsort(URLObject("http://www.google.com?a=b&a=c").query_dict)
        {'a': 'c'}
        )r   dictr   s    r   
query_dictzURLObject.query_dict  s     zzr   c                 .    | j                   j                  S )a  
        This URL's :attr:`.query` as a dict mapping names to lists of values.

        All values associated with a given name will be represented, in order,
        in that name's list.

        >>> dictsort(URLObject("http://www.google.com?a=b&c=d").query_multi_dict)
        {'a': ['b'], 'c': ['d']}
        >>> dictsort(URLObject("http://www.google.com?a=b&a=c").query_multi_dict)
        {'a': ['b', 'c']}
        )r   
multi_dictr   s    r   query_multi_dictzURLObject.query_multi_dict  s     zz$$$r   c                 X    | j                  | j                  j                  ||            S )a  
        Add a single query parameter.

        You can ``add`` several query parameters with the same name to a URL.

        >>> print(URLObject("http://www.google.com").add_query_param("a", "b"))
        http://www.google.com?a=b
        >>> print(URLObject("http://www.google.com").add_query_param("a", "b").add_query_param("a", "c"))
        http://www.google.com?a=b&a=c
        )ri   r   	add_paramr   namevalues      r   add_query_paramzURLObject.add_query_param  s$     tzz33D%@AAr   c                 X    | j                   | j                  j                  |i |      S )a  
        Add multiple query parameters.

        Accepts anything you would normally pass to ``dict()``: iterables of
        name/value pairs, keyword arguments and dictionary objects.

        >>> print(URLObject("http://www.google.com").add_query_params([('a', 'b'), ('c', 'd')]))
        http://www.google.com?a=b&c=d
        >>> print(URLObject("http://www.google.com").add_query_params(a="b"))
        http://www.google.com?a=b
        )ri   r   
add_paramsr   argskwargss      r   add_query_paramszURLObject.add_query_params  *     4tzz44dEfEFFr   c                 X    | j                  | j                  j                  ||            S )z
        Set a single query parameter, overriding it if it exists already.

        >>> print(URLObject("http://www.google.com?a=b&c=d").set_query_param("a", "z"))
        http://www.google.com?c=d&a=z
        )ri   r   	set_paramrx   s      r   set_query_paramzURLObject.set_query_param  s$     tzz33D%@AAr   c                 X    | j                   | j                  j                  |i |      S )a  
        Set query parameters, overriding existing ones.

        Accepts anything you would normally pass to ``dict()``: iterables of
        name/value pairs, keyword arguments and dictionary objects.

        >>> print(URLObject("http://www.google.com?a=b&c=d").set_query_params([('a', 'z'), ('d', 'e')]))
        http://www.google.com?c=d&a=z&d=e
        >>> print(URLObject("http://www.google.com?a=b").set_query_params(a="z"))
        http://www.google.com?a=z
        )ri   r   
set_paramsr~   s      r   set_query_paramszURLObject.set_query_params  r   r   c                 V    | j                  | j                  j                  |            S )z
        Remove any and all query parameters with the given name from the URL.

        >>> print(URLObject("http://www.google.com?a=b&c=d&c=e").del_query_param("c"))
        http://www.google.com?a=b
        )ri   r   	del_param)r   ry   s     r   del_query_paramzURLObject.del_query_param  s"     tzz33D9::r   c                 V    | j                  | j                  j                  |            S )z
        Remove multiple query params from the URL.

        >>> print(URLObject("http://www.google.com?a=b&c=d&d=e").del_query_params(["c", "d"]))
        http://www.google.com?a=b
        )ri   r   
del_params)r   paramss     r   del_query_paramszURLObject.del_query_params  s"     tzz44V<==r   c                 X    | j                  | j                  j                  ||            S )z
        Remove any and all query parameters with the given name/value pair from
        the URL.

        >>> print(URLObject("http://www.google.com?a=b&a=c&a=d").del_query_param_value("a", "c"))
        http://www.google.com?a=b&a=d
        )ri   r   del_param_valuerx   s      r   del_query_param_valuezURLObject.del_query_param_value  s$     tzz99$FGGr   c                 R    t        t        j                  |       j                        S )z
        This URL's fragment.

        >>> print(URLObject("http://www.google.com/a/b/c#fragment").fragment)
        fragment
        )r   r   r   r   r   s    r   r   zURLObject.fragment  s      8,,T2;;<<r   c                 8    | j                  t        |            S )z
        Add or replace this URL's :attr:`.fragment`.

        >>> print(URLObject("http://www.google.com/a/b/c#fragment").with_fragment("new_fragment"))
        http://www.google.com/a/b/c#new_fragment
        r   )r+   r   )r   r   s     r   with_fragmentzURLObject.with_fragment  s     ~~{8'<~==r   c                 &    | j                  d      S )z
        Remove this URL's :attr:`.fragment`.

        >>> print(URLObject("http://www.google.com/a/b/c#fragment").without_fragment())
        http://www.google.com/a/b/c
        rk   r   r*   r   s    r   without_fragmentzURLObject.without_fragment  s     ~~r~**r   c                 (    t        |       |      }|j                  r|S |j                  r|j                  | j                        S |j                  rf|j                  | j                        j                  | j                        j                  | j                  j                  |j                              S |j                  rM|j                  | j                        j                  | j                        j                  | j                        S |j                  rf|j                  | j                        j                  | j                        j                  | j                        j                  | j                        S | j                         S )a  
        Resolve another URL relative to this one.

        For example, if you have a browser currently pointing to
        ``http://www.google.com/a/b/c/``, then an HTML element like
        ``<a href="../d/e/f">`` would resolve to
        ``http://www.google.com/a/b/d/e/f`` using this function.

        >>> print(URLObject("http://www.google.com/a/b/c/").relative("../d/e/f"))
        http://www.google.com/a/b/d/e/f
        )typer(   r   r,   r   r/   rV   relativer   r   ri   r   )r   others     r   r   zURLObject.relative!  s    T
5!<<L\\$$T[[11ZZ$$T[[1==dkkJYtyy11%**=>?[[$$T[[1==dkkJYtyy)*^^$$T[[1==dkkJYtyy)**TZZ*@A $$&&r   c           	           t        |       t        j                   t        j                  |       j                  di |            S )z=Replace a field in the ``urlparse.SplitResult`` for this URL. )r   r   r!   r   r    )r   replaces     r   	__replacezURLObject.__replaceA  s@    tDz(--,Hd#,,7w79 : 	:r   N)4__name__
__module____qualname____doc__r   classmethodr&   propertyr(   r,   r   r/   r1   r4   r7   r:   r<   r>   r@   rB   rD   rF   rI   rL   rN   rP   rS   r   rV   rY   r[   r]   ra   re   r   ri   rl   ro   rr   ru   r{   r   r   r   r   r   r   r   r   r   r   r+   r   r   r   r   r      s   27 !8 !8F . .	- 
6 
6- 	$ 	$E@ 	$ 	$E@ $ $E 	  	 =<    >< . .0 	5 	5) 	# 	# 	0 	0 ! !">; 	: 	:+( 
 
   % %BGBG;>H = =>+'@:r   r   N)compatr   r   r   r   r   r   r   portsr   query_stringr	   sixr
   r   r   r   r   r   <module>r      s(      3 3   % |:	 |:r   