a
    0f7                     @   s  d dl mZ d dlZd dlmZ ddlmZ ddlmZ g dZ	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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*Z+G d*d+ d+ed+e	Z,d,d- Z-d=d/d0Z.d1d2 Z/d3d4 Z0d5d6 Z1d7d8 Z2d9d: Z3d;d< Z4dS )>    )absolute_importN)
namedtuple   )LocationParseError)sixschemeauthhostportpathqueryfragment)httphttpsNz%[a-fA-F0-9]{2}z^(?:[a-zA-Z][a-zA-Z0-9+-]*:|/)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}))hexZ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   U/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_vendor/urllib3/util/url.py
<listcomp>6       r   )z(?:%25|%)(?:[z]|%[a-fA-F0-9]{2})+z\[z)?\]z!(?:[^\[\]%:/?#]|%[a-fA-F0-9]{2})*z!^(/[^?#]*)(?:\?([^#]*))?(?:#.*)?$^$(z)\]$z)^(%s|%s|%s)(?::0*?(|0|[1-9][0-9]{0,4}))?$zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-~z!$&'()*+,;=:@/?c                       s^   e Zd ZdZdZd fdd	Zedd Zedd	 Zed
d Z	edd Z
dd Z  ZS )Urlz
    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.
    r   Nc              
      sD   |r| dsd| }|d ur&| }tt| | |||||||S )Nr#   )
startswithlowersuperr%   __new__)clsr   r	   r
   r   r   r   r   	__class__r   r   r)   [   s    

zUrl.__new__c                 C   s   | j S )z@For backwards-compatibility with urlparse. We're nice like that.)r
   selfr   r   r   hostnamem   s    zUrl.hostnamec                 C   s&   | j pd}| jdur"|d| j 7 }|S )z)Absolute path including the query string.r#   Nr$   )r   r   )r.   urir   r   r   request_urir   s    

zUrl.request_uric                 C   s   | j rd| j| j f S | jS )z(Network location including host and portz%s:%d)r   r
   r-   r   r   r   netloc|   s    z
Url.netlocc           	      C   s   | \}}}}}}}d}|dur*||d 7 }|dur>||d 7 }|durN||7 }|durf|dt | 7 }|durv||7 }|dur|d| 7 }|dur|d| 7 }|S )a  
        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: ::

            >>> U = parse_url('http://google.com/mail/')
            >>> U.url
            'http://google.com/mail/'
            >>> Url('http', 'username:password', 'host.com', 80,
            ... '/path', 'query', 'fragment').url
            'http://username:password@host.com:80/path?query#fragment'
         Nz://r"   r!   r$   #)str)	r.   r   r	   r
   r   r   r   r   urlr   r   r   r6      s"    zUrl.urlc                 C   s   | j S N)r6   r-   r   r   r   __str__   s    zUrl.__str__)NNNNNNN)__name__
__module____qualname____doc__	__slots__r)   propertyr/   r1   r2   r6   r8   __classcell__r   r   r+   r   r%   R   s&          

	

'r%   c                 C   sv   d}d}|D ]0}|  |}|dk r$q|du s4||k r|}|}q|du sN|dk rX| ddfS | d| | |d d |fS )a  
    .. deprecated:: 1.25

    Given a string and an iterable of delimiters, split on the first found
    delimiter. Return two split parts and the matched delimiter.

    If not found, then the first part is the full input string.

    Example::

        >>> split_first('foo/bar?baz', '?/=')
        ('foo', 'bar?baz', '/')
        >>> split_first('foo/bar?baz', '123')
        ('foo/bar?baz', '', None)

    Scales linearly with number of delims. Not ideal for large number of delims.
    Nr   r3      )find)sdelimsmin_idx	min_delimdidxr   r   r   split_first   s    

rH   utf-8c           
      C   s   | du r| S t | } tdd | \} }| dd}||dk}t }tdt|D ]n}|||d  }t	|}	|r|dks|	d	k r|
 |v r||7 }qX|dt|	d
d  d
   qX|
|S )zfPercent-encodes a URI component without reapplying
    onto an already percent-encoded component.
    Nc                 S   s   |  d S )Nr   )groupupper)matchr   r   r   <lambda>   r   z'_encode_invalid_chars.<locals>.<lambda>rI   surrogatepass   %r   r@      r   )r   ensure_text
PERCENT_REsubnencodecount	bytearrayrangelenorddecodeextendr   zfillrK   )
	componentallowed_charsencodingpercent_encodings	uri_bytesis_percent_encodedencoded_componentibytebyte_ordr   r   r   _encode_invalid_chars   s*    

*rg   c                 C   s   |  d}g }|D ]0}|dkr"qq|dkr6|| q|r|  q| drf|rZ|d rf|dd | drz|d d|S )Nr#   .z..r   r3   )z/.z/..)splitappendpopr&   insertendswithjoin)r   segmentsoutputsegmentr   r   r   _remove_path_dot_segments   s    



rr   c                 C   s   | rt | tjrt| } |tv rt| }|rt| }|r|	d\}}| || }|
drx|dkrx|dd  }n|dd  }dt|t }| d |  | | |d   S |  S n*t| stddd | dD S | S )	Nr@   z%25   %   .c                 S   s   g | ]}t |qS r   )_idna_encode)r   labelr   r   r   r   ,  r   z#_normalize_host.<locals>.<listcomp>rh   )
isinstancer   binary_type
ensure_strNORMALIZABLE_SCHEMESIPV6_ADDRZ_RErL   
ZONE_ID_REsearchspanr&   rg   UNRESERVED_CHARSr'   IPV4_RErn   ri   )r
   r   is_ipv6rL   startendzone_idr   r   r   _normalize_host  s*    


 

r   c                 C   s   | rt dd | D rzddlm} W n" tyH   ttdd  Y n0 z|j|  dddW S  |j	y   ttd|  d  Y n0 |  d	S )
Nc                 s   s   | ]}t |d kV  qdS )rP   N)rY   r   r   r   r   	<genexpr>2  r   z_idna_encode.<locals>.<genexpr>r   )idnaz-Unable to parse URL without the 'idna' moduleT)strict
std3_rulesz#Name '%s' is not a valid IDNA labelascii)
anypip._vendorr   ImportErrorr   
raise_fromr   rT   r'   	IDNAError)namer   r   r   r   rv   1  s    

rv   c                 C   s>   t |  \}}t|t} t|t}|dur:| d| 7 } | S )zHPercent-encodes a request target so that there are no invalid charactersNr$   )	TARGET_RErL   groupsrg   
PATH_CHARSQUERY_CHARS)targetr   r   r   r   r   _encode_targetC  s    

r   c              	      s  | s
t  S | }t| s d|  } zt|  \}}}}}|du pN| tv }|r\| }|r|d\}}	}
|pvd}t	|
 \}}|r|rt
|t}|dkrd}n
d\}}}|durt|}d|  krdksn t| t||}|r
|r
t|}t
|t}|r |r t
|t}|r6|r6t
|t}W n( ttfy`   tt|d Y S 0 |s|dus||durd}nd}t| tjrtj ntj  fd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:`urlparse`.

    Example::

        >>> parse_url('http://google.com/mail/')
        Url(scheme='http', host='google.com', port=None, path='/mail/', ...)
        >>> parse_url('google.com:80')
        Url(scheme=None, host='google.com', port=80, path=None, ...)
        >>> parse_url('/foo?bar')
        Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...)
    z//Nr"   r3   )NNNr   i  c                    s   | d u r| S  | S r7   r   )r   ensure_funcr   r   ensure_type  s    zparse_url.<locals>.ensure_typer   )r%   	SCHEME_REr~   URI_RErL   r   r'   r{   
rpartition_HOST_PORT_RErg   USERINFO_CHARSintr   r   rr   r   r   FRAGMENT_CHARS
ValueErrorAttributeErrorr   r   rx   	text_typerQ   rz   )r6   
source_urlr   	authorityr   r   r   normalize_urir	   _	host_portr
   r   r   r   r   r   	parse_urlM  sd    





r   c                 C   s   t | }|jpd|j|jfS )z4
    Deprecated. Use :func:`parse_url` instead.
    r   )r   r   r/   r   )r6   pr   r   r   get_host  s    r   )rI   )5
__future__r   recollectionsr   
exceptionsr   packagesr   	url_attrsr{   compilerR   r   UNICODEDOTALLr   IPV4_PATHEX_PATformatLS32_PATr   _variationsUNRESERVED_PATrn   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   r%   rH   rg   rr   r   rv   r   r   r   r   r   r   r   <module>   sd   


	

]#
"
a