o
    ¯bÿ   ã                   @   sd   d Z ddlmZ ddlmZmZmZ ddl	m
Z d dd„ edd	ƒD ƒ¡Zd
d„ ZG dd„ dƒZdS )z(
L{URLPath}, a representation of a URL.
é    )Úcast)ÚquoteÚunquoteÚ
urlunsplit)ÚURLó    c                 C   s   g | ]	}t |ƒ d ¡‘qS )Úascii)ÚchrÚencode)Ú.0Úx© r   ú8/usr/lib/python3/dist-packages/twisted/python/urlpath.pyÚ
<listcomp>   s    r   é   é€   c                    s"   d|  ‰ t ‡ fdd„‡ fd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                    s
   t | ˆ ƒS ©N)Úgetattr©Úself©ÚprivateNamer   r   Ú<lambda>   ó   
 z"_rereconstituter.<locals>.<lambda>c                    s(   t | ˆ t|tƒr
|n| d¡ƒp|  ¡ S )NÚcharmap)ÚsetattrÚ
isinstanceÚbytesr
   Ú_reconstitute)r   Úvaluer   r   r   r      s   ý)Úproperty)Únamer   r   r   Ú_rereconstituter   s
   


þr#   c                   @   sÚ   e Zd ZdZ	d+dd„Zdd„ ZedƒZed	ƒZed
ƒZ	edƒZ
edƒZedd„ ƒZd,dd„Zedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zd-dd„Zd-dd„Zd-dd „Zd-d!d"„Zd#d$„ Zd%efd&d'„Zd%efd(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                 C   s2   |pd| _ || _|pd| _|| _|| _|  ¡  d S )Ns   httpó   /)Ú_schemeÚ_netlocÚ_pathÚ_queryÚ	_fragmentr   )r   ÚschemeÚnetlocÚpathÚqueryÚfragmentr   r   r   Ú__init__=   s   

zURLPath.__init__c                 C   s@   t t| j| j| j| j| jfƒtd�}t 	| 
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   Úurltextr   r   r   r   G   s   ÿüzURLPath._reconstituter,   r-   r.   r/   r0   c                 C   sœ   |   | ¡}|j|jpdgd�|_|jj d¡|_|j ¡  d¡|_t	|jjdd� 
¡  ¡  d¡|_t	|jjd� 
¡  ¡  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}
        Ú )r.   r   T)r.   Úrooted)r/   r   N)Ú__new__Úreplacer.   r9   r,   r
   r'   Ú	authorityr(   r6   ÚasURIÚasTextr)   r/   r*   r0   r+   )ÚclsÚurlInstancer   r   r   r   Ú_fromURLY   s   
ÿ&zURLPath._fromURLFTc                    s8   | j j}dd„ ‰ |rˆ fdd„‰ dg‡ fdd„|D ƒ 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                 S   s
   |   d¡S )Nr   )r
   )r   r   r   r   r   {   r   z"URLPath.pathList.<locals>.<lambda>c                 S   s   |t | ƒƒS r   )Ú
urlunquote)r   Úmr   r   r   r   }   s    r   c                    s   g | ]}ˆ |ƒ‘qS r   r   )r   Úsegment©Úmapperr   r   r   ~   s    z$URLPath.pathList.<locals>.<listcomp>)r9   r.   )r   r   ÚcopyÚsegmentsr   rH   r   ÚpathListo   s
   zURLPath.pathListc                 C   s"   t |tƒs	tdƒ‚|  t |¡¡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Ú
ValueErrorrD   r6   r7   )ÚklassÚurlr   r   r   Ú
fromString€   s   
zURLPath.fromStringc                 C   s(   t |tƒs	tdƒ‚t|td�}|  |¡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 bytesr2   )r   r   rN   r4   r5   rQ   )rO   rP   Úquotedr   r   r   Ú	fromBytes�   s   

zURLPath.fromBytesc                 C   s   |   | ¡ ¡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}
        )rS   Ú
prePathURL)rO   Úrequestr   r   r   ÚfromRequest¡   s   zURLPath.fromRequestc                 C   s&   |   |jd|r| jjd�¡S d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   )r0   r/   )rD   r>   r9   r/   )r   ÚnewURLÚ	keepQueryr   r   r   Ú_mod®   s
   ÿÿzURLPath._modc                 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   )rY   r9   Úsiblingr8   ©r   r.   rX   r   r   r   r[   Á   s   zURLPath.siblingc                 C   rZ   )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   )rY   r9   Úchildr8   r\   r   r   r   r]   Ñ   s   zURLPath.childc                 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..©rY   r9   Úclick©r   rX   r   r   r   Úparentà   ó   
zURLPath.parentc                 C   r^   )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}
        Ú.r_   ra   r   r   r   Úhereì   rc   zURLPath.herec                 C   s   |   | 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   )rD   r9   r`   r8   )r   Ústr   r   r   r`   ø   s   zURLPath.clickÚreturnc                 C   s   t t| j ¡  ¡ ƒS )z=
        The L{str} of a L{URLPath} is its URL text.
        )r   rM   r9   r@   rA   r   r   r   r   Ú__str__  s   zURLPath.__str__c                 C   s   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,   r-   r.   r/   r0   r   r   r   r   Ú__repr__  s   ûzURLPath.__repr__N)r   r%   r   r   r   )FT)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r1   r   r#   r,   r-   r.   r/   r0   ÚclassmethodrD   rL   rQ   rS   rV   rY   r[   r]   rb   re   r`   rM   rh   rj   r   r   r   r   r$   )   s6    
ÿ









r$   N)rn   Útypingr   Úurllib.parser   r4   r   rE   r   Ú	hyperlinkr   r6   ÚjoinÚranger5   r#   r$   r   r   r   r   Ú<module>   s   