o
    vhzi                     @   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 )PzRFC 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   O/var/www/html/hyperkenya/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 )zReturn 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 )zReturn 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 )zReturn 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 )zReturn 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 )zReturn 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   )zReturn 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 )zSplit 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   )zReturn 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 )zSplit 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|  |rd|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rtd| du r|du r|d	sd|d	d v rd| }t |ttfrt|t|	}n$t |t	j
jrt|||	}nt |t	j
jrt|||	}n|durtd|durt|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""	



