
    \d                          d Z ddlmZ ddlmZmZmZ ddl	m
Z d                    d  edd          D                       Zd	 Z G d
 d          ZdS )z(
L{URLPath}, a representation of a URL.
    )cast)quoteunquote
urlunsplit)URL    c                 R    g | ]$}t          |                              d           %S )ascii)chrencode).0xs     6lib/python3.11/site-packages/twisted/python/urlpath.py
<listcomp>r      s*    DDDc!ffmmG,,DDDr         c                 :    d| z   t          fdfd          S )a  
    Attriute declaration to preserve mutability on L{URLPath}.

    @param name: a public attribute name
    @type name: native L{str}

    @return: a descriptor which retrieves the private version of the attribute
        on get and calls rerealize on set.
    _c                 $    t          |           S N)getattr)selfprivateNames    r   <lambda>z"_rereconstituter.<locals>.<lambda>   s    WT;// r   c                     t          | t          |t                    r|n|                    d                    p|                                 S )Ncharmap)setattr
isinstancebytesr   _reconstitute)r   valuer   s     r   r   z"_rereconstituter.<locals>.<lambda>   sS    #E511Nu||I7N7N  $
 !!## r   )property)namer   s    @r   _rereconstituterr$      s@     *K////	
 	
 	
 	

 
 
r   c                   4   e Zd ZdZ	 ddZd Z ed          Z ed          Z ed          Z	 ed	          Z
 ed
          Zed             ZddZed             Zed             Zed             Zd ZddZddZddZddZd ZdefdZdefdZdS )URLPatha  
    A representation of a URL.

    @ivar scheme: The scheme of the URL (e.g. 'http').
    @type scheme: L{bytes}

    @ivar netloc: The network location ("host").
    @type netloc: L{bytes}

    @ivar path: The path on the network location.
    @type path: L{bytes}

    @ivar query: The query argument (the portion after ?  in the URL).
    @type query: L{bytes}

    @ivar fragment: The page fragment (the portion after # in the URL).
    @type fragment: L{bytes}
    r   	   localhostc                 |    |pd| _         || _        |pd| _        || _        || _        |                                  d S )Ns   http   /)_scheme_netloc_path_query	_fragmentr    )r   schemenetlocpathqueryfragments         r   __init__zURLPath.__init__=   sH     (\T
!r   c           	         t          t          | j        | j        | j        | j        | j        f          t                    }t          j	        |
                    d                              d                    | _        dS )zM
        Reconstitute this L{URLPath} from all its given attributes.
        safer
   N)urlquoter   r*   r+   r,   r-   r.   	_allascii_URLfromTextr   decode_url)r   urltexts     r   r    zURLPath._reconstituteG   ss     t|TZdnU  	
 
 
 M'.."9"9"@"@"I"IJJ			r   r/   r0   r1   r2   r3   c                    |                      |           }|                    |j        pdg          |_        |j        j                            d          |_        |j                                                            d          |_        t          |j        j        d          
                                                                                    d          |_        t          |j        j                  
                                                                                    d          dd         |_        |j        j                            d          |_        |S )	a  
        Reconstruct all the public instance variables of this L{URLPath} from
        its underlying L{_URL}.

        @param urlInstance: the object to base this L{URLPath} on.
        @type urlInstance: L{_URL}

        @return: a new L{URLPath}
         )r1   r
   T)r1   rooted)r2   r   N)__new__replacer1   r=   r/   r   r*   	authorityr+   r:   asURIasTextr,   r2   r-   r3   r.   )clsurlInstancer   s      r   _fromURLzURLPath._fromURLY   s    {{3''[-=-E"'FF	y'..w77y**,,33G<<dinT22288::AACCJJ7SS 	
 $)/22288::AACCJJ7SSUVUWUWX+227;;r   FTc                 T    | j         j        }d |rfddgfd|D             z   S )a  
        Split this URL's path into its components.

        @param unquote: whether to remove %-encoding from the returned strings.

        @param copy: (ignored, do not use)

        @return: The components of C{self.path}
        @rtype: L{list} of L{bytes}
        c                 ,    |                      d          S )Nr
   )r   )r   s    r   r   z"URLPath.pathList.<locals>.<lambda>{   s    188G,, r   c                 2     |t          |                     S r   )
urlunquote)r   ms     r   r   z"URLPath.pathList.<locals>.<lambda>}   s    :a==)9)9 r   r   c                 &    g | ]} |          S  rP   )r   segmentmappers     r   r   z$URLPath.pathList.<locals>.<listcomp>~   s!    @@@Gw@@@r   )r=   r1   )r   r   copysegmentsrR   s       @r   pathListzURLPath.pathListo   sN     9>,, 	:!'999Fu@@@@x@@@@@r   c                     t          |t                    st          d          |                     t	          j        |                    S )z
        Make a L{URLPath} from a L{str} or L{unicode}.

        @param url: A L{str} representation of a URL.
        @type url: L{str} or L{unicode}.

        @return: a new L{URLPath} derived from the given string.
        @rtype: L{URLPath}
        z'url' must be a str)r   str
ValueErrorrI   r:   r;   )klassurls     r   
fromStringzURLPath.fromString   sA     #s## 	42333~~dmC00111r   c                     t          |t                    st          d          t          |t                    }|                     |          S )z
        Make a L{URLPath} from a L{bytes}.

        @param url: A L{bytes} representation of a URL.
        @type url: L{bytes}

        @return: a new L{URLPath} derived from the given L{bytes}.
        @rtype: L{URLPath}

        @since: 15.4
        z'url' must be bytesr6   )r   r   rX   r8   r9   r[   )rY   rZ   quoteds      r   	fromByteszURLPath.fromBytes   sK     #u%% 	42333#I...'''r   c                 P    |                      |                                          S )a  
        Make a L{URLPath} from a L{twisted.web.http.Request}.

        @param request: A L{twisted.web.http.Request} to make the L{URLPath}
            from.

        @return: a new L{URLPath} derived from the given request.
        @rtype: L{URLPath}
        )r^   
prePathURL)rY   requests     r   fromRequestzURLPath.fromRequest   s"     w1133444r   c                 r    |                      |                    d|r| j        j        nd                    S )a  
        Return a modified copy of C{self} using C{newURL}, keeping the query
        string if C{keepQuery} is C{True}.

        @param newURL: a L{URL} to derive a new L{URLPath} from
        @type newURL: L{URL}

        @param keepQuery: if C{True}, preserve the query parameters from
            C{self} on the new L{URLPath}; if C{False}, give the new L{URLPath}
            no query parameters.
        @type keepQuery: L{bool}

        @return: a new L{URLPath}
        r@   rP   )r3   r2   )rI   rC   r=   r2   )r   newURL	keepQuerys      r   _modzURLPath._mod   s;     }}NNB.RdiooPRNSS
 
 	
r   c                     |                      | j                            |                    d                    |          S )a  
        Get the sibling of the current L{URLPath}.  A sibling is a file which
        is in the same directory as the current file.

        @param path: The path of the sibling.
        @type path: L{bytes}

        @param keepQuery: Whether to keep the query parameters on the returned
            L{URLPath}.
        @type keepQuery: L{bool}

        @return: a new L{URLPath}
        r
   )rf   r=   siblingr<   r   r1   re   s      r   rh   zURLPath.sibling   s4     yy**4;;w+?+?@@)LLLr   c                     |                      | j                            |                    d                    |          S )a)  
        Get the child of this L{URLPath}.

        @param path: The path of the child.
        @type path: L{bytes}

        @param keepQuery: Whether to keep the query parameters on the returned
            L{URLPath}.
        @type keepQuery: L{bool}

        @return: a new L{URLPath}
        r
   )rf   r=   childr<   ri   s      r   rk   zURLPath.child   s2     yyW)=)=>>	JJJr   c                 ^    |                      | j                            d          |          S )z
        Get the parent directory of this L{URLPath}.

        @param keepQuery: Whether to keep the query parameters on the returned
            L{URLPath}.
        @type keepQuery: L{bool}

        @return: a new L{URLPath}
        z..rf   r=   clickr   re   s     r   parentzURLPath.parent   s&     yy..	:::r   c                 ^    |                      | j                            d          |          S )z
        Get the current directory of this L{URLPath}.

        @param keepQuery: Whether to keep the query parameters on the returned
            L{URLPath}.
        @type keepQuery: L{bool}

        @return: a new L{URLPath}
        .rm   ro   s     r   herezURLPath.here   s&     yy--y999r   c                     |                      | j                            |                    d                              S )a7  
        Return a path which is the URL where a browser would presumably take
        you if you clicked on a link with an HREF as given.

        @param st: A relative URL, to be interpreted relative to C{self} as the
            base URL.
        @type st: L{bytes}

        @return: a new L{URLPath}
        r
   )rI   r=   rn   r<   )r   sts     r   rn   zURLPath.click   s0     }}TY__RYYw-?-?@@AAAr   returnc                 ~    t          t          | j                                                                                  S )z=
        The L{str} of a L{URLPath} is its URL text.
        )r   rW   r=   rE   rF   r   s    r   __str__zURLPath.__str__  s,     C**1133444r   c                 f    d                     | j        | j        | j        | j        | j                  S )z{
        The L{repr} of a L{URLPath} is an eval-able expression which will
        construct a similar L{URLPath}.
        zGURLPath(scheme={!r}, netloc={!r}, path={!r}, query={!r}, fragment={!r}))formatr/   r0   r1   r2   r3   rx   s    r   __repr__zURLPath.__repr__  s6    
 Y__KKIJM
 
 	
r   N)r   r'   r   r   r   )FT)F)__name__
__module____qualname____doc__r4   r    r$   r/   r0   r1   r2   r3   classmethodrI   rU   r[   r^   rb   rf   rh   rk   rp   rs   rn   rW   ry   r|   rP   r   r   r&   r&   )   s        ( NQ   
K 
K 
K h''Fh''FF##DW%%E
++H  [*A A A A" 2 2 [2 ( ( [(" 
5 
5 [
5
 
 
&M M M M K K K K
; 
; 
; 
;
: 
: 
: 
:B B B5 5 5 5 5
# 
 
 
 
 
 
r   r&   N)r   typingr   urllib.parser   r8   r   rM   r   	hyperlinkr   r:   joinranger9   r$   r&   rP   r   r   <module>r      s   
        M M M M M M M M M M ! ! ! ! ! !HHDDeeAsmmDDDEE	  0m
 m
 m
 m
 m
 m
 m
 m
 m
 m
r   