o
    .j                     @  s  U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	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dlmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZ dd	lmZm Z m!Z!m"Z" dd
lm#Z$ ej%dkrddl&Z&ndZ&ddl'm(Z( ddl)m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZB ddlCmDZDmEZE ddlFmGZG zddlHmIZI W n eJy   dZIY nw ejKrddlLmMZM ddlNmOZOmPZPmQZQmRZR ddlmSZSmTZT e eZe e Z dZUdd d!ZVd"eWd#< d$Xe	Yd%eDd&d'd( ZZd)eWd*< ej%d+krHdd.d/Z[dd1d2Z!dd6d7Z\ed8d9ddd?d@Z]ddCdDZ^ej_ddHdIZ`ddMdNZaebdOZcebdPZdddSdTZeddVdWZfddYdZZgddd\d]ZhddadbZiddedfZjddidjZkddmdnZlddtduZmddxdyZnebdzeoepZqdddZresdZtdddZudddZvdd ddZwedd9d!ddZxd"ddZyd#ddZzd$ddZ{d$ddZ|d%ddZ}d&ddZ~ej_d'ddZd(ddZd)d*ddZd+ddZ	&d,d-ddZd.d/ddZd0ddZd1ddZd2ddZd3ddńZd4ddǄZd5dd̄Zd5dd΄Zd6ddӄZd7ddׄZd8dd܄Zd9ddZd:ddZd;d<ddZd=ddZd>ddZd>ddZd?ddZd?ddZd@ddZdAddZdBd dZdCddZejdDddZejdEd	dZdFd
dZdS (G  z
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
    )annotationsN)OrderedDict)	lru_cache)	CookieJar)NetrcParseErrornetrc)quoteunquoteurljoinurlparse
urlunparseuses_relative)
getproxiesgetproxies_environmentproxy_bypassproxy_bypass_environment)parse_http_list
emscripten)
from_bytes   __version__)iscoroutinefunction)
InvalidURLMissingSchemaUnrewindableBodyError)RevocationConfigurationRevocationStrategy)ConnectionInfo)BaseResolverManyResolverProtocolResolverResolverDescription)AsyncBaseResolverAsyncManyResolverAsyncResolverDescription)ExtensionFromHTTPload_extension)AsyncExtensionFromHTTP)make_headers	parse_url)CaseInsensitiveDict)BACKENDssl)RequestsCookieJar)AsyncResponsePreparedRequestRequestResponse)AsyncResolverTypeResolverType)z.netrc_netrcP   i  httphttpszdict[str, int]DEFAULT_PORTSz, z,\s*T)accept_encodingzaccept-encodingstrDEFAULT_ACCEPT_ENCODINGwin32returnboolc              	   C  s   zdd l }W n
 ty   Y dS w z||jd}t||dd }||dd }W n ttfy8   Y dS w |r=|s?dS |d}t	d |}|D ]*}|dkrXd| vrX d	S |
dd
}|
dd}|
dd}t|| tjru d	S qKdS )Nr   Fz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableProxyOverride;z<local>.Tz\.*z.*?)winregImportErrorOpenKeyHKEY_CURRENT_USERintQueryValueExOSError
ValueErrorsplitfilterreplacerematchI)hostrG   internetSettingsproxyEnableproxyOverridetest rZ   C/home/thesage/.local/lib/python3.10/site-packages/niquests/utils.pyproxy_bypass_registryY   s<   

r\   rU   c                 C  s   t  rt| S t| S )zReturn True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        )r   r   r\   )rU   rZ   rZ   r[   r      s   r   o
typing.AnyrK   c              	   C  s  d }d}t | drt| }n't | dr| j}nt | dr5z|  }W n tjtfy.   Y nw t|j}t | dr}t	| j
s}z| 
 }W n tyT   |d urR|}Y n)w t | dr}|d u r}z| dd | 
 }| |pnd W n ty|   d}Y nw |d u rd}td|| S )Nr   __len__lenfilenotellseek   )hasattrr`   ra   ioUnsupportedOperationAttributeErrorosfstatst_sizer   rb   rM   rc   max)r]   total_lengthcurrent_positionra   rZ   rZ   r[   	super_len   s@   



ro   @   )maxsizeFurl
str | Noneraise_errorstuple[str, str] | Nonec              
   C  sJ  | du rdS t jd}|dur|fntdd tD }z<tdd |D d}|du r.W dS t| }|j}|du r<W dS t|	|}|rV|\}}	}
|rS|
rS||
fW S W dS W dS  t
yr } z|rgtd|W Y d}~dS d}~w ty } z|rtd|W Y d}~dS d}~w ty } z|rtd|W Y d}~dS d}~ww )	z;Returns the Requests tuple auth for a given url from netrc.NNETRCc                 s  s    | ]}d | V  qdS )z~/NrZ   .0frZ   rZ   r[   	<genexpr>   s    z!get_netrc_auth.<locals>.<genexpr>c                 s  s0    | ]}t jt j|rt j|V  qd S N)ri   pathexists
expanduserrw   rZ   rZ   r[   rz      s   . zSyntax error in netrc filez+Problem accessing or reading the netrc filez6Unexpected error while retrieving netrc authenticators)ri   environgettupleNETRC_FILESnextr*   hostnamer   authenticatorsr   rN   rM   rh   RuntimeError)rr   rt   
netrc_filenetrc_locations
netrc_pathrirU   r5   login_passworderZ   rZ   r[   get_netrc_auth   sT    







r   obj	typing.IOc                 C  sB   t | dd}|rt|tr|d dkr|d dkrtj|S dS )z0Tries to guess the filename of the given object.nameNr   <>)getattr
isinstancer<   ri   r|   basename)r   r   rZ   rZ   r[   guess_filename   s   &r   filenamestr | bytes | os.PathLike-typing.Generator[typing.BinaryIO, None, None]c                 c  sz    t jtj| d\}}z"t|d}|V  W d   n1 s"w   Y  t||  W dS  ty<   t|  w )z-Write a file to the disk in an atomic fashion)dirwbN)	tempfilemkstempri   r|   dirnamefdopenrQ   BaseExceptionremove)r   tmp_descriptortmp_nametmp_handlerrZ   rZ   r[   atomic_open   s   
r   valuetyping.Any | NoneOrderedDict | Nonec                 C  s,   | du rdS t | tttfstdt| S )a  Take an object and test to see if it can be represented as a
    dictionary. Unless it can not be represented as such, return an
    OrderedDict, e.g.,

    ::

        >>> from_key_val_list([('key', 'val')])
        OrderedDict([('key', 'val')])
        >>> from_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples
        >>> from_key_val_list({'key': 'val'})
        OrderedDict([('key', 'val')])
    N+cannot encode objects that are not 2-tuples)r   r   listdictrN   r   r   rZ   rZ   r[   from_key_val_list  s
   r   _KT_VTLdict[_KT, _VT] | typing.Mapping[_KT, _VT] | typing.Iterable[tuple[_KT, _VT]]list[tuple[_KT, _VT]]c                 C  sD   | du rt dt| ttttfrt dt| dr|  } t| S )a  Take an object and test to see if it can be represented as a
    dictionary. If it can be, return a list of tuples, e.g.,

    ::

        >>> to_key_val_list([('key', 'val')])
        [('key', 'val')]
        >>> to_key_val_list({'key': 'val'})
        [('key', 'val')]
        >>> to_key_val_list('string')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples
    Nz%cannot accept None in to_key_val_listr   items)	rN   r   r<   bytesr@   rK   re   r   r   r   rZ   rZ   r[   to_key_val_list  s   
r   	list[str]c                 C  sX   g }t | D ]#}|dd |dd   krdkr$n nt|dd }|| q|S )a  Parse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Quotes are removed automatically after parsing.

    It basically works like :func:`parse_set_header` just that items
    may appear multiple times and case sensitivity is preserved.

    The return value is a standard :class:`list`:

    >>> parse_list_header('token, "quoted value"')
    ['token', 'quoted value']

    To create a header from the :class:`list` again, use the
    :func:`dump_header` function.

    :param value: a string with a list header.
    :return: :class:`list`
    Nr   r   ")_parse_list_headerunquote_header_valueappend)r   resultitemrZ   rZ   r[   parse_list_header<  s   (r   typing.Mapping[str, str | None]c                 C  sx   i }t | D ]3}d|vrd||< q|dd\}} | dd | dd   kr+dkr5n nt| dd } | ||< q|S )aM  Parse lists of key, value pairs as described by RFC 2068 Section 2 and
    convert them into a python dict:

    >>> d = parse_dict_header('foo="is a fish", bar="as well"')
    >>> type(d) is dict
    True
    >>> sorted(d.items())
    [('bar', 'as well'), ('foo', 'is a fish')]

    If there is no value for a key it will be `None`:

    >>> parse_dict_header('key_without_value')
    {'key_without_value': None}

    To create a header from the :class:`dict` again, use the
    :func:`dump_header` function.

    :param value: a string with a dict header.
    :return: :class:`dict`
    =Nr   r   r   )r   rO   r   )r   r   r   r   rZ   rZ   r[   parse_dict_header[  s   (
r   is_filenamec                 C  s^   | r-| d | d   krdkr-n | S | dd } |r#| dd dkr-|  dd d	dS | S )
zUnquotes a header value.  (Reversal of :func:`quote_header_value`).
    This does not use the real unquoting but what browsers are actually
    using for quoting.

    :param value: the header value to unquote.
    r   r   r   r   Nrd   z\\\z\")rQ   )r   r   rZ   rZ   r[   r   }  s   "r   cjr   dict[str, str | None]c                 C  s   dd | D }|S )zoReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    c                 S  s   i | ]}|j |jqS rZ   )r   r   )rx   cookierZ   rZ   r[   
<dictcomp>      z'dict_from_cookiejar.<locals>.<dictcomp>rZ   )r   cookie_dictrZ   rZ   r[   dict_from_cookiejar  s   r   r.   RequestsCookieJar | CookieJarc                 C  s   ddl m} ||| S )zReturns a CookieJar from a key/value dictionary.

    :param cj: CookieJar to insert cookies into.
    :param cookie_dict: Dict of key/values to insert into CookieJar.
    r   )cookiejar_from_dict)cookiesr   )r   r   r   rZ   rZ   r[   add_dict_to_cookiejar  s   
r   header1tuple[str, dict[str, str | typing.Literal[True]]]c           
      C  s   |  d}|d  |dd }}i }d}|D ]0}| }|rH|d}}|d}	|	dkrB|d|	 |}||	d d |}||| < q||fS )	zReturns content type and parameters from given header

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters
    rC   r   r   Nz"' Tr   r   )rO   stripfindlower)
r   tokenscontent_typeparamsparams_dictitems_to_stripparamkeyr   index_of_equalsrZ   rZ   r[   _parse_content_type_header  s   



r   headerstyping.Mapping[str, str]c                 C  sV   |  d}|s	dS t|\}}d|v r#t|d tr!|d dS dS d|v r)dS dS )zmReturns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    zcontent-typeNcharsetz'"zapplication/jsonutf-8)r   r   r   r<   r   )r   r   r   rZ   rZ   r[   get_encoding_from_headers  s   
 r   iterator#typing.Generator[bytes, None, None]rr2   )typing.Generator[bytes | str, None, None]c                 c  sj    |j du r| E dH  dS t|j dd}| D ]}||}|r$|V  q|jddd}|r3|V  dS dS zStream decodes an iterator.NrQ   )errors    T)finalencodingcodecsgetincrementaldecoderdecode)r   r   decoderchunkrvrZ   rZ   r[   stream_decode_response_unicode  s   



r   "typing.AsyncGenerator[bytes, None](typing.AsyncGenerator[bytes | str, None]c                 C s   |j du r| 2 z	3 dH W }|V  q6 dS t|j dd}| 2 z3 dH W }||}|r0|V  q 6 |jddd}|r@|V  dS dS r   r   )r   r   r   r   r   rZ   rZ   r[   astream_decode_response_unicode  s"   


r   _SVstringslice_length
int | None!typing.Generator[_SV, None, None]c                 c  sX    d}|du s|dkrt | }|t | k r*| |||  V  ||7 }|t | k sdS dS )z Iterate over slices of a string.r   N)r`   )r   r   posrZ   rZ   r[   iter_slices	  s   r   zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~uric              	   C  s   |  d}tdt|D ]Q}|| dd }t|dkrT| rTz	tt|d}W n ty8   td| dw |tv rJ||| dd  ||< qd||  ||< qd||  ||< qd		|S )
zUn-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
    %r   r   rd      z"Invalid percent-escape sequence: ''N )
rO   ranger`   isalnumchrrK   rN   r   UNRESERVED_SETjoin)r   partsihcrZ   rZ   r[   unquote_unreserved  s   

r  c                 C  s:   d}d}z	t t| |dW S  ty   t | |d Y S w )zRe-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.
    z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~)safe)r   r  r   )r   safe_with_percentsafe_without_percentrZ   rZ   r[   requote_uri-  s   r      mask	totalbitsc                 C  s   d| > d ||  > }|S )a
  Converts a mask from /xx format to an integer
    to be used as a mask for IP's in int format
    Example: if mask is 24 function returns 0xFFFFFF00
             if mask is 24 and totalbits=128 function
                returns 0xFFFFFF00000000000000000000000000
    r   rZ   )r  r  bitsrZ   rZ   r[   _get_mask_bitsA  s   r     addrc                 C  s   t | jS )zCached check for whether an IP address is private. Avoids repeated
    ``ipaddress.ip_address()`` construction which is expensive, especially for IPv6.)	ipaddress
ip_address
is_private)r  rZ   rZ   r[   is_private_ipM  s   r  ipnetc                 C  s   | d\}}t| r,t|r,tdt| d }tt|}tdt|d }n8t| rbt|rbtdt	tj
| \}}|d> |A }tt|d}tdt	tj
|\}	}
|	d> |
A }ndS ||@ ||@ kS )a!  This function allows you to check if an IP belongs to a network subnet

    Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
             returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
             returns True if ip = 1:2:3:4::1 and net = 1:2:3:4::/64
    /z>Lr   z>QQrp      F)rO   is_ipv4_addressstructunpacksocket	inet_atonr  rK   is_ipv6_address	inet_ptonAF_INET6)r  r  netaddrr  ipaddrnetmasknetwork
ipaddr_msb
ipaddr_lsbnetwork_msbnetwork_lsbrZ   rZ   r[   address_in_networkT  s   r0  c                 C  s&   ddd|  > d A }t td|S )zpConverts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0
    l    r   r  z>I)r#  	inet_ntoar!  pack)r  r  rZ   rZ   r[   dotted_netmaskk  s   r3  	string_ipc                 C  s&   zt |  W dS  ty   Y dS w NFT)r#  r$  rM   r4  rZ   rZ   r[   r   t  s   r   c                 C  s*   z
t t j|  W dS  ty   Y dS w r5  r#  r&  r'  rM   r6  rZ   rZ   r[   r%  |  s   r%  abc                 C  s4   zt t j| t t j|kW S  ty   Y dS w )zD
    Compare 2 IPs, uses socket.inet_pton to normalize IPv6 IPs
    Fr7  )r8  r9  rZ   rZ   r[   compare_ipv6  s
   r:  string_networkc                 C  s   |  ddkrB| d\}}t|dks| du rdS t|}t|r0|dk s,|dkr.dS dS t|r@|dk s<|dkr>dS dS dS dS )zD
    Very simple check of the cidr format in no_proxy variable.
    r  r      Fr  r  T)countrO   r`   isdigitrK   r   r%  )r;  addressr  mask_intrZ   rZ   r[   is_valid_cidr  s   rA  env_name"typing.Generator[None, None, None]c              	   c  sz    |du}|rt j| }|t j| < zdV  W |r*|du r#t j| = dS |t j| < dS dS |r<|du r7t j| = w |t j| < w )zSet the environment variable 'env_name' to 'value'

    Save previous value, yield, and then restore the previous value stored in
    the environment variable 'env_name'.

    If 'value' is None, do nothingN)ri   r   r   )rB  r   value_changed	old_valuerZ   rZ   r[   set_environ  s   
rF  no_proxyc           
   
   C  sZ  ddd}|}|du r|d}t | }|jdu rd	S |r|td
d |dddD }t|js6t|jr[|D ]!}t|rHt|j|rG d	S q8|j|krP d	S t	|j|rY d	S q8n!|j}|j
ri|d|j
 7 }|D ]}|j|sx||r{ d	S qktd| zt|j}	W n ttjfy   d}	Y nw W d   n1 sw   Y  |	rd	S dS )z:
    Returns whether we should bypass proxies or not.
    r   r<   r?   rs   c                 S  s   t j| pt j|  S r{   )ri   r   r   upper)r   rZ   rZ   r[   	get_proxy  s   z(should_bypass_proxies.<locals>.get_proxyNrG  Tc                 s  s    | ]}|r|V  qd S r{   rZ   )rx   rU   rZ   rZ   r[   rz     s    z(should_bypass_proxies.<locals>.<genexpr> r  ,:F)r   r<   r?   rs   )r   r   r   rQ   rO   r   r%  rA  r0  r:  portendswithrF  r   	TypeErrorr#  gaierror)
rr   rG  rI  no_proxy_argparsedno_proxy_listproxy_iphost_with_portrU   bypassrZ   rZ   r[   should_bypass_proxies  sN   

 
rW  dict[str, str]c                 C  s"   t  }|si S t| |dri S |S )z/
    Return a dict of environment proxies.
    rG  )r   rW  )rr   rG  proxiesrZ   rZ   r[   get_environ_proxies  s   r[  rZ  &typing.Mapping[str, str | None] | Nonec           
      C  s   |pi }|sdS t | }|jdu r||j|dS |jd |j |jd|j dg}|j dvrk|j}d}d|v rFt|jddd\}}zt||}W n	 tyV   Y nw |	|}|
| |
|d |j  d}|D ]}	|	|v r|||	 } |S qo|S )	zSelect a proxy for the url, if applicable.

    :param url: The url being for the request
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    Nall://zall://r7   +r   )maxsplit)r   r   r   schemer   r   rO   r'   rH   scheme_to_http_schemer   )
rr   rZ  urlparts
proxy_keysmaybe_extension_schemeimplementationextension_classparent_schemeproxy	proxy_keyrZ   rZ   r[   select_proxy	  s@   


rk  requestPreparedRequest | Requestdict[str, str] | None	trust_envc           	      C  s   |dur|ni }| j }|dusJ dt|}|d}| }|r?t||ds?t||d}|||d}|r?||| |S )a  This method takes proxy information from a request and configuration
    input to resolve a mapping of target proxies. This will consider settings
    such a NO_PROXY to strip proxy configurations.

    :param request: Request or PreparedRequest
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    :param trust_env: Boolean declaring whether to trust environment configs
    Nz,PreparedRequest is not initialized correctlyrG  rY  r]  )rr   parse_schemer   copyrW  r[  
setdefault)	rl  rZ  ro  rr   ra  rG  new_proxiesenviron_proxiesri  rZ   rZ   r[   resolve_proxies<  s   
ru  niquestsr   c                 C  s   |  dt  S )z>
    Return a string representing the default user agent.
    r  r   )r   rZ   rZ   r[   default_user_agent\  s   rw  r+   c                   C  s(   t dkrtt tdddS tddiS )Nutlsz*/*z
keep-alive)z
User-AgentzAccept-EncodingAccept
Connectionrz  )r,   r+   rw  r=   rZ   rZ   rZ   r[   default_headersc  s   r{  list[dict[str, str]]c           	   
   C  s   g }d}|  |} | s|S td| D ]M}z
|dd\}}W n ty-   |d}}Y nw d| di}|dD ] }z	|d\}} W n
 tyO   Y  nw |  ||| |< q:|| q|S )	zReturn a list of parsed link headers proxies.

    i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
    z '"z, *<rC   r   r  rr   z<> '"r   )r   rR   rO   rN   r   )	r   linksreplace_charsvalrr   r   linkr   r   rZ   rZ   r[   parse_header_linksw  s*   
r  
new_schemec                 C  sp   t | }|\}}}}}}}	|j}
|
s||
}
}|r"|
r"d||
g}
|du r(|}|du r.d}t||
|d||	fS )zGiven a URL that may or may not have a scheme, prepend the given scheme.
    Does not replace a present scheme with the one provided as an argument.
    @Nr  )r*   netlocr  r   )rr   r  rR  ra  authrU   rM  r|   queryfragmentr  rZ   rZ   r[   prepend_scheme_if_needed  s   
r  tuple[str, str]c              	   C  sf   t | }|jrd|jvrdS t|jdd\}}zt|t|f}W |S  ttfy2   d}Y |S w )zdGiven a url with authentication components, extract them into a tuple of
    username,password.
    rL  )r  r  r   )r*   r  r   rO   r	   rh   rO  )rr   rR  usernamer   r  rZ   rZ   r[   get_auth_from_url  s   r  c                 C  sF   t | \}}}}}}|s||}}|ddd }t|||||dfS )zF
    Given a url remove the fragment and the authentication part.
    r  r   r   r  )r   rsplitr   )rr   ra  r  r|   r   r  r  rZ   rZ   r[   urldefragauth  s
   
r  prepared_requestr0   Nonec                 C  sR   t | jdd}|dur%t| jtr%z|| j W dS  ty$   tdw td)zfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    rc   N;An error occurred when rewinding request body for redirect.+Unable to rewind request body for redirect.r   bodyr   _body_positionrK   rM   r   r  	body_seekrZ   rZ   r[   rewind_body  s   r  c                   sZ   t | jdd}|dur)t| jtr)z|| jI dH  W dS  ty(   tdw td)z!Async counterpart of rewind_body.rc   Nr  r  r  r  rZ   rZ   r[   arewind_body  s   r  
definitionResolverType | Noner   c                 C    | du rt jdd}|durt|} nttj S t| t	r#| S t| t
r/t| g}n-t| tr8| g}n$t| trX| sFttj S t| d t
rUdd | D }n| }ntdg }d}|D ]_}t|t
r|t| |d jtjkr{d	}d
|d v r|d jd
 du rd|d d< |d jd
= qb|| d
|d v r|d jd
 du rd|d d< |d jd
= |d jtjkrd	}qb|s|td |D ]}d|vrd|vrd|vrt |d< qtdd |D  S )AInstantiate a unique resolver, reusable across the Session scope.NNIQUESTS_DNS_URLr   c                 S     g | ]}t |qS rZ   )r"   from_urlrx   r   rZ   rZ   r[   
<listcomp>  r   z#create_resolver.<locals>.<listcomp>!invalid resolver definition givenFr   Tverify	cert_reqs system://default?hosts=localhostca_cert_dataca_cert_dirca_certsc                 S     g | ]}|  qS rZ   newrx   r   rZ   rZ   r[   r  .      )ri   r   r   r"   r  r!   SYSTEMr  r   r   r<   r   rN   r   protocolkwargswassimagenerate_ca_bundler    r  overrule_dnsresolver	resolverscan_resolve_localhostresolver_descriptionrdrZ   rZ   r[   create_resolver  V   





r  AsyncResolverType | Noner#   c                 C  r  )r  Nr  r   c                 S  r  rZ   )r%   r  r  rZ   rZ   r[   r  E  r   z)create_async_resolver.<locals>.<listcomp>r  Fr   Tr  r  r  r  r  r  c                 S  r  rZ   r  r  rZ   rZ   r[   r  n  r  )ri   r   r   r%   r  r!   r  r  r   r#   r<   r   rN   r   r  r  r  r  r$   r  rZ   rZ   r[   create_async_resolver1  r  r  disable_ipv4disable_ipv6socket.AddressFamilyc                 C  s   | rt jS |r
t jS t jS r{   )r#  r'  AF_INET	AF_UNSPEC)r  r  rZ   rZ   r[   resolve_socket_familyq  s
   r  responseAsyncResponse | Responsec                 C  sH   | j }t|jdko|jd tu}|r|jd | _ d S | d | _ d S )Nr   r   )	__class__r`   	__bases__object__subclasses__)r  response_classis_asyncrZ   rZ   r[   _swap_contexty  s
   r  ConnectionInfo | Nonec                 C  s8   | d u rd S t  }t|  D ]
\}}t||| q|S r{   )r   varsr   setattr)r]   nattrr  rZ   rZ   r[   _deepcopy_ci  s   r     default
max_lengthc                 C  s   z| d|  dd|d  }W | S  tyX } z:|dur&|W  Y d}~S z| d|  dd|d  }| W W  Y d}~S  tyG   Y nw td| d|  d|d}~ww )zWe tend to extract url scheme often enough, but we were crazy
    enough to use urlparse for it...! We were wasting precious CPU cycles.
    Return used scheme url, lowercased.Nr^  r   rL  zInvalid URL z0: No scheme supplied. Perhaps you meant https://rF   )indexrN   r   r   )rr   r  r  ra  r   outsider_schemerZ   rZ   r[   rp    s   rp  basec                 C  sb   t | dd}|r|tv rt| |S d| t|d  }t||}|dr/||tdd  S |S )zGRFC 3986 relative join that also works for niquests' synthetic schemes.r  r  r9   Nzhttps://)rp  r   r
   r`   
startswith)r  rr   ra  tempjoinedrZ   rZ   r[   urljoin_safe  s   


r  	conn_infoc                 C  H   | d u s| j d u s| jd u rdS dd t| jdg D }|s"dS dS )NFc                 S     g | ]	}| d r|qS zhttp://r  rx   eprZ   rZ   r[   r        z#is_ocsp_capable.<locals>.<listcomp>OCSPTcertificate_dercertificate_dictr   r   r  	endpointsrZ   rZ   r[   is_ocsp_capable  s   r  c                 C  r  )NFc                 S  r  r  r  r  rZ   rZ   r[   r    r  z"is_crl_capable.<locals>.<listcomp>crlDistributionPointsTr  r  rZ   rZ   r[   is_crl_capable  s   r  revocation_configurationRevocationConfiguration | Nonec                 C  >   t | sdS |d u rdS |jtjtjhv rdS t| sdS dS r5  )r  strategyr   
PREFER_CRL	CHECK_ALLr  r  r  rZ   rZ   r[   should_check_crl     r  c                 C  r  r5  )r  r  r   PREFER_OCSPr  r  r  rZ   rZ   r[   should_check_ocsp  r  r  	extensiontype[ExtensionFromHTTP]c                      ddl m mmmmm ddl m
 ddlm	m
mm	 ddlm ddlm ddlm ddlm G  	
fdd	d	| }|S )
z
    We want to properly map exceptions from below (urllib3-future) into our own exceptions.
    This function purposely wrap the extension class to achieve that.
    Warning: synchronous context only!
    r   ChunkedEncodingErrorConnectionErrorContentDecodingErrorInvalidHeader
ProxyErrorReadTimeoutSSLErrorClosedPoolErrorDecodeErrorProtocolErrorReadTimeoutError	HTTPErrorr  r  c                      z   e Zd Zd	
 f	ddZd	
 fdd	Zd	
 fd
dZ  ZS )z:wrap_extension_for_http.<locals>._WrappedExtensionFromHTTPr?   str | bytes | Nonec              
     s   z
t  j|i |W S  y } z |d }~w y) } z|d }~w y8 } z|d }~w yG } z|d }~ww r{   supernext_payloadselfargsr  r   	r  r   r  r	  r  r
  RequestsSSLError	_SSLErrorr  rZ   r[   r  *  s   zGwrap_extension_for_http.<locals>._WrappedExtensionFromHTTP.next_payloadbufstr | bytesr  c              
     s   z	t  | W d S  tfy } z|d }~w  y* } z|d }~w 
y9 } z|d }~w fyb } zt|rK|t|rT|t|	r]| d }~ww r{   r  send_payloadrM   r   r  r  errr   r  r  r  r	  r  r  r
  r  
_HTTPError_InvalidHeader_ProxyErrorr  r  rZ   r[   r  6  s*   


zGwrap_extension_for_http.<locals>._WrappedExtensionFromHTTP.send_payloadc              
     s   zt    W d S  tfy } z|d }~w  y) } z|d }~w 
y8 } z|d }~w fya } zt|rJ|t|rS|t|	r\| d }~ww r{   r  closerM   r   r  r  r   r   rZ   r[   r%  I  s*   


z@wrap_extension_for_http.<locals>._WrappedExtensionFromHTTP.closer?   r  r  r  r?   r  r?   r  __name__
__module____qualname__r  r  r%  __classcell__rZ   r  r  r  r   r  r  r	  r  r  r
  r  r!  r"  r#  r  r  r[   _WrappedExtensionFromHTTP)      &.r1  
exceptionsr  r  r   r  r  r  r  packages.urllib3.exceptionsr  r  r	  r
  r  )r  r1  rZ   r/  r[   wrap_extension_for_http      	03r6  type[AsyncExtensionFromHTTP]c                   r  )
z
    We want to properly map exceptions from below (urllib3-future) into our own exceptions.
    This function purposely wrap the extension class to achieve that.
    Warning: asynchronous context only!
    r   r  r  r  r  r  r  c                      r  )zEasync_wrap_extension_for_http.<locals>._AsyncWrappedExtensionFromHTTPr?   r  c              
     s   zt  j|i |I d H W S  y } z |d }~w y- } z|d }~w y< } z|d }~w yK } z|d }~ww r{   r  r  r  rZ   r[   r    s    zRasync_wrap_extension_for_http.<locals>._AsyncWrappedExtensionFromHTTP.next_payloadr  r  r  c              
     s   zt  |I d H  W d S  tfy } z|d }~w  y. } z|d }~w 
y= } z|d }~w fyf } zt|rO|t|rX|t|	ra| d }~ww r{   r  r  r   rZ   r[   r    s,   


zRasync_wrap_extension_for_http.<locals>._AsyncWrappedExtensionFromHTTP.send_payloadc              
     s   zt   I d H  W d S  tfy } z|d }~w  y- } z|d }~w 
y< } z|d }~w fye } zt|rN|t|rW|t|	r`| d }~ww r{   r$  r&  r   rZ   r[   r%    s,   


zKasync_wrap_extension_for_http.<locals>._AsyncWrappedExtensionFromHTTP.closer'  r(  r)  r*  rZ   r/  r0  r[   _AsyncWrappedExtensionFromHTTP  r2  r9  r3  )r  r9  rZ   r/  r[   async_wrap_extension_for_http_  r7  r:  excr   c                 C  sL   t  }| }|r$||vr$t|tjrdS || |jp|j}|r$||vsdS )NTF)setr   asyncioCancelledErroradd	__cause____context__)r;  seencurrZ   rZ   r[   is_cancelled_error_root_cause  s   
rD  datar   c                 C  sB   t | g dd }|d ur|jdkr|jrdS |jddS d S )N)r   zutf-16zutf-32z	utf-16-lez	utf-16-bez	utf-32-lez	utf-32-be)cp_isolationutf_8z	utf-8-sigr   -)r   bestr   bomrQ   )rE  encoding_guessrZ   rZ   r[   guess_json_utf  s   rL  base_urlc                 C     d S r{   rZ   rM  rr   rZ   rZ   r[   merge_base_url     rP  c                 C  rN  r{   rZ   rO  rZ   rZ   r[   rP    rQ  c                 C  s^   | d u s|d u r
|S t |dddkr-| dr| d d } |r)|ds)d| }| | S |S )Nr  r  r  r   )rp  rN  r  rO  rZ   rZ   r[   rP    s   

)r?   r@   )rU   r<   r?   r@   )r]   r^   r?   rK   )F)rr   rs   rt   r@   r?   ru   )r   r   r?   rs   )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?   r   )r   r<   r?   r   )r   r   r?   rs   )r   r   r   r2   r?   r   )r   r   r   r2   r?   r   )r   r   r   r   r?   r   )r   r<   r?   r<   )r  )r  rK   r  rK   r?   rK   )r  r<   r?   r@   )r  r<   r  r<   r?   r@   )r  rK   r?   r<   )r4  r<   r?   r@   )r8  r<   r9  r<   )r;  r<   r?   r@   )rB  r<   r   rs   r?   rC  )rr   r<   rG  rs   r?   r@   r{   )rr   r<   rG  rs   r?   rX  )rr   r<   rZ  r\  r?   rs   )T)rl  rm  rZ  rn  ro  r@   r?   rX  )rv  )r   r<   r?   r<   )r?   r+   )r   r<   r?   r|  )rr   r<   r  r<   r?   r<   )rr   r<   r?   r  )rr   r<   r?   r<   )r  r0   r?   r  )r  r  r?   r   )r  r  r?   r#   )r  r@   r  r@   r?   r  )r  r  r?   r  )r]   r  r?   r  )Nr  )rr   r<   r  rs   r  rK   r?   r<   )r  r<   rr   r<   r?   r<   )r  r  r?   r@   )r  r  r  r  r?   r@   )r  r  r?   r  )r  r8  r?   r8  )r;  r   r?   r@   )rE  r   r?   rs   )rM  rs   rr   r  r?   r  )rM  rs   rr   r<   r?   r<   )rM  rs   rr   rs   r?   rs   )__doc__
__future__r   r=  r   
contextlibrf   r  ri   rR   r#  r!  sysr   typingcollectionsr   	functoolsr   http.cookiejarr   r   r   urllib.parser   r	   r
   r   r   r   urllib.requestr   r   r   r   r   r   platformr  charset_normalizerr   r   _compatr   r4  r   r   r   extensions.revocationr   r   packages.urllib3r   !packages.urllib3.contrib.resolverr   r    r!   r"   (packages.urllib3.contrib.resolver._asyncr#   r$   r%   &packages.urllib3.contrib.webextensionsr&   r'   -packages.urllib3.contrib.webextensions._asyncr(   packages.urllib3.utilr)   r*   
structuresr+   packages.urllib3.contrib.anytlsr,   rH   TYPE_CHECKINGr   r.   modelsr/   r0   r1   r2   r3   r4   r   r:   __annotations__r  rO   r=   r\   ro   r   r   contextmanagerr   r   TypeVarr   r   r   r   r   r   r   r   r   r   r   r   r<   r   r   r   	frozensetr  r  r  r  r  r0  r3  r   r%  r:  rA  rF  rW  r[  rk  ru  rw  r{  r  r  r  r  r  r  r  r  r  r  r  rp  r  r  r  r  r  r6  r:  rD  rL  overloadrP  rZ   rZ   rZ   r[   <module>   s     



$'3*

"
	
=6 #@@]]