o
    ‡ôjâ�  ã                   @  sB  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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 dd	lmZ dd
lmZ ddl m!Z!m"Z"m#Z#m$Z$ ddl%m&Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl(m6Z7 ddl8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@ erÓddlAmBZB ddlmCZC ddlm%ZD ddlEmFZFmGZGmHZH dZIdeJd< e K¡ ZLdeJd< dddœZMdeJd< edƒZNed ƒZOd! Pe Qd"ed#d$�d% ¡¡ZRdeJd&< e
jSd'k�rdÕd+d,„ZTdÕd-d.„Z/dÖd2d3„ZUd×d7d8„ZV	9dØdÙd>d?„ZWdÚdBdC„ZXdÛdEdF„ZYejZdÜdIdJ„ƒZ[dÝdNdO„Z\edÞdQdR„ƒZ]edßdUdR„ƒZ]dàdXdR„Z]dádZd[„Z^dâd]d^„Z_dØdãd`da„Z`däddde„Zadådhdi„Zbdædkdl„Zcdçdodp„Zddèdsdt„Zedédzd{„Zfedêd�d‚„ƒZgedëd„d‚„ƒZgdìd‡d‚„Zgdíd‰dŠ„Zheid‹ƒZjdeJdŒ< dîdŽd�„Zkdîd�d‘„Zldïd”d•„Zmdðd—d˜„Zndñdšd›„Zodòd�dž„ZpejZdód¡d¢„ƒZqdôd¤d¥„Zrdõdöd¦d§„Zsd÷dªd«„Zt	#dødùd¯d°„Zudúdûd³d´„Zvdüdµd¶„Zwdýd¸d¹„Zxdº yd»¡Zzezd¼ Z{ezd½ Z|dþd¿dÀ„Z}dÿdÂdÃ„Z~�d dÅdÆ„Z�ddÈdÉ„Z€�ddÍdÎ„Z��ddÏdÐ„Z‚�ddÓdÔ„ZƒdS (  z”
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
é    )ÚannotationsN)ÚOrderedDict)Ú	GeneratorÚIterable)ÚTYPE_CHECKINGÚAnyÚFinalÚTypeVarÚcastÚoverload)Úmake_headersÚ	parse_urlé   )Úcerts©Ú__version__)Ú_HEADER_VALIDATORS_BYTEÚ_HEADER_VALIDATORS_STRÚHEADER_VALIDATORSÚto_native_string)ÚSupportsItems)ÚMappingÚbytesÚ
getproxiesÚgetproxies_environmentÚinteger_typesÚis_urllib3_1Úproxy_bypassÚproxy_bypass_environmentÚquoteÚstrÚunquoteÚurlparseÚ
urlunparse)Úparse_http_list©Úcookiejar_from_dict)ÚFileModeWarningÚInvalidHeaderÚ
InvalidURLÚUnrewindableBodyError)ÚCaseInsensitiveDict)Ú	CookieJar)ÚBufferedWriter)Ú_types)ÚPreparedRequestÚRequestÚResponse)z.netrcÚ_netrcr   ÚNETRC_FILESr    ÚDEFAULT_CA_BUNDLE_PATHéP   i»  )ÚhttpÚhttpsÚDEFAULT_PORTSÚ_KTÚ_VTz, z,\s*T)Úaccept_encodingzaccept-encodingÚDEFAULT_ACCEPT_ENCODINGÚwin32ÚhostÚ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 SettingsZProxyEnableZProxyOverrideú;z<local>Ú.Tz\.Ú*z.*ú?)ÚwinregÚImportErrorÚOpenKeyÚHKEY_CURRENT_USERÚintÚQueryValueExÚOSErrorÚ
ValueErrorÚsplitÚfilterÚreplaceÚreÚmatchÚI)r>   rE   ZinternetSettingsZproxyEnableZproxyOverrideÚtest© rT   úa/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/requests/utils.pyÚproxy_bypass_registryc   s<   ÿþÿ

ÿrV   c                 C  s   t ƒ rt| ƒS t| ƒS )zšReturn True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        )r   r   rV   )r>   rT   rT   rU   r   ‰   s   r   Údú6_t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]úIterable[tuple[Any, Any]]c                 C  s   t | tƒr	|  ¡ S | S )z/Returns an internal sequence dictionary update.)Ú
isinstanceÚ_SupportsItemsÚitems)rW   rT   rT   rU   Údict_to_sequence•   s   
r]   Úor   rI   c              	   C  s8  d }d}t st| tƒr|  d¡} t| dƒrt| ƒ}n2t| dƒr#| j}n)t| dƒrLz|  ¡ }W n tjt	fy:   Y nw t
 |¡j}d| jvrLt dt¡ t| dƒr�z|  ¡ }W n tyf   |d urd|}Y n)w t| d	ƒr�|d u r�z|  dd
¡ |  ¡ }|  |p€d¡ W n tyŽ   d}Y nw |d u r•d}td|| ƒS )Nr   úutf-8Ú__len__ÚlenÚfilenoÚba%  Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.ÚtellÚseeké   )r   rZ   r    ÚencodeÚhasattrra   rb   ÚioÚUnsupportedOperationÚAttributeErrorÚosÚfstatÚst_sizeÚmodeÚwarningsÚwarnr'   rd   rK   re   Úmax)r^   Ztotal_lengthZcurrent_positionrb   rT   rT   rU   Ú	super_len    sN   




ü
÷
€úÿrs   FÚurlú
_t.UriTypeÚraise_errorsútuple[str, str] | Nonec              	   C  s8  t | tƒr
|  d¡} tj d¡}|dur|f}ndd„ tD ƒ}zpddlm}m} d}|D ]}tj	 
|¡}tj	 |¡r>|} nq,|du rFW dS t| ƒ}	|	j}
|
du rTW dS z+||ƒ |
¡}|rxt|ƒr||d rhdnd}|| pod	|d
 ptd	fW W S W W dS W W dS  |tfy�   |r‹‚ Y W dS w  ttfy›   Y dS w )z;Returns the Requests tuple auth for a given url from netrc.r_   ZNETRCNc                 s  s   � | ]}d |› �V  qdS )z~/NrT   )Ú.0ÚfrT   rT   rU   Ú	<genexpr>ó   s   € z!get_netrc_auth.<locals>.<genexpr>r   )ÚNetrcParseErrorÚnetrcr   Ú rf   )rZ   r   Údecoderl   ÚenvironÚgetr3   r|   r{   ÚpathÚ
expanduserÚexistsr"   ÚhostnameZauthenticatorsÚanyrK   rF   rk   )rt   rv   Z
netrc_fileZnetrc_locationsr{   r|   Z
netrc_pathry   ZlocZrir>   r2   Zlogin_irT   rT   rU   Úget_netrc_authç   sF   

þýÿýÿr†   Úobjú
str | Nonec                 C  sR   t | ddƒ}|r!t|ttfƒr#|d dkr%|d dkr'tj |¡S dS dS dS dS )z0Tries to guess the filename of the given object.ÚnameNr   ú<éÿÿÿÿú>)ÚgetattrrZ   r    r   rl   r�   Úbasename)r‡   r‰   rT   rT   rU   Úguess_filename  s   *ÿr�   r�   c              	   C  sæ   t j | ¡r| S t j | ¡\}}|r2t j |¡s2t j |¡\}}|s#nd ||g¡}|r2t j |¡rt |¡s9| S t |¡}|| ¡ vrF| S t j 	| d¡d ¡d }t
j|d�\}}zt  || |¡¡ W t  |¡ |S t  |¡ w )zÄReplace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
    ú/r‹   )Úsuffix)rl   r�   rƒ   rM   ÚjoinÚzipfileÚ
is_zipfileÚZipFileÚnamelistÚsplitextÚtempfileÚmkstempÚwriteÚreadÚclose)r�   ÚarchiveÚmemberÚprefixZzip_filer‘   ÚfdZextracted_pathrT   rT   rU   Úextract_zipped_paths"  s*   ú


þr¡   Úfilenameú%Generator[BufferedWriter, 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)	r˜   r™   rl   r�   ÚdirnameÚfdopenrO   ÚBaseExceptionÚremove)r¢   Ztmp_descriptorZtmp_nameZtmp_handlerrT   rT   rU   Úatomic_openH  s   €ÿ
þrª   Úvalueú4Mapping[Any, Any] | Iterable[tuple[Any, Any]] | Noneúdict[Any, Any] | Nonec                 C  s.   | du rdS t | ttttfƒr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')])

    :rtype: OrderedDict
    Nú+cannot encode objects that are not 2-tuples)rZ   r    r   r@   rI   rL   r   ©r«   rT   rT   rU   Úfrom_key_val_listU  s
   r°   ÚNonec                 C  ó   d S ©NrT   r¯   rT   rT   rU   Úto_key_val_listr  s   r´   ú6_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]]úlist[tuple[_KT, _VT]]c                 C  r²   r³   rT   r¯   rT   rT   rU   r´   t  ó   ú=_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | Noneúlist[tuple[_KT, _VT]] | Nonec                 C  sD   | du rdS t | ttttfƒrtdƒ‚t | tƒrt|  ¡ ƒS 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

    :rtype: list
    Nr®   )	rZ   r    r   r@   rI   rL   r[   Úlistr\   r¯   rT   rT   rU   r´   x  s   
ú	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`
    :rtype: list
    Nr   r‹   ú")Ú_parse_list_headerÚunquote_header_valueÚappend)r«   ÚresultÚitemrT   rT   rU   Úparse_list_header˜  s   (rÂ   údict[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 )a^  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`
    :rtype: dict
    ú=Nr   r‹   r¼   )r½   rM   r¾   )r«   rÀ   rÁ   r‰   rT   rT   rU   Ú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 )
zçUnquotes 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.
    :rtype: str
    r   r‹   r¼   r   Nrf   z\\ú\z\")rO   )r«   rÆ   rT   rT   rU   r¾   Û  s   "÷r¾   Úcjr,   c                 C  s   dd„ | D ƒ}|S )z€Returns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    c                 S  s   i | ]}|j |j“qS rT   )r‰   r«   )rx   ÚcookierT   rT   rU   Ú
<dictcomp>û  s    z'dict_from_cookiejar.<locals>.<dictcomp>rT   ©rÈ   Úcookie_dictrT   rT   rU   Údict_from_cookiejarô  s   rÍ   rÌ   údict[str, str]c                 C  s
   t || ƒS )zÂReturns 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.
    :rtype: CookieJar
    r%   rË   rT   rT   rU   Úadd_dict_to_cookiejarÿ  s   
rÏ   Úcontentc                 C  sT   t  dt¡ tjdtjd�}tjdtjd�}t d¡}| | ¡| | ¡ | | ¡ S )zlReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    z¤In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)z!<meta.*?charset=["\']*(.+?)["\'>])Úflagsz+<meta.*?content=["\']*;?charset=(.+?)["\'>]z$^<\?xml.*?encoding=["\']*(.+?)["\'>])rp   rq   ÚDeprecationWarningrP   ÚcompilerR   Úfindall)rÐ   Z
charset_reZ	pragma_reZxml_rerT   rT   rU   Úget_encodings_from_content
  s   ú	
ÿþÿrÕ   Úheaderútuple[str, dict[str, Any]]c           
      C  s�   |   d¡}|d  ¡ |dd… }}i }d}|D ]+}| ¡ }|rC| d¡ }dkrC|d|…  |¡}||d d…  |¡}	|	|| ¡ < q||fS )z¨Returns content type and parameters from given header.

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters.
    rA   r   r   Nz"' rÄ   r‹   )rM   ÚstripÚfindÚlower)
rÖ   ÚtokensÚcontent_typeÚparamsZparams_dictZstrip_charsÚparamÚidxÚkeyr«   rT   rT   rU   Ú_parse_content_type_header#  s   
€rá   ÚheadersúCaseInsensitiveDict[str]c                 C  sP   |   d¡}|s	dS t|ƒ\}}d|v r|d  d¡S d|v r dS d|v r&dS dS )	z}Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    zcontent-typeNÚcharsetz'"Útextz
ISO-8859-1zapplication/jsonr_   )r€   rá   rØ   )râ   rÜ   rÝ   rT   rT   rU   Úget_encoding_from_headers9  s   
þræ   ÚiteratorúIterable[bytes]Úrr1   ú"Generator[str | bytes, 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.NrO   ©Úerrorsó    T)Úfinal)ÚencodingÚcodecsÚgetincrementaldecoderr~   )rç   ré   ÚdecoderÚchunkÚrvrT   rT   rU   Ústream_decode_response_unicodeR  s   €


€
ÿrõ   Ústringr   Úslice_lengthú
int | NoneúGenerator[bytes, None, None]c                 C  r²   r³   rT   ©rö   r÷   rT   rT   rU   Úiter_slicese  r·   rû   úGenerator[str, None, None]c                 C  r²   r³   rT   rú   rT   rT   rU   rû   i  r·   úbytes | strú"Generator[bytes | str, 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)ra   )rö   r÷   ÚposrT   rT   rU   rû   m  s   €þústr | bytes | Nonec                 C  sˆ   t  dt¡ | jdu rdS g }t| jƒ}|r,zt| j|ƒW S  ty+   | |¡ Y nw zt| j|p3ddd�W S  t	yC   | j Y S w )zâReturns the requested content back in unicode.

    :param r: Response object to get unicode content from.

    Tried:

    1. charset from content-type
    2. fall back and replace all unicode characters

    :rtype: str
    z£In requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)Nr_   rO   rë   )
rp   rq   rÒ   rÐ   ræ   râ   r    ÚUnicodeErrorr¿   Ú	TypeError)ré   Ztried_encodingsrï   rT   rT   rU   Úget_unicode_from_responsey  s&   ú

ÿ
ÿr  zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~ÚUNRESERVED_SETÚ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 )
z¨Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

    :rtype: str
    ú%r   r   rf   é   z"Invalid percent-escape sequence: 'ú'Nr}   )
rM   Úrangera   ÚisalnumÚchrrI   rL   r)   r  r’   )r  ÚpartsÚiÚhÚcrT   rT   rU   Úunquote_unreserved¨  s   
ÿ
r  c                 C  s:   d}d}z	t t| ƒ|d�W S  ty   t | |d� Y S w )z¬Re-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.

    :rtype: str
    z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~)Úsafe)r   r  r)   )r  Zsafe_with_percentZsafe_without_percentrT   rT   rU   Úrequote_uriÀ  s   ür  ÚipÚnetc                 C  sl   t  dt | ¡¡d }| d¡\}}t  dt tt|ƒƒ¡¡d }t  dt |¡¡d |@ }||@ ||@ kS )zï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

    :rtype: bool
    z=Lr   r�   )ÚstructÚunpackÚsocketÚ	inet_atonrM   Údotted_netmaskrI   )r  r  ZipaddrZnetaddrÚbitsÚnetmaskÚnetworkrT   rT   rU   Úaddress_in_networkÖ  s
   r  Úmaskc                 C  s&   ddd|  > d A }t  t d|¡¡S )z�Converts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0

    :rtype: str
    l   ÿÿ r   é    z>I)r  Ú	inet_ntoar  Úpack)r  r  rT   rT   rU   r  å  s   r  Ú	string_ipc                 C  s&   zt  | ¡ W dS  ty   Y dS w )z
    :rtype: bool
    FT)r  r  rK   )r"  rT   rT   rU   Úis_ipv4_addressð  s   þÿr#  Ústring_networkc                 C  s‚   |   d¡dkr?zt|  d¡d ƒ}W n
 ty   Y dS w |dk s%|dkr'dS zt |  d¡d ¡ W dS  ty>   Y dS w dS )zV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    r�   r   Fr  r   T)ÚcountrI   rM   rL   r  r  rK   )r$  r  rT   rT   rU   Úis_valid_cidrû  s   ÿüÿr&  Úenv_nameúGenerator[None, None, None]c              	   c  s~   � |du}d}|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 r9t j| = w |t j| < w )zÎSet 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)rl   r   r€   )r'  r«   Zvalue_changedÚ	old_valuerT   rT   rU   Úset_environ  s    €
ür*  Úno_proxyc              
   C  sZ  ddd„}|}|du r|dƒ}t | ƒ}|j}|du rd	S |r}d
d„ | dd¡ d¡D ƒ}t|ƒrJ|D ]}t|ƒrAt||ƒr@ d	S q2||krH d	S q2n3|}|jrW|d|j› �7 }|D ]#}	|	 d¡}	||	ksh||	krk d	S d|	 }	| 	|	¡sy| 	|	¡r| d	S qYt
d|ƒ� zt|ƒ}
W n ttjfy—   d}
Y nw W d  ƒ n1 s¢w   Y  |
r«d	S dS )zL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    rà   r    r?   rˆ   c                 S  s   t j | ¡pt j |  ¡ ¡S r³   )rl   r   r€   Úupper)rà   rT   rT   rU   Ú	get_proxy3  s   z(should_bypass_proxies.<locals>.get_proxyNr+  Tc                 s  s   � | ]}|r|V  qd S r³   rT   )rx   r>   rT   rT   rU   rz   E  s   € z(should_bypass_proxies.<locals>.<genexpr>ú r}   ú,ú:rB   F)rà   r    r?   rˆ   )r"   r„   rO   rM   r#  r&  r  ÚportÚlstripÚendswithr*  r   r  r  Úgaierror)rt   r+  r-  Zno_proxy_argÚparsedr„   Zno_proxy_hostsZproxy_ipZhost_with_portr>   ZbypassrT   rT   rU   Úshould_bypass_proxies*  sT   
	
ÿýü	
ÿÿ€ýr6  c                 C  s   t | |d�ri S tƒ S )zA
    Return a dict of environment proxies.

    :rtype: dict
    ©r+  )r6  r   )rt   r+  rT   rT   rU   Úget_environ_proxiesi  s   r8  Úproxiesúdict[str, str] | Nonec                 C  sv   |pi }t | ƒ}|jdu r| |j| d¡¡S |jd |j |jd|j dg}d}|D ]}||v r8|| } |S q+|S )z­Select 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Úallz://zall://)r"   r„   r€   Úscheme)rt   r9  ÚurlpartsZ
proxy_keysÚproxyZ	proxy_keyrT   rT   rU   Úselect_proxyu  s"   
üür?  ÚrequestúRequest | PreparedRequestÚ	trust_envc           	      C  sz   |dur|ni }t t| jƒ}t|ƒj}| 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 as 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

    :rtype: dict
    Nr+  r7  r;  )
r
   r    rt   r"   r<  r€   Úcopyr6  r8  Ú
setdefault)	r@  r9  rB  rt   r<  r+  Znew_proxiesZenviron_proxiesr>  rT   rT   rU   Úresolve_proxies�  s   

rE  úpython-requestsr‰   c                 C  s   | › dt › �S )zO
    Return a string representing the default user agent.

    :rtype: str
    r�   r   )r‰   rT   rT   rU   Údefault_user_agent®  s   rG  c                   C  s   t tƒ tdddœƒS )z9
    :rtype: requests.structures.CaseInsensitiveDict
    z*/*z
keep-alive)z
User-AgentzAccept-EncodingÚAcceptÚ
Connection)r+   rG  r<   rT   rT   rT   rU   Údefault_headers·  s   üÿrJ  ú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 )	z¼Return 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"

    :rtype: list
    z '"z, *<rA   r   r}   rt   z<> '"rÄ   )rØ   rP   rM   rL   r¿   )	r«   ZlinksZreplace_charsÚvalrt   rÝ   ÚlinkrÞ   rà   rT   rT   rU   Úparse_header_linksÅ  s*   
ÿÿrN  ú Úasciirf   é   Údatac                 C  sÐ   | dd… }|t jt jfv rdS |dd… t jkrdS |dd… t jt jfv r)dS | t¡}|dkr4d	S |dkrN|ddd… tkrCd
S |ddd… tkrNdS |dkrf|dd… t	kr\dS |dd… t	krfdS dS )z
    :rtype: str
    Né   zutf-32rQ  z	utf-8-sigrf   zutf-16r   r_   z	utf-16-ber   z	utf-16-lez	utf-32-bez	utf-32-le)
rð   ÚBOM_UTF32_LEÚBOM_UTF32_BEÚBOM_UTF8ÚBOM_UTF16_LEÚBOM_UTF16_BEr%  Ú_nullÚ_null2Ú_null3)rR  ÚsampleZ	nullcountrT   rT   rU   Úguess_json_utfð  s*   
r]  Ú
new_schemec                 C  sv   t | ƒ}|\}}}}}}}	|j}
|
s||
}
}|r%tt|
ƒ}
d ||
g¡}
|du r+|}|du r1d}t||
|d||	fƒS )zªGiven 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.

    :rtype: str
    ú@Nr}   )r   Únetlocr
   r    r’   r#   )rt   r^  r5  r<  ÚauthÚ_hostZ_portr�   ÚqueryÚfragmentr`  rT   rT   rU   Úprepend_scheme_if_needed  s   

re  útuple[str, str]c              	   C  s@   t | ƒ}zt|jƒt|jƒf}W |S  ttfy   d}Y |S w )z{Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    )r}   r}   )r"   r!   ÚusernameÚpasswordrk   r  )rt   r5  ra  rT   rT   rU   Úget_auth_from_url.  s   ýýri  útuple[str | bytes, str | bytes]c                 C  s$   | \}}t | |dƒ t | |dƒ dS )z§Verifies that header parts don't contain leading whitespace
    reserved characters, or return characters.

    :param header: tuple, in the format (name, value).
    r   r   N)Ú_validate_header_part)rÖ   r‰   r«   rT   rT   rU   Úcheck_header_validity?  s   rl  Úheader_partústr | bytesÚheader_validator_indexc                 C  sx   t |tƒr
t| }nt |tƒrt| }ntd|›d| › dt|ƒ› �ƒ‚| |¡s:|dkr.dnd}td|› d|›�ƒ‚d S )	NzHeader part (z) from z# must be of type str or bytes, not r   r‰   r«   zTInvalid leading whitespace, reserved character(s), or return character(s) in header z: )rZ   r    r   r   r   r(   ÚtyperQ   )rÖ   rm  ro  Z	validatorZheader_kindrT   rT   rU   rk  J  s&   



ÿÿ
ÿÿÿþrk  c                 C  sF   t | ƒ\}}}}}}|s||}}| dd¡d }t|||||dfƒS )zW
    Given a url remove the fragment and the authentication part.

    :rtype: str
    r_  r   r‹   r}   )r"   Úrsplitr#   )rt   r<  r`  r�   rÝ   rc  Z	_fragmentrT   rT   rU   Úurldefragauthb  s
   
rr  Úprepared_requestr/   c                 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.
    re   Nz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)r�   ÚbodyrZ   Z_body_positionr   rK   r*   )rs  Ú	body_seekrT   rT   rU   Úrewind_bodys  s   
þÿÿrv  )r>   r    r?   r@   )rW   rX   r?   rY   )r^   r   r?   rI   )F)rt   ru   rv   r@   r?   rw   )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?   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é   r1   r?   rê   )rö   r   r÷   rø   r?   rù   )rö   r    r÷   rø   r?   rü   )rö   rý   r÷   rø   r?   rþ   )ré   r1   r?   r   )r  r    r?   r    )r  r    r  r    r?   r@   )r  rI   r?   r    )r"  r    r?   r@   )r$  r    r?   r@   )r'  r    r«   rˆ   r?   r(  )rt   r    r+  rˆ   r?   r@   r³   )rt   r    r+  rˆ   r?   rÎ   )rt   r    r9  r:  r?   rˆ   )T)r@  rA  r9  r:  rB  r@   r?   rÎ   )rF  )r‰   r    r?   r    )r?   rã   )r«   r    r?   rK  )rR  r   r?   rˆ   )rt   r    r^  r    r?   r    )rt   r    r?   rf  )rÖ   rj  r?   r±   )rÖ   rj  rm  rn  ro  rI   r?   r±   )rt   r    r?   r    )rs  r/   r?   r±   )„Ú__doc__Ú
__future__r   rð   Ú
contextlibri   rl   rP   r  r  Úsysr˜   rp   r“   Úcollectionsr   Úcollections.abcr   r   Útypingr   r   r   r	   r
   r   Zurllib3.utilr   r   r}   r   r   Z_internal_utilsr   r   r   r   r.   r   r[   Úcompatr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r½   Úcookiesr&   Ú
exceptionsr'   r(   r)   r*   Z
structuresr+   Úhttp.cookiejarr,   r-   Z_tÚmodelsr/   r0   r1   r3   Ú__annotations__Úwherer4   r8   r9   r:   r’   rM   r<   ÚplatformrV   r]   rs   r†   r�   r¡   Úcontextmanagerrª   r°   r´   rÂ   rÅ   r¾   rÍ   rÏ   rÕ   rá   ræ   rõ   rû   r  Ú	frozensetr  r  r  r  r  r#  r&  r*  r6  r8  r?  rE  rG  rJ  rN  rg   rY  rZ  r[  r]  re  ri  rl  rk  rr  rv  rT   rT   rT   rU   Ú<module>   sÈ     	<ÿ

&

Hÿ
4
&


 
 #







*ÿ






?
ý
	

&

 