
    Zhu                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZmZm Z m!Z!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Z- ej\                         Z/dddZ0ejb                  dk(  rd Z2d Zd Z3d Z4d@dZ5d Z6d Z7d Z8d Z9d Z:d Z;d@dZ<d Z=d Z>d  Z?d! Z@d" ZAd# ZBd$ ZCd% ZD eEd&      ZFd' ZGd( ZHd) ZId* ZJd+ ZKd, ZLej                  d-        ZNd. ZOdAd/ZPd0 ZQdBd1ZRd2 ZSd3 ZTd4j                  d5      ZVeVd6z  ZWeVd7z  ZXd8 ZYd9 ZZd: Z[ ej                  d;      Z] ej                  d<      Z^d= Z_d> Z`d? Zay)Cz
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
    N)OrderedDict   __version__)certs)to_native_string)parse_http_list)quoteurlparsebytesstrunquote
getproxiesproxy_bypass
urlunparse
basestringinteger_typesis_py3proxy_bypass_environmentgetproxies_environmentMappingcookiejar_from_dict)CaseInsensitiveDict)
InvalidURLInvalidHeaderFileModeWarningUnrewindableBodyError)z.netrc_netrcP   i  )httphttpswin32c                 
   	 t         rdd l}ndd l}	 |j	                  |j
                  d      }t        |j                  |d      d         }|j                  |d      d   }|r|sy|j                  d      }|D ]j  }|dk(  rd| vr y	|j                  dd
      }|j                  dd      }|j                  dd      }t        j                  || t        j                        sj y	 y# t        $ r Y yw xY w# t        $ r Y yw xY w)Nr   Fz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableProxyOverride;z<local>.Tz\.*z.*?)r   winreg_winregImportErrorOpenKeyHKEY_CURRENT_USERintQueryValueExOSErrorsplitreplacerematchI)hostr+   internetSettingsproxyEnableproxyOverridetests         ]/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/requests/utils.pyproxy_bypass_registryr>   0   s+   	(
	%~~f.F.FN P f112B.;==>@ AK #//0@0?AABDM -
 &++C0! 	Dy d?<<U+D<<U+D<<T*DxxdBDD)	 ?  		  		s#   C' AC6 '	C32C36	DDc                 B    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>   )r8   s    r=   r   r   W   s      "#+D11(..    c                 >    t        | d      r| j                         } | S )z/Returns an internal sequence dictionary update.items)hasattrrB   )ds    r=   dict_to_sequencerE   c   s     q'GGIHr@   c                    d }d}t        | d      rt        |       }n~t        | d      r| j                  }net        | d      rY	 | j                         }t        j                  |      j
                  }d| j                  vrt        j                  dt               	 t        | d      rW	 | j                         }t        | d      r:|8	 | j                  dd	       | j                         }| j                  |xs d       |d}t!        d||z
        S # t        j                  $ r Y w xY w# t        t        f$ r d}Y ?w xY w# t        t        f$ r ||}Y Xw xY w)
Nr   __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   )rC   rH   rI   osfstatst_sizemodewarningswarnr   ioUnsupportedOperationrK   rL   r2   IOErrormax)ototal_lengthcurrent_positionrI   s       r=   	super_lenr[   l   s`   Lq)1v	E	uu	H		XXZF 88F+33L !&& . $ q&	% vvx q&!l&:	%FF1aL#$668L FF+0q1 q,!1122[ && 		N  ) %#$L%% ! 	0
 '#/ 	0s6   D (E 7D* D'&D'*D>=D>EEc                 >   	 ddl m }m} d}t        D ]T  }	 t        j                  j                  dj                  |            }t        j                  j                  |      sR|} n |yt        |       }d}t        | t              r|j                  d      }|j                  j                  |      d   }		  ||      j                  |	      }
|
r|
d   rdnd}|
|   |
d   fS y# t        $ r Y  yw xY w# |t         f$ r |r Y yw xY w# t"        t$        f$ r Y yw xY w)	z;Returns the Requests tuple auth for a given url from netrc.r   )netrcNetrcParseErrorNz~/{}   :asciir   rM   )r]   r^   NETRC_FILESrN   path
expanduserformatKeyErrorexistsr   
isinstancer   decodenetlocr3   authenticatorsrV   r-   AttributeError)urlraise_errorsr]   r^   
netrc_pathflocrisplitstrr8   r   login_is               r=   get_netrc_authrt      s6   -0
 	Agg((q)9: ww~~c" 
	 c] c3w/Hyyx(+
	:&55d;F &q	1qw33 3   	:  ) 	  	 ( s_   D
 .C&D
 $D
 ,AD
 9+C6 &	C3/D
 2C33D
 6DD
 DD
 
DDc                     t        | dd      }|rBt        |t              r1|d   dk7  r(|d   dk7  rt        j                  j                  |      S yyyy)z0Tries to guess the filename of the given object.nameNr   <>)getattrrg   r   rN   rb   basename)objrv   s     r=   guess_filenamer}      sV    3%DD*-$q'S.HOww%%  3A-r@   c                    t         j                  j                  |       r| S t         j                  j                  |       \  }}|rvt         j                  j                  |      sWt         j                  j                  |      \  }}dj	                  ||g      }|r t         j                  j                  |      sWt        j                  |      s| S t        j                  |      }||j                         vr| S t        j                         }t        j                  j                  |g|j                  d       }t         j                  j                  |      s|j                  ||      }|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.
    /)rb   )rN   rb   rf   r3   joinzipfile
is_zipfileZipFilenamelisttempfile
gettempdirextract)rb   archivememberprefixzip_filetmpextracted_paths          r=   extract_zipped_pathsr      s   
 
ww~~d ggmmD)OGV
"''..1''--066*+ "''..1 g&w'HX&&(( 


CWW\\#:S(9:N77>>.)!))&s);r@   c                 t    | y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)rg   r   r   boolr0   
ValueErrorr   values    r=   from_key_val_listr     s6    $ }%#udC01FGGur@   c                     | yt        | t        t        t        t        f      rt        d      t        | t              r| j                         } 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   )	rg   r   r   r   r0   r   r   rB   listr   s    r=   to_key_val_listr     sJ    " }%#udC01FGG%!;r@   c                     g }t        |       D ]5  }|dd |dd cxk(  rdk(  rn nt        |dd       }|j                  |       7 |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   rx   ")_parse_list_headerunquote_header_valueappend)r   resultitems      r=   parse_list_headerr   =  sY    . F"5) 8tBCy'C''Qr
3Dd Mr@   c                     i }t        |       D ]H  }d|vrd||<   |j                  dd      \  }} | dd | dd cxk(  rdk(  rn nt        | dd       } | ||<   J |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   rx   r   )r   r3   r   )r   r   r   rv   s       r=   parse_dict_headerr   ]  s}    , F"5) d?F4Ljja(e!9bc
)c)(q5Et Mr@   c                     | rF| d   | d   cxk(  rdk(  r5n | S | dd } |r| dd dk7  r"| j                  dd      j                  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   rx   r   r   NrM   z\\\z\")r4   )r   is_filenames     r=   r   r     sd     qU2Y-#- L a eBQi61==.66ucBBLr@   c                 J    i }| D ]  }|j                   ||j                  <    |S )zReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    )r   rv   )cjcookie_dictcookies      r=   dict_from_cookiejarr     s2     K 0#)<<FKK 0 r@   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   r   s     r=   add_dict_to_cookiejarr     s     {B//r@   c                 ^   t        j                  dt               t        j                  dt        j
                        }t        j                  dt        j
                        }t        j                  d      }|j                  |       |j                  |       z   |j                  |       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=["\']*(.+?)["\'>])rR   rS   DeprecationWarningr5   compiler7   findall)content
charset_re	pragma_rexml_res       r=   get_encodings_from_contentr     s    
 MM	- 		 @MJ

IQSQUQUVIZZ?@Fw'g&'NN7#$ %r@   c                 H   | j                  d      }|d   j                         |dd }}i }d}|D ]m  }|j                         }|s|d}}|j                  d      }	|	dk7  r+|d|	 j                  |      }||	dz   d j                  |      }|||j                         <   o ||fS )	zReturns content type and parameters from given header

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters
    r'   r   r   Nz"' Tr   rx   )r3   stripfindlower)
headertokenscontent_typeparamsparams_dictitems_to_stripparamkeyr   index_of_equalss
             r=   _parse_content_type_headerr     s     \\#F!!9??,fQRj&LKN -C#jjoO"$,_-33NCo12399.I',K		$- $$r@   c                     | j                  d      }|syt        |      \  }}d|v r|d   j                  d      S d|v ryy)z}Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    zcontent-typeNcharsetz'"textz
ISO-8859-1)getr   r   )headersr   r   s      r=   get_encoding_from_headersr     sU     ;;~.L5lCL&Fi &&u-- r@   c              #      K   |j                   | D ]  }|  y t        j                  |j                         d      }| D ]  }|j                  |      }|s|  |j                  dd      }|r| yyw)zStream decodes a iterator.Nr4   errorsr@   T)final)encodingcodecsgetincrementaldecoderrh   )iteratorrr   decoderchunkrvs         r=   stream_decode_response_unicoder     s      	zz 	DJ	6f**1::6iHG ^^E"H 
4	(B	 
s   AA;!A;c              #      K   d}||dk  rt        |       }|t        |       k  r| |||z     ||z  }|t        |       k  ryyw)z Iterate over slices of a string.r   N)rH   )stringslice_lengthposs      r=   iter_slicesr     sW     
C|q06{
F
S|+,,| F
s   A AAc                 >   t        j                  dt               g }t        | j                        }|r	 t        | j                  |      S 	 t        | j                  |d      S # t        $ r |j                  |       Y 5w xY w# 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.)r4   r   )
rR   rS   r   r   r   r   r   UnicodeErrorr   	TypeError)r   tried_encodingsr   s      r=   get_unicode_from_responser     s     MM	- 		 O )3H	-qyy(++
199hy99  	-""8,	-  yys#   A$ B $B BBBzBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~c                    | j                  d      }t        dt        |            D ]l  }||   dd }t        |      dk(  rI|j                         r9	 t	        t        |d            }|t        v r|||   dd z   ||<   Vd||   z   ||<   bd||   z   ||<   n dj                  |      S # t        $ r t        d|z        w xY w)	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   rM      z%Invalid percent-escape sequence: '%s'N )
r3   rangerH   isalnumchrr0   r   r   UNRESERVED_SETr   )uripartsihcs        r=   unquote_unreservedr   :  s     IIcNE1c%j! &!HQqMq6Q;199;NAr
O N"uQx|+aq>aU1X~E!H& 775>  N !H1!LMMNs   B''B?c                 p    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
   r   r   )r   safe_with_percentsafe_without_percents      r=   requote_urir   R  sJ     /0	5 ',3DEE 5 S344	5s    55c           
      r   t        j                  dt        j                  |             d   }|j	                  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_atonr3   dotted_netmaskr0   )ipnetipaddrnetaddrbitsnetmasknetworks          r=   address_in_networkr  h  s     ]]4!1!1"!56q9FIIcNMGTmmD&"2"2>#d)3L"MNqQGmmD&"2"27";<Q?'IGW'G"344r@   c                 p    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)r   	inet_ntoar   pack)maskr   s     r=   r   r   w  s7     b4i1,,DFKKd344r@   c                 b    	 t        j                  |        y# t         j                  $ r Y yw xY w)z
    :rtype: bool
    FT)r   r   error)	string_ips    r=   is_ipv4_addressr    s2    #  << s    ..c                     | j                  d      dk(  rR	 t        | j                  d      d         }|dk  s|dkD  ry	 t	        j
                  | j                  d      d          yy# t        $ r Y yw xY w# t        j                  $ r Y yw xY w)zV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    r   r   Fr  r   T)countr0   r3   r   r   r   r
  )string_networkr  s     r=   is_valid_cidrr    s     C A%	~++C034D !8tby	^11#6q9:
    		 || 		s"   A( 'A7 (	A43A47BBc              #   8  K   |du}|r2t         j                  j                  |       }|t         j                  | <   	 d |r(t         j                  | = y|t         j                  | <   yy# |r(t         j                  | = w |t         j                  | <   w w xY w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)rN   environr   )env_namer   value_changed	old_values       r=   set_environr    s      %MJJNN8,	$

81 JJx('0

8$	 = JJx('0

8$	 s   9BA+  +B+,BBc                    d }|}| |d      }t        |       }|j                  y|rd |j                  dd      j                  d      D        }t	        |j                        r=|D ]7  }t        |      rt        |j                  |      s% y|j                  |k(  s7 y nk|j                  }|j                  r|d	j                  |j                        z  }|D ]0  }|j                  j                  |      s|j                  |      s0 y t        d|      5  	 t        |j                        }ddd       ryy
# t        t        j                  f$ r d
}Y )w xY w# 1 sw Y   .xY w)zL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    c                     t         j                  j                  |       xs- t         j                  j                  | j                               S N)rN   r  r   upper)ks    r=   <lambda>z'should_bypass_proxies.<locals>.<lambda>  s+    "**..+Hrzz~~aggi/H r@   Nno_proxyTc              3   &   K   | ]	  }|s|  y wr   ).0r8   s     r=   	<genexpr>z(should_bypass_proxies.<locals>.<genexpr>  s      
TD
s    r   ,z:{}F)r   hostnamer4   r3   r  r  r  portrd   endswithr  r   r   r   gaierror)	rl   r  	get_proxyno_proxy_argparsedproxy_iphost_with_portr8   bypasss	            r=   should_bypass_proxiesr.    sb    II LZ(c]F
%--c26<<SA
 6??+$   *)&//8D#__0    $__N{{%,,v{{";;   ??++D1^5L5LT5R  	  
Z	. 	!&//2F  6??+ 	F		 s*   ED>>EEEEE(c                 4    t        | |      ri S t               S )zA
    Return a dict of environment proxies.

    :rtype: dict
    )r  )r.  r   )rl   r  s     r=   get_environ_proxiesr0    s     S84	|r@   c                 .   |xs i }t        |       }|j                  +|j                  |j                  |j                  d            S |j                  dz   |j                  z   |j                  d|j                  z   dg}d}|D ]  }||v s||   } |S  |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)rl   proxiesurlparts
proxy_keysproxy	proxy_keys         r=   select_proxyr9    s     mG}H {{8??GKK,>?? 	%("3"338$$$	J E 	I&EL
 Lr@   c                     | dt         S )zO
    Return a string representing the default user agent.

    :rtype: str
    r   r   )rv   s    r=   default_user_agentr;    s     K((r@   c                  P    t        t               dj                  d      ddd      S )z9
    :rtype: requests.structures.CaseInsensitiveDict
    z, )gzipdeflatez*/*z
keep-alive)z
User-AgentzAccept-EncodingAccept
Connection)r   r;  r   r  r@   r=   default_headersrA  '  s/     (*99%89"	   r@   c                    g }d}| j                  |      } | s|S t        j                  d|       D ]  }	 |j                  dd      \  }}d|j                  d      i}|j                  d      D ]:  }	 |j                  d      \  }} | j                  |      ||j                  |      <   < |j	                  |        |S # t        $ r |d}}Y w xY w# t        $ r Y  4w xY w)	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, *<r'   r   r   rl   z<> '"r   )r   r5   r3   r   r   )	r   linksreplace_charsvalrl   r   linkr   r   s	            r=   parse_header_linksrG  3  s     EMKK&Exx& 	"))C+KC syy*+\\#& 	HE"[[-
U .3[[-GD=)*	H 	T!$ L  	"rC	"  s#   B?1C?CC	CC r`   rM      c                    | dd }|t         j                  t         j                  fv ry|dd t         j                  k(  ry|dd t         j                  t         j
                  fv ry|j                  t              }|dk(  ry	|dk(  r |ddd   t        k(  ry
|ddd   t        k(  ry|dk(  r|dd t        k(  ry|dd t        k(  ryy)z
    :rtype: str
    N   zutf-32rI  z	utf-8-sigrM   zutf-16r   zutf-8z	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)datasample	nullcounts      r=   guess_json_utfrW  ^  s     "1XF&%%v':':;;bqzV__$bqzf))6+>+>??U#IA~A~#A#;& !$Q$<6!A~"1:!":r@   c                 V    t        | |      \  }}}}}}|s||}}t        ||||||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
    )r   r   )rl   
new_schemer3  ri   rb   r   queryfragments           r=   prepend_scheme_if_neededr\  ~  sC     5=S*4M1FFD&%
 VvvtVUHEFFr@   c                     t        |       }	 t        |j                        t        |j                        f}|S # t        t
        f$ r d}Y |S w xY 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   )rl   r*  auths      r=   get_auth_from_urlra    sU     c]F('&//*BC K I& Ks   *9 AAs   ^\S[^\r\n]*$|^$z^\S[^\r\n]*$|^$c                     | \  }}t        |t              rt        }nt        }	 |j	                  |      st        d|z        y# t        $ r t        d|d|dt        |            w xY w)zVerifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.

    :param header: tuple, in the format (name, value).
    z7Invalid return character or leading space in header: %szValue for header {z: z$} must be of type str or bytes, not N)rg   r   _CLEAN_HEADER_REGEX_BYTE_CLEAN_HEADER_REGEX_STRr6   r   r   type)r   rv   r   pats       r=   check_header_validityrg    s{     KD%%&%Jyy Y\` `aa   J/3UDKI J 	JJs   A 'A+c                 ~    t        |       \  }}}}}}|s||}}|j                  dd      d   }t        |||||df      S )zW
    Given a url remove the fragment and the authentication part.

    :rtype: str
    @r   rx   r   )r   rsplitr   )rl   r3  ri   rb   r   rZ  r[  s          r=   urldefragauthrk    sU     5=SM1FFD&% V]]3"2&FvvtVUB?@@r@   c                     t        | j                  dd      }|.t        | j                  t              r	  || j                         yt        d      # t
        t        f$ r t        d      w xY w)zfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    rL   Nz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)rz   bodyrg   _body_positionr   rV   r2   r   )prepared_request	body_seeks     r=   rewind_bodyrq    sy     (--vt<I,<,K,K]![	>&556
 $$QRR	 ! 	>' )= > >	>s   A A.)Fr  )zpython-requests)b__doc__r   
contextlibrT   rN   r5   r   r   sysr   rR   r   collectionsr   r   r   r   _internal_utilsr   compatr	   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   cookiesr   
structuresr   
exceptionsr   r   r   r   ra   whereDEFAULT_CA_BUNDLE_PATHDEFAULT_PORTSplatformr>   rE   r[   rt   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	frozensetr   r   r   r  r   r  r  contextmanagerr  r.  r0  r9  r;  rA  rG  encoderQ  rR  rS  rW  r\  ra  r   rc  rd  rg  rk  rq  r  r@   r=   <module>r     s     	 	 	   
    # $  - 9? ? ? ? ) +G G #$ c* <<7%N	/:3z0f&@6<@F20%(%2*$!J MO05,550 1 1*:z	4)	"L 	g		@G"" &2::&;< $"**%78 J*A"Sr@   