o
    b>9                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ d	Z	d
Z
G dd deZG dd dede
eZG dd dede
eZdd Zdd ZdS )z3Module containing the urlparse compatibility logic.    )
namedtuple   )compat)
exceptions)misc)normalizers)uri)ParseResultParseResultBytes)schemeuserinfohostportpathqueryfragmentc                   @   s@   e Zd Zdd Zdd Zedd Zedd Zed	d
 ZdS )ParseResultMixinc                    sn    fdddD \}}}| j |ks| j|ks| j|kr4|r"d|}tt|| jt|| j|fS | j	S )Nc                 3   s    | ]} | V  qd S N .0p
attributesr   c/var/www/secure340b-portal/env/lib/python3.10/site-packages/urllib3/packages/rfc3986/parseresult.py	<genexpr>"   s    z7ParseResultMixin._generate_authority.<locals>.<genexpr>r   r   r   z{0})
r   r   r   formatr   Znormalize_authorityr   to_strencoding	authority)selfr   r   r   r   r   r   r   _generate_authority   s"   


z$ParseResultMixin._generate_authorityc                 C   s   |   S )z*Shim to match the standard library method.)unsplitr!   r   r   r   geturl0   s   zParseResultMixin.geturlc                 C      | j S z#Shim to match the standard library.r   r$   r   r   r   hostname4      zParseResultMixin.hostnamec                 C   r&   r'   )r    r$   r   r   r   netloc9   r*   zParseResultMixin.netlocc                 C   r&   r'   )r   r$   r   r   r   params>   r*   zParseResultMixin.paramsN)	__name__
__module____qualname__r"   r%   propertyr)   r+   r,   r   r   r   r   r      s    

r   c                       s   e Zd ZdZdZ	d fdd	Ze		dddZe				dd
dZe	dd Z
ejejejejejejejfddZdddZdddZ  ZS )r	   zImplementation of urlparse compatibility class.

    This uses the URIReference logic to handle compatibility with the
    urlparse.ParseResult class.
    r   utf-8c
              
      s>   t t| | |p	d|pd||pd|pd||}
|	|
_||
_|
S )zCreate a new ParseResult.N)superr	   __new__r   	reference)clsr   r   r   r   r   r   r   uri_refr   parse_result	__class__r   r   r3   N   s   
	zParseResult.__new__Nc	                 C   s   d}	|dur|	|d 7 }	|dur|	|7 }	|dur|	d |7 }	tj||	||||d }
t|
dd\}}}| |
j||||
j|
j|
j|
|d	S )	-Create a ParseResult instance from its parts. N@:{0}r   r    r   r   r   r   Tstrict	r   r   r   r   r   r   r   r6   r   )	r   r   URIReference	normalizeauthority_fromr   r   r   r   )r5   r   r   r   r   r   r   r   r   r    r6   r   r   r   
from_parts^   s6   zParseResult.from_partsTc           	      C   sL   t j||}|s| }t||\}}}| |j||||j|j|j||d	S )a  Parse a URI from the given unicode URI string.

        :param str uri_string: Unicode URI to be parsed into a reference.
        :param str encoding: The encoding of the string provided
        :param bool strict: Parse strictly according to :rfc:`3986` if True.
            If False, parse similarly to the standard library's urlparse
            function.
        :returns: :class:`ParseResult` or subclass thereof
        rA   )	r   rB   from_stringrC   rD   r   r   r   r   )	r5   
uri_stringr   r@   lazy_normalizer4   r   r   r   r   r   r   rF   z   s   zParseResult.from_stringc                 C   s   | j jS z Return the normalized authority.)r4   r    r$   r   r   r   r       s   zParseResult.authorityc              	   C   s   t t|||||||f}i }	|D ]\}
}|tju rt| |
}||	|
< q| |	}| jj|	d ||	d |	d |	d d}td|| j	d|	S )	>Create a copy of this instance replacing with specified parts.r   r   r   r   r   r    r   r   r   r6   r   Nr   )
zipPARSED_COMPONENTSr   UseExistinggetattrr"   r4   	copy_withr	   r   )r!   r   r   r   r   r   r   r   r   
attrs_dictnamevaluer    refr   r   r   rQ      s    



zParseResult.copy_withc                    s<    p| j  ttt fdd| D }td| j d|S )z+Convert to an instance of ParseResultBytes.c                 3   s(    | ]}t |d r| n|V  qdS )encodeN)hasattrrV   )r   attrr   r   r   r      s     z%ParseResult.encode.<locals>.<genexpr>rL   Nr   )r   dictrM   rN   r
   r4   )r!   r   attrsr   rY   r   rV      s   

zParseResult.encodeFc                 C   s<   | }|r| j r| j d}|| j}| j|d}|j S )zCreate a URI string from the components.

        :returns: The parsed URI reconstituted as a string.
        :rtype: str
        idnar(   )r   rV   decoder   rQ   r4   r#   )r!   use_idnar7   	hostbytesr   r   r   r   r#      s   

zParseResult.unsplit)r1   )NNNNNNNr1   r1   TTr   F)r-   r.   r/   __doc__slotsr3   classmethodrE   rF   r0   r    r   rO   rQ   rV   r#   __classcell__r   r   r8   r   r	   D   s,    


r	   c                       s   e Zd ZdZ	d fdd	Ze			dddZe		dd	d
Zedd Z	e
je
je
je
je
je
je
jdfddZdddZ  ZS )r
   z<Compatibility shim for the urlparse.ParseResultBytes object.r1   Tc              
      sL   t t| | |p	d|pd||pd|pd|pd|pd}|	|_||_|
|_|S )z'Create a new ParseResultBytes instance.N)r2   r
   r3   r   r4   rH   )r5   r   r   r   r   r   r   r   r6   r   rH   r7   r8   r   r   r3      s   
	zParseResultBytes.__new__Nc
                 C   s   d}
|dur|
|d 7 }
|dur|
|7 }
|dur!|
d t|7 }
tj||
||||d}|	s2| }tj}t|dd\}}}| ||||||||||||||||||||||	d
S )	r:   r;   Nr<   r=   r>   Tr?   
r   r   r   r   r   r   r   r6   r   rH   )r   intr   rB   rC   r   to_bytesrD   )r5   r   r   r   r   r   r   r   r   rH   r    r6   rh   r   r   r   rE      s:   
zParseResultBytes.from_partsc           
      C   sx   t j||}|s| }t||\}}}tj}	| |	|j||	|||	||||	|j||	|j	||	|j
||||d
S )a  Parse a URI from the given unicode URI string.

        :param str uri_string: Unicode URI to be parsed into a reference.
        :param str encoding: The encoding of the string provided
        :param bool strict: Parse strictly according to :rfc:`3986` if True.
            If False, parse similarly to the standard library's urlparse
            function.
        :returns: :class:`ParseResultBytes` or subclass thereof
        rf   )r   rB   rF   rC   rD   r   rh   r   r   r   r   )
r5   rG   r   r@   rH   r4   r   r   r   rh   r   r   r   rF      s    


zParseResultBytes.from_stringc                 C   s   | j j| jS rI   )r4   r    rV   r   r$   r   r   r   r      s   zParseResultBytes.authorityc	              	   C   s   t t|||||||f}	i }
|	D ]"\}}|tju rt| |}t|ts.t|dr.|| j	}||
|< q| 
|
}tj}| jj||
d | j	||| j	||
d | j	||
d | j	||
d | j	d}|sh| }td	|| j	|d|
S )
rJ   rV   r   r   r   r   rK   )r6   r   rH   Nr   )rM   rN   r   rO   rP   
isinstancebytesrW   rV   r   r"   r   r   r4   rQ   rC   r
   )r!   r   r   r   r   r   r   r   rH   r   rR   rS   rT   r    r   rU   r   r   r   rQ   !  s8   




zParseResultBytes.copy_withFc                 C   sZ   | }|r| j r| j | j}|d}| j|d}| jr"|jdd}|j }|| jS )zCreate a URI bytes object from the components.

        :returns: The parsed URI reconstituted as a string.
        :rtype: bytes
        r\   r(   F)rH   )r   r]   r   rV   rQ   rH   r4   r#   )r!   r^   r7   r   r_   r   r   r   r   r#   A  s   


zParseResultBytes.unsplit)r1   T)	NNNNNNNr1   Tr`   ra   )r-   r.   r/   rb   r3   rd   rE   rF   r0   r    r   rO   rQ   r#   re   r   r   r8   r   r
      s*     

 r
   c                 C   s   d  } }}d }| }d| v r|  dd\}}|dr'|dd\}}|d7 }d|v r4|dd\}}n|s:|r:|}|r@|s@|}|||fS )Nr<   r   []:)rsplit
startswithsplit)r    r   r   r   Z
extra_hostrestr   r   r   split_authorityT  s   

rr   c                    s   z|    W n tjy   |r t| j\}}}Y nw  fdddD \}}}|r=zt|}W n ty<   t|w |||fS )Nc                 3   s    | ]}  |V  qd S r   )getr   Zsubauthorityr   r   r   y  s    z!authority_from.<locals>.<genexpr>r   )Zauthority_infor   ZInvalidAuthorityrr   r    rg   
ValueErrorZInvalidPort)r4   r@   r   r   r   r   rt   r   rD   o  s"   


rD   N)rb   collectionsr   r;   r   r   r   r   r   __all__rN   objectr   r	   r
   rr   rD   r   r   r   r   <module>   s(   &  