
    Ϫf                          d Z ddlmZ ddlmZmZmZ ddl	m
Z dj                   edd      D  cg c]  }  e|       j                  d       c}       Zd	 Z G d
 d      Zyc c} w )z(
L{URLPath}, a representation of a URL.
    )cast)quoteunquote
urlunsplit)URL          asciic                 2    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    8/usr/lib/python3/dist-packages/twisted/python/urlpath.py<lambda>z"_rereconstituter.<locals>.<lambda>   s    WT;/ r   c                     t        | t        |t              r|n|j                  d            xs | j	                         S )Ncharmap)setattr
isinstancebytesencode_reconstitute)r   valuer   s     r   r   z"_rereconstituter.<locals>.<lambda>   s@    #E51u||I7N $
 !!# r   )property)namer   s    @r   _rereconstituterr      s#     *K/	

 
r   c                       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y)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}
    c                 z    |xs d| _         || _        |xs d| _        || _        || _        | j                          y )Ns   http   /)_scheme_netloc_path_query	_fragmentr   )r   schemenetlocpathqueryfragments         r   __init__zURLPath.__init__=   s<     (\T
!r   c           	         t        t        | j                  | j                  | j                  | j
                  | j                  f      t              }t        j                  |j                  d      j                  d            | _        y)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   sc     t||TZZdnnU 	
 MM'.."9"@"@"IJ	r   r)   r*   r+   r,   r-   c                    | j                  |       }|j                  |j                  xs dg      |_        |j                  j                  j                  d      |_        |j                  j                         j                  d      |_        t        |j                  j                  d      j                         j                         j                  d      |_        t        |j                  j                        j                         j                         j                  d      dd |_        |j                  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}
         )r+   r   T)r+   rooted)r,   r	   N)__new__replacer+   r7   r)   r   r$   	authorityr%   r4   asURIasTextr&   r,   r'   r-   r(   )clsurlInstancer   s      r   _fromURLzURLPath._fromURLY   s    {{3''[-=-=-E"'F	yy''..w7yy**,33G<diinnT288:AACJJ7S 	
 $))//288:AACJJ7SUVUWX++227;r   c                     | j                   j                  }d }|r|fd}dg|D cg c]
  } ||       c}z   S c c}w )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                 $    | j                  d      S )Nr   )r   xs    r   r   z"URLPath.pathList.<locals>.<lambda>{   s    188G, r   c                 $     |t        |             S r   )
urlunquote)rG   ms     r   r   z"URLPath.pathList.<locals>.<lambda>}   s    :a=)9 r   r   )r7   r+   )r   r   copysegmentsmappersegments         r   pathListzURLPath.pathListo   s@     99>>,!'9Fux@Gw@@@@s   ;c                     t        |t              st        d      | j                  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
ValueErrorrC   r4   r5   )klassurls     r   
fromStringzURLPath.fromString   s2     #s#233~~dmmC011r   c                 |    t        |t              st        d      t        |t              }| j                  |      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 bytesr0   )r   r   rR   r2   r3   rU   )rS   rT   quoteds      r   	fromByteszURLPath.fromBytes   s7     #u%233#I.''r   c                 @    | j                  |j                               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}
        )rX   
prePathURL)rS   requests     r   fromRequestzURLPath.fromRequest   s     w11344r   c                     | j                  |j                  d|r| j                  j                              S 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:    )r-   r,   )rC   r=   r7   r,   )r   newURL	keepQuerys      r   _modzURLPath._mod   sA     }}NNBdiiooNS
 	
PRNS
 	
r   c                 v    | j                  | j                  j                  |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   )ra   r7   siblingr6   r   r+   r`   s      r   rc   zURLPath.sibling   s-     yy**4;;w+?@)LLr   c                 v    | j                  | j                  j                  |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   )ra   r7   childr6   rd   s      r   rf   zURLPath.child   s+     yyW)=>	JJr   c                 X    | j                  | j                  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..ra   r7   clickr   r`   s     r   parentzURLPath.parent   s"     yy.	::r   c                 X    | j                  | j                  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}
        .rh   rj   s     r   herezURLPath.here   s"     yy-y99r   c                 t    | j                  | j                  j                  |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   )rC   r7   ri   r6   )r   sts     r   ri   zURLPath.click   s)     }}TYY__RYYw-?@AAr   returnc                 n    t        t        | j                  j                         j	                               S )z=
        The L{str} of a L{URLPath} is its URL text.
        )r   rQ   r7   r?   r@   r   s    r   __str__zURLPath.__str__  s%     C*11344r   c                     dj                  | 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)   r*   r+   r,   r-   rs   s    r   __repr__zURLPath.__repr__  s;    
 Y__KKKKIIJJMM
 	
r   N)r   s	   localhostr   r   r   )FT)F)__name__
__module____qualname____doc__r.   r   r   r)   r*   r+   r,   r-   classmethodrC   rO   rU   rX   r\   ra   rc   rf   rk   rn   ri   rQ   rt   rw   r^   r   r   r!   r!   )   s    ( NQ
K h'Fh'FF#DW%E
+H *A" 2 2 ( (" 
5 
5
&M K
;
:B5 5
# 
r   r!   N)r{   typingr   urllib.parser   r2   r   rI   r   	hyperlinkr   r4   joinrangechrr   r3   r   r!   rF   s   0r   <module>r      s[   
  M M !HHeAsmDc!fmmG,DE	0m
 m
7 Es   A"