o
    h9                     @   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                    s    fdddD \}}}| j |ks| j|ks| j|kr4|r"d|}tt|| jt|| j|fS t	| j
tr@| j
dS | j
S )Nc                 3   s    | ]} | V  qd S N .0p
attributesr   [/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/rfc3986/parseresult.py	<genexpr>)   s    
z7ParseResultMixin._generate_authority.<locals>.<genexpr>r   r   r   z{0}utf-8)r   r   r   formatr   Znormalize_authorityr   to_strencoding
isinstance	authoritybytesdecode)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   geturl>   s   zParseResultMixin.geturlc                 C      | j S z#Shim to match the standard library.r   r(   r   r   r   hostnameB      zParseResultMixin.hostnamec                 C   r*   r+   )r"   r(   r   r   r   netlocG   r.   zParseResultMixin.netlocc                 C   r*   r+   )r   r(   r   r   r   paramsL   r.   zParseResultMixin.paramsN)	__name__
__module____qualname__r&   r)   propertyr-   r/   r0   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   r   c
              
      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   r6   ]   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   r9   r    )	r   r   URIReference	normalizeauthority_fromr   r   r   r   )r8   r   r   r   r   r   r   r   r    r"   r9   r   r   r   
from_partsx   s:   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
        rD   )	r   rE   from_stringrF   rG   r   r   r   r   )	r8   
uri_stringr    rC   lazy_normalizer7   r   r   r   r   r   r   rI      s   zParseResult.from_stringc                 C   s   | j jS z Return the normalized authority.)r7   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   r9   r    Nr   )
zipPARSED_COMPONENTSr   UseExistinggetattrr&   r7   	copy_withr	   r    )r%   r   r   r   r   r   r   r   r   
attrs_dictnamevaluer"   refr   r   r   rT      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)hasattrrY   )r   attrr    r   r   r      s
    
z%ParseResult.encode.<locals>.<genexpr>rO   Nr   )r    dictrP   rQ   r
   r7   )r%   r    attrsr   r\   r   rY      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   rY   r$   r    rT   r7   r'   )r%   use_idnar:   	hostbytesr   r   r   r   r'      s   

zParseResult.unsplit)r   )NNNNNNNr   r   TTr   F)r1   r2   r3   __doc__slotsr6   classmethodrH   rI   r4   r"   r   rR   rT   rY   r'   __classcell__r   r   r;   r   r	   R   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.r   Tc              
      sL   t t| | |p	d|pd||pd|pd|pd|pd}|	|_||_|
|_|S )z'Create a new ParseResultBytes instance.N)r5   r
   r6   r    r7   rK   )r8   r   r   r   r   r   r   r   r9   r    rK   r:   r;   r   r   r6     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@   rA   TrB   
r   r   r   r   r   r   r   r9   r    rK   )r   intr   rE   rF   r   to_bytesrG   )r8   r   r   r   r   r   r   r   r    rK   r"   r9   rj   r   r   r   rH   "  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
        rh   )r   rE   rI   rF   rG   r   rj   r   r   r   r   )
r8   rJ   r    rC   rK   r7   r   r   r   rj   r   r   r   rI   P  s"   



zParseResultBytes.from_stringc                 C   s   | j j| jS rL   )r7   r"   rY   r    r(   r   r   r   r"   p  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 )
rM   rY   r   r   r   r   rN   )r9   r    rK   Nr   )rP   rQ   r   rR   rS   r!   r#   rZ   rY   r    r&   r   r   r7   rT   rF   r
   )r%   r   r   r   r   r   r   r   rK   r   rU   rV   rW   r"   r   rX   r   r   r   rT   u  s:   




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)rK   )r   r$   r    rY   rT   rK   r7   r'   )r%   r`   r:   r   ra   r   r   r   r   r'     s   


zParseResultBytes.unsplit)r   T)	NNNNNNNr   Trb   rc   )r1   r2   r3   rd   r6   rf   rH   rI   r4   r"   r   rR   rT   r'   rg   r   r   r;   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_authority  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     s    

z!authority_from.<locals>.<genexpr>r   )Zauthority_infor   ZInvalidAuthorityrr   r"   ri   
ValueErrorZInvalidPort)r7   rC   r   r   r   r   rt   r   rG     s"   


rG   N)rd   collectionsr   r>   r   r   r   r   r   __all__rQ   objectr   r	   r
   rr   rG   r   r   r   r   <module>   s(   
-
 
/
 2