o
    ïT·j{L  ã                   @  sÀ  d dl mZ d dlZd dlZd dlmZ d dlmZ ddl	m
Z
 ddlmZ d	Ze d
¡Ze d¡Ze d¡Ze d¡Ze dejejB ¡ZdZdZdjeed�ZeedœZg d¢ZdZdd dd„ eD ƒ¡ d Zde d Zde d e d Z dZ!e d ¡Z"e d!¡Z#e d"e d# ¡Z$e d"e  d# ¡Z%e d"e dd$…  d# ¡Z&e d%e d& ¡Z'd'e!ee f Z(e e(ejejB ¡Z)e*d(ƒZ+e*d)ƒZ,e+e,B d*hB Z-e-d+d,hB Z.e.d-hB  Z/Z0G d.d/„ d/e 1d/d0ej2e3 fd1ej2e3 fd2ej2e3 fd3ej2e4 fd4ej2e3 fd5ej2e3 fd6ej2e3 fg¡ƒZ5ej6d[d<d=„ƒZ7ej6d\d?d=„ƒZ7d]dAd=„Z7d^dBdC„Z8ej6d_dDdE„ƒZ9ej6d`dFdE„ƒZ9dadGdE„Z9dbdKdL„Z:dcdMdN„Z;dbdOdP„Z<dddSdT„Z=dedVdW„Z>dfdYdZ„Z?dS )gé    )ÚannotationsN)Úpartial)Úunquoteé   )ÚLocationParseErroré   )Úto_str)ÚhttpÚhttpsNz%[a-fA-F0-9]{2}z%[a-fA-F0-9]{2}|%z^(?:[a-zA-Z][a-zA-Z0-9+-]*:|/)z[\x00-\x20\x7f]zS^(?:([a-zA-Z][a-zA-Z0-9+.-]*):)?(?://([^\\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$z(?:[0-9]{1,3}\.){3}[0-9]{1,3}z[0-9A-Fa-f]{1,4}z(?:{hex}:{hex}|{ipv4}))ÚhexÚipv4)r   Úls32)	z(?:%(hex)s:){6}%(ls32)sz::(?:%(hex)s:){5}%(ls32)sz%(?:%(hex)s)?::(?:%(hex)s:){4}%(ls32)sz2(?:(?:%(hex)s:)?%(hex)s)?::(?:%(hex)s:){3}%(ls32)sz6(?:(?:%(hex)s:){0,2}%(hex)s)?::(?:%(hex)s:){2}%(ls32)sz/(?:(?:%(hex)s:){0,3}%(hex)s)?::%(hex)s:%(ls32)sz'(?:(?:%(hex)s:){0,4}%(hex)s)?::%(ls32)sz&(?:(?:%(hex)s:){0,5}%(hex)s)?::%(hex)sz(?:(?:%(hex)s:){0,6}%(hex)s)?::zCABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._\-~z(?:ú|c                 C  s   g | ]}|t  ‘qS © )Ú_subs)Ú.0Úxr   r   úS/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/urllib3/util/url.pyÚ
<listcomp>8   ó    r   ú)z(?:%25|%)(?:[z]|%[a-fA-F0-9]{2})+z\[z)?\]z!(?:[^\[\]%:/?#]|%[a-fA-F0-9]{2})*z!^(/[^?#]*)(?:\?([^#]*))?(?:#.*)?$zE^(?:0[xX][0-9a-fA-F]+|[0-9]+)(?:\.(?:0[xX][0-9a-fA-F]+|[0-9]+)){0,3}$ú^ú$éþÿÿÿú(z)\]$z)^(%s|%s|%s)(?::0*?(|0|[1-9][0-9]{0,4}))?$zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-~z!$&'()*+,;=ú:ú@ú/ú?c                      sž   e Zd ZdZ							d!d"‡ fdd„Zed#dd„ƒZed$dd„ƒZed$dd„ƒZed%dd„ƒZ	ed$dd„ƒZ
ed$dd„ƒZed%dd„ƒZd%dd „Z‡  ZS )&ÚUrla—  
    Data structure for representing an HTTP URL. Used as a return value for
    :func:`parse_url`. Both the scheme and host are normalized as they are
    both case-insensitive according to RFC 3986.

    :param auth: User information as defined in RFC 3986 3.2.1. This
        component is kept percent-encoded. Use :attr:`auth_decoded` or
        :attr:`auth_decoded_joined` to get the decoded form.
    NÚschemeú
str | NoneÚauthÚhostÚportú
int | NoneÚpathÚqueryÚfragmentc              
     s@   |r|  d¡sd| }|d ur| ¡ }tƒ  | |||||||¡S )Nr   )Ú
startswithÚlowerÚsuperÚ__new__)Úclsr    r"   r#   r$   r&   r'   r(   ©Ú	__class__r   r   r,   n   s
   
zUrl.__new__Úreturnú*tuple[None, None] | tuple[str, str | None]c                 C  sB   | j du rdS | j  d¡\}}}t|dd�|rt|dd�fS dfS )zû
        User information with %-escapes decoded as UTF-8, returned as a
        ``(username, password)`` tuple.

        Both values are ``None`` if ``auth`` is ``None``.
        ``password`` is ``None`` if not present in the auth component.
        N)NNr   úutf-8)Úencoding)r"   Ú	partitionÚ_unquote)ÚselfÚusernameÚsepÚpasswordr   r   r   Úauth_decoded~   s   
	
þþzUrl.auth_decodedc                 C  s(   | j \}}|du rdS |› d|pd› �S )aÖ  
        User information with %-escapes decoded as UTF-8, as a string
        prepared for encoding into an 'authorization: basic ...' header.

        This property does not choose the encoding used for an
        'authorization: basic ...' header. Use the ``basic_auth_encoding`` or
        ``proxy_basic_auth_encoding`` parameters of
        :func:`urllib3.util.make_headers` when converting the returned string
        into Basic authentication bytes.

        This is a convenience property that joins the username and
        password with a colon, if both are present.
        If only the username is present, a trailing colon is still
        appended.
        If ``auth`` is ``None``, this returns ``None``.
        Nr   Ú )r:   )r6   r7   r9   r   r   r   Úauth_decoded_joined�   s   
zUrl.auth_decoded_joinedc                 C  ó   | j S )z@For backwards-compatibility with urlparse. We're nice like that.)r#   ©r6   r   r   r   Úhostname¦   s   zUrl.hostnameÚstrc                 C  s&   | j pd}| jdur|d| j 7 }|S )z)Absolute path including the query string.r   Nr   )r&   r'   )r6   Úurir   r   r   Úrequest_uri«   s   

zUrl.request_uric                 C  s.   | j }| j}|du s|du r|S |› d|› �S )z¤
        Authority component as defined in RFC 3986 3.2.
        This includes userinfo (auth), host and port.

        i.e.
            userinfo@host:port
        Nr   )r"   Únetloc)r6   ÚuserinforC   r   r   r   Ú	authorityµ   s
   	zUrl.authorityc                 C  s0   | j du rdS | jdur| j › d| j› �S | j S )z­
        Network location including host and port.

        If you need the equivalent of urllib.parse's ``netloc``,
        use the ``authority`` property instead.
        Nr   )r#   r$   r>   r   r   r   rC   Å   s
   

z
Url.netlocc           	      C  s¢   | \}}}}}}}d}|dur||d 7 }|dur||d 7 }|dur'||7 }|dur3|dt |ƒ 7 }|dur;||7 }|durE|d| 7 }|durO|d| 7 }|S )a2  
        Convert self into a url

        This function should more or less round-trip with :func:`.parse_url`. The
        returned url may not be exactly the same as the url inputted to
        :func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
        with a blank port will have : removed).

        Example:

        .. code-block:: python

            import urllib3

            U = urllib3.util.parse_url("https://google.com/mail/")

            print(U.url)
            # "https://google.com/mail/"

            print( urllib3.util.Url("https", "username:password",
                                    "host.com", 80, "/path", "query", "fragment"
                                    ).url
                )
            # "https://username:password@host.com:80/path?query#fragment"
        r;   Nz://r   r   r   ú#)r@   )	r6   r    r"   r#   r$   r&   r'   r(   Úurlr   r   r   rG   Ó   s"   zUrl.urlc                 C  r=   ©N)rG   r>   r   r   r   Ú__str__  s   zUrl.__str__)NNNNNNN)r    r!   r"   r!   r#   r!   r$   r%   r&   r!   r'   r!   r(   r!   )r0   r1   )r0   r!   )r0   r@   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   Úpropertyr:   r<   r?   rB   rE   rC   rG   rI   Ú__classcell__r   r   r.   r   r   V   s2    ø	/r   r    r"   r#   r$   r&   r'   r(   Ú	componentr@   Úallowed_charsútyping.Container[str]r0   c                 C  ó   d S rH   r   ©rP   rQ   r   r   r   Ú_encode_invalid_chars  ó   rU   ÚNonec                 C  rS   rH   r   rT   r   r   r   rU     rV   r!   c                 C  s¶   | du r| S t | ƒ} d| vr|  ¡ rtt|j| ƒƒr| S t dd„ | ¡\} }|  dd¡}|| d¡k}t	ƒ }|D ]}|r@|dksJ|d	k rPt
|ƒ|v rP| |¡ q8|d
| 7 }q8| ¡ S )zfPercent-encodes a URI component without reapplying
    onto an already percent-encoded component.
    Nú%c                 S  ó   |   d¡ ¡ S ©Nr   ©ÚgroupÚupper©Úmatchr   r   r   Ú<lambda>0  ó    z'_encode_invalid_chars.<locals>.<lambda>r2   Úsurrogatepassó   %é%   é€   s   %%%02X)r   ÚisasciiÚallÚmapÚ__contains__Ú_PERCENT_REÚsubnÚencodeÚcountÚ	bytearrayÚchrÚappendÚdecode)rP   rQ   Úpercent_encodingsÚ	uri_bytesÚis_percent_encodedÚencoded_componentÚbyte_ordr   r   r   rU     s*   ÿþÿc                 C  s‚   |   d¡}g }|D ]}|dkrq	|dkr| |¡ q	|r | ¡  q	|  d¡r2|r,|d r2| dd¡ |  d¡r<| d¡ d |¡S )Nr   Ú.z..r   r;   )z/.z/..)Úsplitrp   Úpopr)   ÚinsertÚendswithÚjoin)r&   ÚsegmentsÚoutputÚsegmentr   r   r   Ú_remove_path_dot_segmentsC  s   
€


r€   c                 C  rS   rH   r   ©r#   r    r   r   r   Ú_normalize_hosta  ó   r‚   c                 C  rS   rH   r   r�   r   r   r   r‚   e  rƒ   c                 C  s"  | r�t  | ¡}|rtd| ›d| ¡ ›�ƒ‚|tv r�t | ¡}|rpt | ¡}|rl| d¡\}}| ||… }| 	d¡rD|dkrD|dd … }n|dd … }t
 tt| d�|¡}t|tƒ}| d |…  ¡ › d|› | |d … › �S |  ¡ S t | ¡s�d| v rt t| ¡} td d	d
„ |  d¡D ƒ¡dƒS | S )NúHost ú contains invalid character r   z%25é   ©Ú
error_hostrX   ó   .c                 S  s   g | ]}t |ƒ‘qS r   )Ú_idna_encode)r   Úlabelr   r   r   r   Œ  r   z#_normalize_host.<locals>.<listcomp>rw   Úascii)Ú_HOST_INVALID_CHAR_REÚsearchr   r\   Ú_NORMALIZABLE_SCHEMESÚ_IPV6_ADDRZ_REr_   Ú_ZONE_ID_REÚspanr)   rj   Úsubr   Ú#_normalize_zone_id_percent_encodingrU   Ú_UNRESERVED_CHARSr*   Ú_IPV4_REÚ_HOST_PERCENT_REÚ _normalize_host_percent_encodingr   r|   rx   )r#   r    Úinvalid_host_charÚis_ipv6r_   ÚstartÚendÚzone_idr   r   r   r‚   i  sB   
ÿÿ


þ
&
þr_   úre.Match[str]rˆ   c                C  sH   |   d¡}tt|dd … dƒƒ}|dk s|dkr"td|›d|›�ƒ‚|S )Nr   r   é   ú úr„   z4 contains invalid percent-encoded control character )r\   ro   Úintr   )r_   rˆ   Úpercent_encoded_octetÚdecoded_octetr   r   r   Ú_decode_percent_encoding’  s   
ÿÿr¥   c                 C  sF   |   d¡dkrt| j›d�ƒ‚t| | jd�}|tv r|S |   d¡ ¡ S )Nr   rX   z is not a valid hostr‡   )r\   r   Ústringr¥   r•   r]   )r_   r¤   r   r   r   r˜   Ÿ  s   r˜   c                C  s   t | |d� |  d¡ ¡ S )Nr‡   r   )r¥   r\   r]   )r_   rˆ   r   r   r   r”   ©  s   r”   ÚnameÚbytesc                 C  s‚   |   ¡ s4zdd l}W n ty   tdƒd ‚w z|j|  ¡ ddd�W S  |jy3   td| › d�ƒd ‚w t dd„ |  ¡ ¡ d	¡S )
Nr   z-Unable to parse URL without the 'idna' moduleT)ÚstrictÚ
std3_ruleszName 'z' is not a valid IDNA labelc                 S  rY   rZ   r[   r^   r   r   r   r`   À  ra   z_idna_encode.<locals>.<lambda>rŒ   )	rf   ÚidnaÚImportErrorr   rl   r*   Ú	IDNAErrorrj   r“   )r§   r«   r   r   r   rŠ   °  s,   ÿþÿ
ÿþÿÿrŠ   Útargetc                 C  sT   t  | ¡}|st| ›d�ƒ‚| ¡ \}}t|tƒ}|dur(t|tƒ}|d| 7 }|S )zÝPercent-encodes a request target so that there are no invalid characters

    Pre-condition for this function is that 'target' must start with '/'.
    If that is the case then _TARGET_RE will always produce a match.
    z is not a valid request URINr   )Ú
_TARGET_REr_   r   ÚgroupsrU   Ú_PATH_CHARSÚ_QUERY_CHARS)r®   r_   r&   r'   Úencoded_targetr   r   r   Ú_encode_targetÅ  s   


r´   rG   c              	   C  sž  | st ƒ S t | ¡sd|  } t | ¡ ¡ \}}}}}|du p#| ¡ tv }|r*| ¡ }|ro| d¡\}}}	|p7d}t	 
|	¡}
|
sYt |	¡}|rRtd|	›d| ¡ ›�ƒ‚t|	›d�ƒ‚|
 ¡ \}}|rh|rht|tƒ}|dkrnd}nd\}}}|dur�t|ƒ}d	|  kr‰d
ksŽt| ƒ‚ t| ƒ‚nd}t||ƒ}|r£|r£t|ƒ}t|tƒ}|r¬|r¬t|tƒ}|rµ|rµt|tƒ}|sÄ|dus¿|durÂd}nd}t |||||||d�S )aŒ  
    Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
    performed to parse incomplete urls. Fields not provided will be None.
    This parser is RFC 3986 and RFC 6874 compliant.

    The parser logic and helper functions are based heavily on
    work done in the ``rfc3986`` module.

    :param str url: URL to parse into a :class:`.Url` namedtuple.

    Partly backwards-compatible with :mod:`urllib.parse`.

    Example:

    .. code-block:: python

        import urllib3

        print( urllib3.util.parse_url('http://google.com/mail/'))
        # Url(scheme='http', host='google.com', port=None, path='/mail/', ...)

        print( urllib3.util.parse_url('google.com:80'))
        # Url(scheme=None, host='google.com', port=80, path=None, ...)

        print( urllib3.util.parse_url('/foo?bar'))
        # Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)
    z//Nr   r„   r…   z is not a valid host or portr;   )NNNr   iÿÿ  )r    r"   r#   r$   r&   r'   r(   )r   Ú
_SCHEME_RErŽ   Ú_URI_REr_   r°   r*   r�   Ú
rpartitionÚ_HOST_PORT_REÚ	fullmatchr�   r   r\   rU   Ú_USERINFO_CHARSr¢   r‚   r€   r±   r²   Ú_FRAGMENT_CHARS)rG   r    rE   r&   r'   r(   Únormalize_urir"   Ú_Ú	host_portÚhost_port_matchr™   r#   r$   Úport_intr   r   r   Ú	parse_url×  sr   


ÿÿ
€
ÿÿ



ùrÁ   )rP   r@   rQ   rR   r0   r@   )rP   rW   rQ   rR   r0   rW   )rP   r!   rQ   rR   r0   r!   )r&   r@   r0   r@   )r#   rW   r    r!   r0   rW   )r#   r@   r    r!   r0   r@   )r#   r!   r    r!   r0   r!   )r_   rž   rˆ   r@   r0   r@   )r_   rž   r0   r@   )r§   r@   r0   r¨   )r®   r@   r0   r@   )rG   r@   r0   r   )@Ú
__future__r   ÚreÚtypingÚ	functoolsr   Úurllib.parser   r5   Ú
exceptionsr   Úutilr   r�   Úcompilerj   r—   rµ   r�   ÚUNICODEÚDOTALLr¶   Ú	_IPV4_PATÚ_HEX_PATÚformatÚ	_LS32_PATr   Ú_variationsÚ_UNRESERVED_PATr|   Ú	_IPV6_PATÚ_ZONE_ID_PATÚ_IPV6_ADDRZ_PATÚ_REG_NAME_PATr¯   r–   Ú_IPV6_REr�   Ú_BRACELESS_IPV6_ADDRZ_REr‘   Ú_HOST_PORT_PATr¸   Úsetr•   Ú_SUB_DELIM_CHARSrº   r±   r²   r»   Ú
NamedTupleÚOptionalr@   r¢   r   ÚoverloadrU   r€   r‚   r¥   r˜   r”   rŠ   r´   rÁ   r   r   r   r   Ú<module>   sœ    




ú	

ÿýÿ
ùþÿ 2

.

)




