o
    vô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   ú_/var/www/html/academy/tools/voices/clone/sv-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^   Útotal_lengthZcurrent_positionrb   rT   rT   rU   Ú	super_len    sN   




ü
÷
€úÿrt   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   )ru   rw   Z
netrc_fileZnetrc_locationsr|   r}   Z
netrc_pathrz   Ú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ÚprefixÚ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®   )ry   Ú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   )ry   r>   rT   rT   rU   r{   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)ru   r.  r0  Zno_proxy_argÚparsedr…   Zno_proxy_hostsZproxy_ipZhost_with_portr>   ZbypassrT   rT   rU   Úshould_bypass_proxies*  sT   
	
ÿýü	
ÿÿ€ýr9  c                 C  s   t | |d�ri S tƒ S )zA
    Return a dict of environment proxies.

    :rtype: dict
    ©r.  )r9  r   )ru   r.  rT   rT   rU   Úget_environ_proxiesi  s   r;  Ú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)ru   r<  ÚurlpartsZ
proxy_keysÚproxyZ	proxy_keyrT   rT   rU   Úselect_proxyu  s"   
üürB  Ú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.  r:  r>  )
r
   r    ru   r"   r?  r�   Úcopyr9  r;  Ú
setdefault)	rC  r<  rE  ru   r?  r.  Znew_proxiesZenviron_proxiesrA  rT   rT   rU   Úresolve_proxies�  s   

rH  ú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   rJ  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+   rJ  r<   rT   rT   rT   rU   Údefault_headers·  s   üÿrM  ú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~   ru   z<> '"rÇ   )rÛ   rP   rM   rL   rÂ   )	r®   ZlinksZreplace_charsÚvalru   rà   Úlinkrá   rã   rT   rT   rU   Úparse_header_linksÅ  s*   
ÿÿrQ  ú Ú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-32rT  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)rU  Ú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#   )ru   ra  r8  r?  ÚauthÚ_hostZ_portr‚   ÚqueryÚfragmentrc  rT   rT   rU   Úprepend_scheme_if_needed  s   

rh  ú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  )ru   r8  rd  rT   rT   rU   Úget_auth_from_url.  s   ýýrl  ú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   ro  Ú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Ù   rp  rr  Z	validatorZheader_kindrT   rT   rU   rn  J  s&   



ÿÿ
ÿÿÿþrn  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
    rb  r   r�   r~   )r"   Úrsplitr#   )ru   r?  rc  r‚   rà   rf  Z	_fragmentrT   rT   rU   Úurldefragauthb  s
   
ru  Ú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*   )rv  Ú	body_seekrT   rT   rU   Úrewind_bodys  s   
þÿÿry  )r>   r    r?   r@   )rW   rX   r?   rY   )r^   r   r?   rI   )F)ru   rv   rw   r@   r?   rx   )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+  )ru   r    r.  rŠ   r?   r@   r¶   )ru   r    r.  rŠ   r?   rÑ   )ru   r    r<  r=  r?   rŠ   )T)rC  rD  r<  r=  rE  r@   r?   rÑ   )rI  )r‹   r    r?   r    )r?   ræ   )r®   r    r?   rN  )rU  r   r?   rŠ   )ru   r    ra  r    r?   r    )ru   r    r?   ri  )rÙ   rm  r?   r´   )rÙ   rm  rp  rq  rr  rI   r?   r´   )ru   r    r?   r    )rv  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*   Ú
structuresr+   Úhttp.cookiejarr,   r-   Ú_tÚmodelsr/   r0   r1   r3   Ú__annotations__Úwherer4   r8   r9   r:   r”   rM   r<   ÚplatformrV   r]   rt   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-  r9  r;  rB  rH  rJ  rM  rQ  rg   r\  r]  r^  r`  rh  rl  ro  rn  ru  ry  rT   rT   rT   rU   Ú<module>   sÈ     	<ÿ

&

Hÿ
4
&


 
 #







*ÿ






?
ý
	

&

 