o
     &zhzi  ã                   @   sÖ  d Z ddlZddlZddlZddlZddlZddlmZ dZdZ	dZ
dZe
e ZdZee ¡ ƒZd	d
d„ edƒD ƒiZdd„ eD ƒZdLdd„ZdMdd„ZG dd„ de dd¡ƒZG dd„ de dd¡ƒZG dd„ deƒZG dd„ deƒZd d!„ Zd"d#„ Zd$d%„ ZdNd'd(„Zd)d*„ Zd+d,„ Z d-d.„ Z!d/d0„ Z"d1d2„ Z#d3d4„ Z$e %d5¡Z&e %d6¡Z'e %d7¡Z(ed8 Z)eZ*ed9 Z+ed: Z,ed: Z-d;d<„ Z.d=d>„ Z/d?d@„ Z0dAdB„ Z1dCdD„ Z2dEdF„ Z3dGdH„ Z4									I	dOdJdK„Z5dS )PzÚRFC 3986 compliant, scheme-agnostic replacement for `urllib.parse`.

This module defines RFC 3986 compliant replacements for the most
commonly used functions of the Python Standard Library
:mod:`urllib.parse` module.

é    N)Ú	hexdigits)Ú
GEN_DELIMSÚRESERVEDÚ
SUB_DELIMSÚ
UNRESERVEDÚ	isabspathÚisabsuriÚ	isnetpathÚ	isrelpathÚ	issamedocÚisuriÚ
uricomposeÚ	uridecodeÚ	uridefragÚ	uriencodeÚurijoinÚurisplitÚ
uriunsplitz5.0.0z:/?#[]@z!$&'()*+,;=zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~ó    c                 C   s*   g | ]}|t v rt|gƒnd |  ¡ ‘qS )z%%%02X)Ú_unreservedÚbytesÚencode)Ú.0Úi© r   úL/var/www/html/kangema/venv/lib/python3.10/site-packages/uritools/__init__.pyÚ
<listcomp>B   s    ÿr   é   c                 C   s.   i | ]}t D ]}||  ¡ t || ¡“qqS r   )r   r   r   Úfromhex)r   ÚaÚbr   r   r   Ú
<dictcomp>G   s
    ÿÿr!   Ú úutf-8Ústrictc                 C   sŒ   t | tƒs|  ||¡} t |tƒs| d¡}zt| }W n! ty<   td dd… }|D ]	}t|gƒ||< q,|t|< Y nw d t|j| ƒ¡S )z(Encode a URI string or string component.Úasciir   N)Ú
isinstancer   r   Ú_encodedÚKeyErrorÚjoinÚmapÚ__getitem__)Ú	uristringÚsafeÚencodingÚerrorsÚencodedr   r   r   r   r   L   s   


ür   c                 C   s¢   t | tƒs|  |p
d|¡} |  d¡}|d g}|j}tj}|dd… D ]}|||dd… d|dd…  ƒƒ ||dd… ƒ q#|durLd |¡ ||¡S d |¡S )z(Decode a URI string or string component.r%   ó   %r   é   Né   r   )	r&   r   r   ÚsplitÚappendÚ_decodedÚgetr)   Údecode)r,   r.   r/   ÚpartsÚresultr5   r8   Úsr   r   r   r   \   s   


"
r   c                   @   s&   e Zd ZdZdZdd„ Zd
dd	„ZdS )ÚDefragResultz(Class to hold :func:`uridefrag` results.r   c                 C   s:   | j }|du r
| jS t|tƒr| jd | S | jd | S )z>Return the recombined version of the original URI as a string.Nó   #ú#)ÚfragmentÚurir&   r   )Úselfr?   r   r   r   Úgeturir   s   
zDefragResult.geturiNr#   r$   c                 C   s   | j }|durt|||ƒS |S )z€Return the decoded fragment identifier, or `default` if the
        original URI did not contain a fragment component.

        N©r?   r   ©rA   Údefaultr.   r/   r?   r   r   r   Úgetfragment|   s   zDefragResult.getfragment©Nr#   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rB   rF   r   r   r   r   r<   m   s
    
r<   zuri fragmentc                   @   sþ   e Zd ZdZdZedd„ ƒZedd„ ƒZedd„ ƒZd	d
„ Z	d8dd„Z
d9dd„Zd9dd„Zd:dd„Zd8dd„Zd;dd„Zd9dd„Zd<dd„Zd<dd „Zd9d!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd=d0d1„Zd2d3„ Zed4d5„ ƒZed6d7„ ƒZdS )>ÚSplitResultz,Base class to hold :func:`urisplit` results.r   c                 C   s0   | j }|d u r	d S | | j¡\}}}|r|S d S ©N)Ú	authorityÚ
rpartitionÚAT)rA   rO   ÚuserinfoÚpresentÚ_r   r   r   rR      s   zSplitResult.userinfoc                 C   sJ   | j }|d u r	d S | | j¡\}}}| | j¡\}}}| | j¡r#|S |S rN   )rO   rP   rQ   ÚCOLONÚlstripÚDIGITS)rA   rO   rT   ÚhostinfoÚhostÚportr   r   r   rY   š   s   zSplitResult.hostc                 C   s<   | j }|d u r	d S | | j¡\}}}|r| | j¡s|S d S rN   )rO   rP   rU   rV   rW   )rA   rO   rT   rS   rZ   r   r   r   rZ   ¦   s   zSplitResult.portc                 C   sŒ   | \}}}}}g }|dur|  || jg¡ |dur#|  | j| j|g¡ | |¡ |dur4|  | j|g¡ |dur@|  | j|g¡ | j |¡S )z[Return the re-combined version of the original URI reference as a
        string.

        N)ÚextendrU   ÚSLASHr5   ÚQUESTÚHASHÚEMPTYr)   )rA   ÚschemerO   ÚpathÚqueryr?   r:   r   r   r   rB   ±   s   
zSplitResult.geturiNc                 C   s2   | j }|du r	|S t|tƒr| d¡ ¡ S | ¡ S )z•Return the URI scheme in canonical (lowercase) form, or `default`
        if the original URI reference did not contain a scheme component.

        Nr%   )r`   r&   r   r8   Úlower)rA   rE   r`   r   r   r   Ú	getschemeÅ   s   
zSplitResult.getschemer#   r$   c                 C   sf   |du rd}nt |tjjƒstdƒ‚t|ƒdkrtdƒ‚|  |d ||¡|  |d |¡|  	|d ¡fS )	zvReturn the decoded userinfo, host and port subcomponents of the URI
        authority as a three-item tuple.

        N©NNNzInvalid default typeé   zInvalid default lengthr   r2   r3   )
r&   ÚcollectionsÚabcÚIterableÚ	TypeErrorÚlenÚ
ValueErrorÚgetuserinfoÚgethostÚgetport)rA   rE   r.   r/   r   r   r   ÚgetauthorityÒ   s   ýzSplitResult.getauthorityc                 C   ó   | j }|du r	|S t|||ƒS )z¥Return the decoded userinfo subcomponent of the URI authority, or
        `default` if the original URI reference did not contain a
        userinfo field.

        N)rR   r   )rA   rE   r.   r/   rR   r   r   r   rm   å   s   zSplitResult.getuserinfoc                 C   s¸   | j }|du s|s|dur|S | | j¡r$| | j¡r$|  |dd… ¡S | | j¡s0| | j¡r6td| ƒ‚zt|tƒrEt	 
| d¡¡W S t	 
|¡W S  ty[   t|d|ƒ ¡  Y S w )zÉReturn the decoded host subcomponent of the URI authority as a
        string or an :mod:`ipaddress` address object, or `default` if
        the original URI reference did not contain a host.

        Nr2   éÿÿÿÿzInvalid host %rr%   r#   )rY   Ú
startswithÚLBRACKETÚendswithÚRBRACKETÚ_SplitResult__parse_ip_literalrl   r&   r   Ú	ipaddressÚIPv4Addressr8   r   rc   )rA   rE   r/   rY   r   r   r   rn   ñ   s   
ÿzSplitResult.gethostc                 C   s   | j }|r	t|ƒS |S )z»Return the port subcomponent of the URI authority as an
        :class:`int`, or `default` if the original URI reference did
        not contain a port or if the port was empty.

        )rZ   Úint)rA   rE   rZ   r   r   r   ro     s   zSplitResult.getportc                 C   s   |   | j¡}t|||ƒS )z'Return the normalized decoded URI path.)Ú!_SplitResult__remove_dot_segmentsra   r   )rA   r.   r/   ra   r   r   r   Úgetpath  s   zSplitResult.getpathc                 C   rq   )z€Return the decoded query string, or `default` if the original URI
        reference did not contain a query component.

        N)rb   r   )rA   rE   r.   r/   rb   r   r   r   Úgetquery  ó   zSplitResult.getqueryú&c                 C   s4   t  t¡}|  |||¡D ]\}}||  |¡ q|S )a  Split the query component into individual `name=value` pairs
        separated by `sep` and return a dictionary of query variables.
        The dictionary keys are the unique query variable names and
        the values are lists of values for each name.

        )rg   ÚdefaultdictÚlistÚgetquerylistr5   )rA   Úsepr.   r/   ÚdictÚnameÚvaluer   r   r   Úgetquerydict#  s   
zSplitResult.getquerydictc           	         s´   ˆ j sg S t|tˆ j ƒƒrˆ j  |¡}nt|tƒr#ˆ j  | d¡¡}n	ˆ j  | d¡¡}g }‡ fdd„|D ƒD ] }t|d ||ƒ}|d rNt|d ||ƒ}nd}| ||f¡ q7|S )z—Split the query component into individual `name=value` pairs
        separated by `sep`, and return a list of `(name, value)`
        tuples.

        r%   c                    s   g | ]
}|r|  ˆ j¡‘qS r   )Ú	partitionÚEQ)r   Úqs©rA   r   r   r   >  s    z,SplitResult.getquerylist.<locals>.<listcomp>r   r2   r3   N)	rb   r&   Útyper4   r   r8   r   r   r5   )	rA   rƒ   r.   r/   ÚqslÚitemsr9   r…   r†   r   r‹   r   r‚   /  s   
zSplitResult.getquerylistc                 C   rq   )zŠReturn the decoded fragment identifier, or `default` if the
        original URI reference did not contain a fragment component.

        NrC   rD   r   r   r   rF   G  r~   zSplitResult.getfragmentc                 C   s
   | j duS )z&Return :const:`True` if this is a URI.N©r`   r‹   r   r   r   r   R  s   
zSplitResult.isuric                 C   s   | j duo	| jdu S )z0Return :const:`True` if this is an absolute URI.N)r`   r?   r‹   r   r   r   r   V  ó   zSplitResult.isabsuric                 C   s   | j du o	| jduS )z9Return :const:`True` if this is a network-path reference.N)r`   rO   r‹   r   r   r   r	   Z  r   zSplitResult.isnetpathc                 C   s"   | j du o| jdu o| j | j¡S )z;Return :const:`True` if this is an absolute-path reference.N©r`   rO   ra   rs   r\   r‹   r   r   r   r   ^  s
   
ÿýzSplitResult.isabspathc                 C   s$   | j du o| jdu o| j | j¡ S )z:Return :const:`True` if this is a relative-path reference.Nr‘   r‹   r   r   r   r
   f  s
   
ÿýzSplitResult.isrelpathc                 C   s&   | j du o| jdu o| j o| jdu S )z:Return :const:`True` if this is a same-document reference.N)r`   rO   ra   rb   r‹   r   r   r   r   n  s   
ÿþüzSplitResult.issamedocFc                 C   sÔ   | j  |¡ ¡ \}}}}}|dur|s|| jkr|  |¡}nB|dur+| j}|  |¡}n5|s@| j}| j}| j}|du r=| jn|}n | | j	¡rR| j}| j}|  |¡}n| j}| j}|  |  
|¡¡}t| ƒ|||||ƒS )zwTransform a URI reference relative to `self` into a
        :class:`SplitResult` representing its target URI.

        N)ÚREÚmatchÚgroupsr`   r{   rO   ra   rb   rs   r\   Ú_SplitResult__mergerŒ   )rA   Úrefr$   r`   rO   ra   rb   r?   r   r   r   Ú	transformw  s&   zSplitResult.transformc                 C   s>   | j d ur| js| j| S | j | j¡}|d  |d |f¡S )Nr2   r   )rO   ra   r\   rP   r)   )rA   ra   r9   r   r   r   Ú__merge“  s   
zSplitResult.__mergec                 C   sÔ   g }|  | j¡D ]1}|| jkrq|| jkr| |¡ qt|ƒdkr&|d s&q|r4|d | jkr4| ¡  q| |¡ q| | j¡d | j| jfv rN| | j¡ |rdt|ƒdkrd|d | jkrd| 	d| j¡ | j 
|¡S )Nr2   r   rr   r3   )r4   r\   ÚDOTÚDOTDOTr5   rk   ÚpoprP   r_   Úinsertr)   )Úclsra   Úpsegr;   r   r   r   Ú__remove_dot_segments›  s    


z!SplitResult.__remove_dot_segmentsc                 C   s0   t |tƒr
| d¡}| d¡rtdƒ‚t |¡S )Nr%   Úvzaddress mechanism not supported)r&   r   r8   rs   rl   rx   ÚIPv6Address)r   Úaddressr   r   r   Ú__parse_ip_literal±  s
   



zSplitResult.__parse_ip_literalrN   rG   )Nr$   ©r#   r$   )r   r#   r$   ©F)rH   rI   rJ   rK   rL   ÚpropertyrR   rY   rZ   rB   rd   rp   rm   rn   ro   r|   r}   r‡   r‚   rF   r   r   r	   r   r
   r   r—   r•   Úclassmethodr{   rw   r   r   r   r   rM   ˆ   s@    















	
rM   z$scheme authority path query fragmentc                   @   óF   e Zd ZdZejdejdZd\ZZ	Z
ZZZZd\ZZd\ZZdZdS )	ÚSplitResultBytesr   sü   
    (?:([A-Za-z][A-Za-z0-9+.-]*):)?  # scheme (RFC 3986 3.1)
    (?://([^/?#]*))?                 # authority
    ([^?#]*)                         # path
    (?:\?([^#]*))?                   # query
    (?:\#(.*))?                      # fragment
    ©Úflags)ó   :ó   /ó   ?r=   ó   [ó   ]ó   @)ó   .s   ..)r   ó   =ó
   0123456789N©rH   rI   rJ   rL   ÚreÚcompileÚVERBOSEr’   rU   r\   r]   r^   rt   rv   rQ   r™   rš   r_   r‰   rW   r   r   r   r   r©   É  ó    ør©   c                   @   r¨   )	ÚSplitResultStringr   zü
    (?:([A-Za-z][A-Za-z0-9+.-]*):)?  # scheme (RFC 3986 3.1)
    (?://([^/?#]*))?                 # authority
    ([^?#]*)                         # path
    (?:\?([^#]*))?                   # query
    (?:\#(.*))?                      # fragment
    rª   )ú:ú/ú?r>   ú[ú]ú@)Ú.z..)r"   ú=Ú
0123456789Nrµ   r   r   r   r   rº   ë  r¹   rº   c                 C   s@   t | tƒr|  d¡}n|  d¡}t|d |d r|d ƒS dƒS )zBRemove an existing fragment component from a URI reference string.r=   r>   r   r2   r3   N)r&   r   rˆ   r<   )r,   r9   r   r   r   r     s   

 r   c                 C   s(   t | tƒrt}nt}||j | ¡ ¡ Ž S )z¹Split a well-formed URI reference string into a tuple with five
    components corresponding to a URI's general structure::

      <scheme>://<authority>/<path>?<query>#<fragment>

    )r&   r   r©   rº   r’   r“   r”   )r,   r:   r   r   r   r     s   
r   c                 C   s6   | \}}}}}t |tƒrt}nt}||||||ƒ ¡ S )zdCombine the elements of a five-item iterable into a URI reference's
    string representation.

    )r&   r   r©   rº   rB   )r9   r`   rO   ra   rb   r?   r:   r   r   r   r   $  s
   
r   Fc                 C   s\   t | t|ƒƒrt| ƒ ||¡ ¡ S t | tƒr"t|  ¡ ƒ ||¡ ¡ S t| ƒ | ¡ |¡ ¡ S )zRConvert a URI reference relative to a base URI to its target URI
    string.

    )r&   rŒ   r   r—   rB   r   r8   )Úbaser–   r$   r   r   r   r   1  s
   
r   c                 C   ó   t | ƒ ¡ S )z-Return :const:`True` if `uristring` is a URI.)r   r   ©r,   r   r   r   r   >  ó   r   c                 C   rÅ   )z7Return :const:`True` if `uristring` is an absolute URI.)r   r   rÆ   r   r   r   r   C  rÇ   r   c                 C   rÅ   )z@Return :const:`True` if `uristring` is a network-path reference.)r   r	   rÆ   r   r   r   r	   H  rÇ   r	   c                 C   rÅ   )zBReturn :const:`True` if `uristring` is an absolute-path reference.)r   r   rÆ   r   r   r   r   M  rÇ   r   c                 C   rÅ   )zAReturn :const:`True` if `uristring` is a relative-path reference.)r   r
   rÆ   r   r   r   r
   R  rÇ   r
   c                 C   rÅ   )zAReturn :const:`True` if `uristring` is a same-document reference.)r   r   rÆ   r   r   r   r   W  rÇ   r   s   ^[A-Za-z][A-Za-z0-9+.-]*$s   ^(?:(.*)@)?(.*?)(?::([0-9]*))?$z^(?:(.*)@)?(.*?)(?::([0-9]*))?$r»   z:@/z:@/?c                 C   s   t  | ¡r	|  ¡ S tdƒ‚)NzInvalid scheme component)Ú
_SCHEME_REr“   rc   rl   r   r   r   r   Ú_schemem  s   
rÉ   c                 C   s  g }| d ur|  t| t|ƒ¡ |  d¡ t|tjƒr'|  d|j ¡  d ¡ n*t|tjƒr6|  |j ¡ ¡ nt|t	ƒrC|  t
|ƒ¡ n|d urQ|  t
| d¡ƒ¡ t|tjƒrc|  tt|ƒ ¡ ƒ¡ nt|t	ƒrp|  t|ƒ¡ n|d ur}|  t| ¡ ƒ¡ |r„d |¡S d S )Nr±   r¯   r°   r#   r   )r5   r   Ú_SAFE_USERINFOr&   rx   r¡   Ú
compressedr   ry   r   Ú_hostÚnumbersÚNumberÚ_portÚstrr)   )rR   rY   rZ   r.   rO   r   r   r   Ú
_authorityt  s&   


rÑ   c                 C   s*   |   d¡r	tdƒ‚dt | ¡j ¡  d S )Nr    zAddress mechanism not supportedr¯   r°   )rs   rl   rx   r¡   rË   r   )r¢   r   r   r   Ú_ip_literalŽ  s   
rÒ   c                 C   s\   |   d¡r|  d¡rt| dd…  ¡ ƒS zt|  d¡ƒW S  ty-   t|  ¡ tdƒ Y S w )Nr¯   r°   r2   rr   r#   )rs   ru   rÒ   r8   rl   r   rc   Ú
_SAFE_HOST)rY   r   r   r   rÌ   •  s   ÿrÌ   c                 C   s"   |   d¡r	tdƒ‚| rd|  S dS )Nr´   zInvalid port subcomponentr¬   r   )rV   rl   )rZ   r   r   r   rÏ   £  s
   
rÏ   c           	      C   s–   g }|j }t |d¡}| D ]5\}}t|||ƒ}|d u r ||ƒ qt|ttfƒr4||d t|||ƒ ƒ q||d tt|ƒ||ƒ ƒ q| d¡ |¡S )Nr"   r³   r%   )	r5   Ú_SAFE_QUERYÚreplacer   r&   r   rÐ   r   r)   )	rŽ   rƒ   r.   Útermsr5   r-   Úkeyr†   r…   r   r   r   Ú
_querylist¯  s   
rØ   c                    sv   g }|   ¡ D ].\‰ }t|ttfƒr| ˆ |f¡ qt|tjjƒr-| ‡ fdd„|D ƒ¡ q| ˆ |f¡ qt	|||ƒS )Nc                    s   g | ]}ˆ |f‘qS r   r   )r   r    ©r×   r   r   r   Ä  s    z_querydict.<locals>.<listcomp>)
rŽ   r&   r   rÐ   r5   rg   rh   ri   r[   rØ   )Úmappingrƒ   r.   rŽ   r†   r   rÙ   r   Ú
_querydict¾  s   rÛ   r   c
           
      C   sØ  t | tƒr
t| ƒ} n
| durt|  ¡ ƒ} |du rd}n/t |tƒr(t |¡ ¡ }n"t |tƒr5t |¡ ¡ }nt |t	j
jƒs@tdƒ‚t|ƒdkrJtdƒ‚t|durQ|n|d |durZ|n|d |durc|n|d |	ƒ}t|t|	ƒ}|dur~|r~| d	¡s~td
ƒ‚|du r‹| d¡r‹tdƒ‚| du r¥|du r¥| d	¡s¥d| d	¡d v r¥d| }t |ttfƒr³t|t|	ƒ}n$t |t	j
jƒrÁt|||	ƒ}nt |t	j
jƒrÏt|||	ƒ}n|dur×tdƒ‚|durát|t|	ƒ}t| ||||fƒ ¡ S )z>Compose a URI reference string from its individual components.Nre   zInvalid authority typerf   zInvalid authority lengthr   r2   r3   r­   z%Invalid path with authority components   //z(Invalid path without authority componentr¬   s   ./zInvalid query type)r&   r   rÉ   r   Ú_AUTHORITY_RE_BYTESr“   r”   rÐ   Ú_AUTHORITY_RE_STRrg   rh   ri   rj   rk   rl   rÑ   r   Ú
_SAFE_PATHrs   rˆ   rÔ   ÚMappingrÛ   rØ   Ú_SAFE_FRAGMENTr   r8   )
r`   rO   ra   rb   r?   rR   rY   rZ   Úquerysepr.   r   r   r   r   Ê  sN   



ür   )r"   r#   r$   r¤   r¥   )
NNr"   NNNNNr   r#   )6rK   rg   Úcollections.abcrx   rÍ   r¶   Ústringr   Ú__all__Ú__version__r   r   r   r   Ú	frozensetr   r   Úranger'   r6   r   r   Ú
namedtupler<   rM   r©   rº   r   r   r   r   r   r   r	   r   r
   r   r·   rÈ   rÜ   rÝ   rÊ   rÓ   rÞ   rÔ   rà   rÉ   rÑ   rÒ   rÌ   rÏ   rØ   rÛ   r   r   r   r   r   Ú<module>   sˆ    ÿÿÿÿ



ÿ  C""	



ö