
    -j                       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jK                    ZLdeJd<   dddZMdeJd<    ed          ZN ed           ZOd!P                     ejQ        d" ed#$          d%                             ZRdeJd&<   e
jS        d'k    rdd+ZTdd,Z/dd0ZUdd4ZV	 ddd:ZWdd=ZXdd?ZYejZ        ddB            Z[ddFZ\eddH            Z]eddK            Z]ddNZ]ddPZ^ddRZ_dddTZ`ddWZaddZZbdd\Zcdd_ZdddbZeddhZfeddn            Zgeddp            ZgddsZgdduZh eidv          ZjdeJdw<   ddyZkddzZldd}ZmddZnddZoddZpejZ        dd            ZqddZrdddZsddZt	 dddZudddZvddZwddZxdy                    d          Zzezdz  Z{ezdz  Z|ddZ}ddZ~ddZddZddZddZddZd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_PATHP   i  )httphttpsDEFAULT_PORTS_KT_VTz, z,\s*T)accept_encodingzaccept-encodingDEFAULT_ACCEPT_ENCODINGwin32hostreturnboolc                l   	 dd l }n# t          $ r Y dS w xY w	 |                    |j        d          }t	          |                    |d          d                   }|                    |d          d         }n# t          t          f$ r Y dS w xY w|r|sdS |                    d          }t          d |          }|D ]t}|dk    rd| vr d	S |
                    dd
          }|
                    dd          }|
                    dd          }t          j        || t          j                  r d	S ud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)r?   rI   internetSettingsproxyEnableproxyOverridetests         b/lsinfo/ai/hellotax_ai/training_center/backend/venv/lib/python3.11/site-packages/requests/utils.pyproxy_bypass_registryr\   c   s   	MMMM 	 	 	55	
	%~~(N   
 f112BMRRSTUVVK"//0@/RRSTUMM$ 	 	 	55	 	- 	5
 &++C00t]33! 	 	Dy  d??44<<U++D<<U++D<<T**DxdBD)) ttus    
A A: :BBc                Z    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\   )r?   s    r[   r   r      s.     "## 	/+D111(...    d6_t.SupportsItems[Any, Any] | Iterable[tuple[Any, Any]]Iterable[tuple[Any, Any]]c                X    t          | t                    r|                                 S | S )z/Returns an internal sequence dictionary update.)
isinstance_SupportsItemsitems)r_   s    r[   dict_to_sequencerf      s)    
 !^$$ wwyyHr^   or   rM   c                H   d }d}t           s*t          | t                    r|                     d          } t	          | d          rt          |           }nt	          | d          r| j        }n~t	          | d          rn	 |                                 }t          j        |          j	        }d| j
        vrt          j        dt                     n# t          j        t           f$ r Y nw xY wt	          | d          r	 |                                 }t	          | d	          rW|U	 |                     dd
           |                                 }|                     |pd           n'# t&          $ r d}Y nw xY wn# t&          $ r ||}Y nw xY w|d}t)          d||z
            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   rc   r!   encodehasattrrk   rl   osfstatst_sizemodewarningswarnr(   ioUnsupportedOperationAttributeErrorrn   ro   rO   max)rg   total_lengthcurrent_positionrl   s       r[   	super_lenr      s   L Jq#..  HHWq) 1vv	E		 u	H		 	XXZZF 8F++3L !&  2 $
 
 
 '8 	 	 	 D		. q& %	% vvxx q&!! %l&:	%FF1aLLL#$6688L FF+0q1111 % % %#$LLL%%  	0 	0 	0
 '#/ 	0* q,!11222s7   ?C C)(C)=E9 $AE& &E54E59F
	F
Furl
_t.UriTyperaise_errorstuple[str, str] | Nonec                   t          | t                    r|                     d          } t          j                            d          }||f}nd t          D             }	 ddlm}m} d}|D ]D}t          j	        
                    |          }t          j	                            |          r|} nE|dS t          |           }	|	j        }
|
dS 	  ||                              |
          }|r/t          |          r"|d         rdnd}||         pd|d	         pdfS dS dS # |t           f$ r |r Y dS w xY w# t"          t$          f$ r Y dS w xY w)
z;Returns the Requests tuple auth for a given url from netrc.ri   NETRCNc              3      K   | ]	}d | V  
dS )z~/N ).0fs     r[   	<genexpr>z!get_netrc_auth.<locals>.<genexpr>   s(      99888999999r^   r   )NetrcParseErrornetrcr    rp   )rc   r   decoders   environgetr4   r   r   path
expanduserexistsr#   hostnameauthenticatorsanyrO   rJ   r{   )r   r   
netrc_filenetrc_locationsr   r   
netrc_pathr   locrir?   r3   login_is                r[   get_netrc_authr      s   
 #u "jj!!((J%-99[999#00000000
  	 	A'$$Q''Cw~~c""  

 Fc]]{<F
	U:&&55d;;F @#f++ @%ay/!!aw-2vayB??@ @ @ @  ) 	 	 	    	 (   s8   "AD; 7D; AD% %D84D; 7D88D; ;EEobj
str | Nonec                    t          | dd          }|rSt          |t          t          f          r9|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   <>)getattrrc   r!   r   rs   r   basename)r   r   s     r[   guess_filenamer     s{    3%%D &
4#u.. &47c>>d2hRUoow%%%& & & &>>oor^   r   c                f   t           j                            |           r| S t           j                            |           \  }}|r|t           j                            |          s]t           j                            |          \  }}|sn8d                    ||g          }|rt           j                            |          ]t          j        |          s| S t          j        |          }||                                vr| S t           j        	                    |                    d          d                   d         }t          j        |          \  }}	 t          j        ||                    |                     t          j        |           n# t          j        |           w xY w|S )zReplace 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)rs   r   r   rQ   joinzipfile
is_zipfileZipFilenamelistsplitexttempfilemkstempwritereadclose)r   archivememberprefixzip_filer   fdextracted_paths           r[   extract_zipped_pathsr   "  s   
 
w~~d  gmmD))OGV
 ,"'..11 ,'--00 	 66*++  ,"'..11 , g&& w''HX&&(((( Wfll3//344R8F!)888B
X]]6**+++
s   (F F.filename%Generator[BufferedWriter, None, None]c              #  H  K   t          j        t          j                            |                     \  }}	 t          j        |d          5 }|V  ddd           n# 1 swxY w Y   t          j        ||            dS # t          $ r t          j        |            w xY w)z-Write a file to the disk in an atomic fashion)dirwbN)	r   r   rs   r   dirnamefdopenrS   BaseExceptionremove)r   tmp_descriptortmp_nametmp_handlers       r[   atomic_openr   H  s        (/BGOOH4M4MNNNNHY~t,, 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	

8X&&&&&   
	(s/   B AB A##B &A#'B  B!value4Mapping[Any, Any] | Iterable[tuple[Any, Any]] | Nonedict[Any, Any] | Nonec                    | 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)rc   r!   r   rA   rM   rP   r   r   s    r[   from_key_val_listr   U  sG    ( }t%#udC011 HFGGGur^   Nonec                    d S Nr   r   s    r[   to_key_val_listr   r  s    *-#r^   6_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]]list[tuple[_KT, _VT]]c                    d S r   r   r   s    r[   r   r   t  s	      Cr^   =_t.SupportsItems[_KT, _VT] | Iterable[tuple[_KT, _VT]] | Nonelist[tuple[_KT, _VT]] | Nonec                   | 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   )	rc   r!   r   rA   rM   rP   rd   listre   r   s    r[   r   r   x  sm    & }t%#udC011 HFGGG%(( #EKKMM""";;r^   	list[str]c                    g }t          |           D ]N}|dd         |dd         cxk    rdk    rn nt          |dd                   }|                    |           O|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items      r[   parse_list_headerr     s    . F"5))  8tBCCy''''C''''''QrT
33DdMr^   dict[str, str | None]c                    i }t          |           D ]a}d|vrd||<   |                    dd          \  }} | dd         | dd         cxk    rdk    rn nt          | dd                   } | ||<   b|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   rQ   r   )r   r   r   r   s       r[   parse_dict_headerr     s    , %'F"5))  d??F4Ljja((e!9bcc
))))c)))))(qt55EtMr^   is_filenamec                    | r`| d         | d         cxk    rdk    rGn nD| 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.
    :rtype: str
    r   r   r   r   Nrp   z\\\z\")rS   )r   r   s     r[   r   r     s      CqU2Y----#-----
 ad  	CeBQBi611==..66ucBBBLr^   cjr-   c                    d | D             }|S )zReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    c                (    i | ]}|j         |j        S r   )r   r   )r   cookies     r[   
<dictcomp>z'dict_from_cookiejar.<locals>.<dictcomp>  s    >>>6;>>>r^   r   r   cookie_dicts     r[   dict_from_cookiejarr     s     ?>2>>>Kr^   r   dict[str, str]c                "    t          ||           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.
    :rtype: CookieJar
    r&   r   s     r[   add_dict_to_cookiejarr     s     {B///r^   contentc                `   t          j        dt                     t          j        dt          j                  }t          j        dt          j                  }t          j        d          }|                    |           |                    |           z   |                    |           z   S )zlReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    zIn 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=["\']*(.+?)["\'>])rw   rx   DeprecationWarningrT   compilerV   findall)r   
charset_re	pragma_rexml_res       r[   get_encodings_from_contentr   
  s    
 M1 	   @MMMJ
IQSQUVVVIZ?@@F 	7##


G
$
$	%
..
!
!	"r^   headertuple[str, dict[str, Any]]c                   |                      d          }|d                                         |dd         }}i }d}|D ]}|                                }|ro|                    d          x}dk    rT|d|                             |          }||dz   d                             |          }	|	||                                <   ||fS )zReturns content type and parameters from given header.

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters.
    rE   r   r   Nz"' r   r   )rQ   stripfindlower)
r  tokenscontent_typeparamsparams_dictstrip_charsparamidxkeyr   s
             r[   _parse_content_type_headerr  #  s     \\#F!!9??,,fQRRj&L)+KK - - 	-UZZ__,c33+##K00C#'))$**;77E',K		$$$r^   headersCaseInsensitiveDict[str]c                    |                      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/jsonri   )r   r  r  )r  r  r	  s      r[   get_encoding_from_headersr  9  s     ;;~..L t5lCCL&Fi &&u---|\))w *)r^   iteratorIterable[bytes]rr2   "Generator[str | bytes, None, None]c              #     K   |j         
| E d{V  dS  t          j        |j                   d          }| D ]}|                    |          }|r|V  |                    dd          }|r|V  dS dS )zStream decodes an iterator.NrS   errorsr^   T)final)encodingcodecsgetincrementaldecoderr   )r  r  decoderchunkrvs        r[   stream_decode_response_unicoder$  R  s      
 	z6f*1:66iHHHG  ^^E"" 	HHH	4	(	(B	  r^   stringr   slice_length
int | NoneGenerator[bytes, None, None]c                    d S r   r   r%  r&  s     r[   iter_slicesr+  e  s	     $'3r^   Generator[str, None, None]c                    d S r   r   r*  s     r[   r+  r+  i  s	     "%r^   bytes | str"Generator[bytes | str, None, None]c              #     K   d}||dk    rt          |           }|t          |           k     r)| |||z            V  ||z  }|t          |           k     'dS dS )z Iterate over slices of a string.r   N)rk   )r%  r&  poss      r[   r+  r+  m  s}       C|q006{{
F

S3--....| F





r^   str | bytes | Nonec                P   t          j        dt                     | j        dS g }t	          | j                  }|r;	 t          | j        |          S # t          $ r |                    |           Y nw xY w	 t          | j        |pdd          S # t          $ r
 | j        cY S w xY w)zReturns 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
    zIn 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.)Nri   rS   r  )
rw   rx   r   r   r  r  r!   UnicodeErrorr   	TypeError)r  tried_encodingsr  s      r[   get_unicode_from_responser7  y  s     M1 	   	yt!#O )33H -	-qy(+++ 	- 	- 	-""8,,,,,	-19h1')DDDD   ys#   A A43A48B B%$B%zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~UNRESERVED_SETuric                   |                      d          }t          dt          |                    D ]}||         dd         }t          |          dk    r|                                ro	 t	          t          |d                    }n!# t          $ r t          d| d          w xY w|t          v r|||         dd         z   ||<   d||          ||<   d||          ||<   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.

    :rtype: str
    %r   r   rp      z"Invalid percent-escape sequence: ''Nr   )
rQ   rangerk   isalnumchrrM   rP   r*   r8  r   )r9  partsihcs        r[   unquote_unreservedrE    s    IIcNNE1c%jj!! & &!HQqSMq66Q;;199;;;LAr

OO L L L !Ja!J!J!JKKKL N""uQx|+a)uQx>>a%58~~E!HH775>>s   -BB)c                    d}d}	 t          t          |           |          S # t          $ r t          | |          cY S w xY 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.

    :rtype: str
    z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~)safe)r    rE  r*   )r9  safe_with_percentsafe_without_percents      r[   requote_urirJ    sk     /0	5 ',,3DEEEE 5 5 5 S3444444	5s   $ AAipnetc           
        t          j        dt          j        |                     d         }|                    d          \  }}t          j        dt          j        t          t          |                                        d         }t          j        dt          j        |                    d         |z  }||z  ||z  k    S )zThis 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_atonrQ   dotted_netmaskrM   )rK  rL  ipaddrnetaddrbitsnetmasknetworks          r[   address_in_networkrX    s     ]4!1"!5!566q9FIIcNNMGTmD&"2>#d))3L3L"M"MNNqQGmD&"27";";<<Q?'IGW'G"344r^   maskc                l    ddd| z
  z  dz
  z  }t          j        t          j        d|                    S )zConverts 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)rP  	inet_ntoarN  pack)rY  rU  s     r[   rR  rR    s8     b4i1,,DFKd33444r^   	string_ipc                T    	 t          j        |            n# t          $ r Y dS w xY wdS )z
    :rtype: bool
    FT)rP  rQ  rO   )r^  s    r[   is_ipv4_addressr`    sB    ####   uu4s    
%%string_networkc                N   |                      d          dk    r	 t          |                     d          d                   }n# t          $ r Y dS w xY w|dk     s|dk    rdS 	 t	          j        |                     d          d                    n# t          $ r Y dS w xY wdS dS )zV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    r   r   Fr[  r   T)countrM   rQ   rP   rP  rQ  rO   )ra  rY  s     r[   is_valid_cidrrd    s     C  A%%	~++C00344DD 	 	 	55	 !88tbyy5	^11#66q9:::: 	 	 	55	 u4s#   (A 
AA$-B 
B B env_nameGenerator[None, None, None]c              #    K   |du}d}|r.t           j                            |           }|t           j        | <   	 dV  |r"|t           j        | = dS |t           j        | <   dS dS # |r|t           j        | = n|t           j        | <   w xY 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)rs   r   r   )re  r   value_changed	old_values       r[   set_environrj    s       %M I %JNN8,,	$
81 	1 Jx((('0
8$$$		1 	1= 	1 Jx(('0
8$0000s   A$ $#Bno_proxyc                   dd}|}| |d          }t          |           }|j        }|dS |rd	 |                    d
d                              d          D             }t	          |          r2|D ].}t          |          rt          ||          r dS %||k    r dS /nq|}|j        r|d|j         z  }|D ]X}	|	                    d          }	||	k    s||	k    r dS d|	z   }	|	                    |	          s|	                    |	          r dS Yt          d|          5  	 t          |          }
n# t          t          j        f$ r d}
Y nw xY wddd           n# 1 swxY w Y   |
rdS dS )zL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    r  r!   r@   r   c                    t           j                            |           p0t           j                            |                                           S r   )rs   r   r   upper)r  s    r[   	get_proxyz(should_bypass_proxies.<locals>.get_proxy3  s1    z~~c""AbjnnSYY[[&A&AAr^   Nrk  Tc              3     K   | ]}||V  	d S r   r   )r   r?   s     r[   r   z(should_bypass_proxies.<locals>.<genexpr>E  s(      XX4SWX$XXXXXXr^    r   ,:rF   F)r  r!   r@   r   )r#   r   rS   rQ   r`  rd  rX  portlstripendswithrj  r   r5  rP  gaierror)r   rk  ro  no_proxy_argparsedr   no_proxy_hostsproxy_iphost_with_portr?   bypasss              r[   should_bypass_proxiesr~  *  sV   B B B B
 L9Z((c]]FHt   YX8+;+;C+D+D+J+J3+O+OXXX8$$ 	 *     **  )(H== $#tt$))  44 *	  &N{ 4"3fk"3"33&    {{3''t##~'='=44Tz$$T**  n.E.Ed.K.K  44  
Z	.	.  	!(++FF6?+ 	 	 	FFF	                t5s6   %E!'D76E!7EE!EE!!E%(E%c                D    t          | |          ri S t                      S )zA
    Return a dict of environment proxies.

    :rtype: dict
    rk  )r~  r   )r   rk  s     r[   get_environ_proxiesr  i  s(     S8444 	||r^   proxiesdict[str, str] | Nonec                   |pi }t          |           }|j        .|                    |j        |                    d                    S |j        dz   |j        z   |j        d|j        z   dg}d}|D ]}||v r
||         } n|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allz://zall://)r#   r   r   scheme)r   r  urlparts
proxy_keysproxy	proxy_keys         r[   select_proxyr  u  s     mG}}H {{8?GKK,>,>??? 	%("338$$	J E  	I&EE   Lr^   requestRequest | PreparedRequest	trust_envc                   ||ni }t          t          | j                  }t          |          j        }|                    d          }|                                }|rct          ||          sRt          ||          }|                    ||                    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
    Nrk  r  r  )
r   r!   r   r#   r  r   copyr~  r  
setdefault)	r  r  r  r   r  rk  new_proxiesenviron_proxiesr  s	            r[   resolve_proxiesr    s     !,gg"G
sGK
 
 Cc]]!F{{:&&H,,..K 2.sXFFF 2-cHEEE##FO,?,?,F,FGG 	2""65111r^   python-requestsr   c                    |  dt            S )zO
    Return a string representing the default user agent.

    :rtype: str
    r   r   )r   s    r[   default_user_agentr    s     ""["""r^   c                 L    t          t                      t          ddd          S )z9
    :rtype: requests.structures.CaseInsensitiveDict
    z*/*z
keep-alive)z
User-AgentzAccept-EncodingAccept
Connection)r,   r  r=   r   r^   r[   default_headersr    s2     ,..6&		
 	
  r^   list[dict[str, str]]c                   g }d}|                      |          } | s|S t          j        d|           D ]}	 |                    dd          \  }}n# t          $ r |d}}Y nw xY wd|                     d          i}|                    d          D ]X}	 |                    d          \  }} n# t          $ r Y  n0w xY w|                      |          ||                     |          <   Y|                    |           |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"

    :rtype: list
    z '"z, *<rE   r   r   r   z<> '"r   )r  rT   rQ   rP   r   )	r   linksreplace_charsvalr   r	  linkr  r  s	            r[   parse_header_linksr    sA    #%EMKK&&E x&&  	"))C++KC 	" 	" 	"rCCC	" !&syy':':;\\#&& 	H 	HE"[[--
UU    .3[[-G-GD=))**TLs#   AA! A!B,,
B:9B: asciirp      datac                   | 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    rd	S |dk    r,|ddd         t          k    rd
S |ddd         t          k    rdS |dk    r*|dd         t          k    rdS |dd         t          k    rdS dS )z
    :rtype: str
    N   zutf-32r  z	utf-8-sigrp   zutf-16r   ri   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_BErc  _null_null2_null3)r  sample	nullcounts      r[   guess_json_utfr    s    "1"XF&%v':;;;xbqbzV_$${bqbzf)6+>???xU##IA~~wA~~##A#;&  ;!$Q$<6!!;A~~"1":;!"":;4r^   
new_schemec                    t          |           }|\  }}}}}}}	|j        }
|
s||
}}
|r,t          t          |
          }
d                    ||
g          }
||}|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.

    :rtype: str
    @Nr   )r   netlocr   r!   r   r$   )r   r  ry  r  auth_host_portr   queryfragmentr  s              r[   prepend_scheme_if_neededr    s     s^^F8>5FD%eX ]F $V * c6""4.))~|vvtRABBBr^   tuple[str, str]c                    t          |           }	 t          |j                  t          |j                  f}n# t          t
          f$ r d}Y nw xY w|S )z{Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    )r   r   )r#   r"   usernamepasswordr{   r5  )r   ry  r  s      r[   get_auth_from_urlr  .  sd     c]]F(('&/*B*BCI&    Ks   (: AAtuple[str | bytes, str | bytes]c                T    | \  }}t          | |d           t          | |d           dS )zVerifies 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   s      r[   check_header_validityr  ?  s7     KD%&$***&%+++++r^   header_partstr | bytesheader_validator_indexc           
     D   t          |t                    rt          |         }nHt          |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: )rc   r!   r   r   r   r)   typerU   )r  r  r  	validatorheader_kinds        r[   r  r  J  s    
 +s## 	
*+AB			K	'	' 
+,BC		EK E E& E E15k1B1BE E
 
 	

 ??;'' 
 6! ; ;ffE&1E E5@E E
 
 	

 
r^   c                    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$   )r   r  r  r   r	  r  	_fragments          r[   urldefragauthr  b  sb     6>c]]2FFD&%  $V]]3""2&FvvtVUB?@@@r^   prepared_requestr0   c                    t          | j        dd          }|Jt          | j        t                    r0	  || j                   dS # t
          $ r t          d          w xY wt          d          )zfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    ro   Nz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)r   bodyrc   _body_positionr   rO   r+   )r  	body_seeks     r[   rewind_bodyr  s  s     (-vt<<I'" "	I&566666 	 	 	'M  	
 $$QRRRs   A A )r?   r!   r@   rA   )r_   r`   r@   ra   )rg   r   r@   rM   )F)r   r   r   rA   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   rA   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  r2   r@   r  )r%  r   r&  r'  r@   r(  )r%  r!   r&  r'  r@   r,  )r%  r.  r&  r'  r@   r/  )r  r2   r@   r2  )r9  r!   r@   r!   )rK  r!   rL  r!   r@   rA   )rY  rM   r@   r!   )r^  r!   r@   rA   )ra  r!   r@   rA   )re  r!   r   r   r@   rf  )r   r!   rk  r   r@   rA   r   )r   r!   rk  r   r@   r   )r   r!   r  r  r@   r   )T)r  r  r  r  r  rA   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  rM   r@   r   )r   r!   r@   r!   )r  r0   r@   r   )__doc__
__future__r   r  
contextlibry   rs   rT   rP  rN  sysr   rw   r   collectionsr   collections.abcr   r   typingr   r   r	   r
   r   r   urllib3.utilr   r   r   r   r   _internal_utilsr   r   r   r   r/   r   rd   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modelsr0   r1   r2   r4   __annotations__wherer5   r9   r:   r;   r   rQ   r=   platformr\   rf   r   r   r   r   contextmanagerr   r   r   r   r   r   r   r   r   r  r  r$  r+  r7  	frozensetr8  rE  rJ  rX  rR  r`  rd  rj  r~  r  r  r  r  r  r  rq   r  r  r  r  r  r  r  r  r  r  r   r^   r[   <module>r     s4     # " " " " "      				 				 				   



    # # # # # # / / / / / / / /                1 0 0 0 0 0 0 0       $ $ $ $ $ $            4 3 3 3 3 3                              : 9 9 9 9 9 ( ( ( ( ( (            , + + + + + ;((((((!!!!!!::::::::::) ) ) ) ) *ekmm  + + + + !#S11 1 1 1 1genngenn "&BHWll48889JKLL" "     
 <7$ $ $ $L	/ 	/ 	/ 	/   D3 D3 D3 D3P +01 1 1 1 1h& & & &# # # #L 	 	 	 	   : 
 - - - 
 -	      
    @   @   F    2   0 0 0 0   2% % % %,   2   & 
' ' ' 
' 
% % % 
%	 	 	 	& & & &T "	M     
   05 5 5 5,5 5 5 55 5 5 5      0 1 1 1 1,< < < <~	 	 	 	 	   :     ># # # # #   " " " "L 	g		   @C C C C<   ", , , ,
 
 
 
0A A A A"S S S S S Sr^   