
    t                        S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJrJrJrJr  SSKJrJrJrJr  SS	KJrJrJr  SS
KJrJr  SSKJr  SSKJrJ r J!r!  SSK"J#r#J$r$J%r%J&r&  SSK'J(r(  SSK)J*r*  SSKJ+r+J,r,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3  SSKJ4r4  \Rj                  S:X  a   \Rl                  r7O\R                  r7\4S jr:\4S jr; " S S\<5      r= " S S\=5      r>S r?g! \8 a    \Rr                  r7 N:f = f)z
requests.sessions
~~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
    N)	timedelta)OrderedDict   )_basic_auth_str)	cookielibis_py3urljoinurlparseMapping)cookiejar_from_dictextract_cookies_to_jarRequestsCookieJarmerge_cookies)RequestPreparedRequestDEFAULT_REDIRECT_LIMIT)default_hooksdispatch_hook)to_native_string)to_key_val_listdefault_headersDEFAULT_PORTS)TooManyRedirectsInvalidSchemaChunkedEncodingErrorContentDecodingError)CaseInsensitiveDict)HTTPAdapter)requote_uriget_environ_proxiesget_netrc_authshould_bypass_proxiesget_auth_from_urlrewind_bodyresolve_proxies)codes)REDIRECT_STATIwin32c                 <   Uc  U $ U c  U$ [        U[        5      (       a  [        U [        5      (       d  U $ U" [        U5      5      nUR                  [        U 5      5        UR	                  5        VVs/ s H  u  pEUb  M
  UPM     nnnU H  nX7	 M     U$ s  snnf )zDetermines appropriate setting for a given request, taking into account
the explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class`
)
isinstancer   r   updateitems)request_settingsession_setting
dict_classmerged_settingkv	none_keyskeys           ,platform/bq/third_party/requests/sessions.pymerge_settingr6   3   s      0000 @AN//:; "0!5!5!7E!7v1!7IE  	 Fs   5	BBc                     Ub  UR                  S5      / :X  a  U $ U b  U R                  S5      / :X  a  U$ [        XU5      $ )zProperly merges both requests and session hooks.

This is necessary because when request_hooks == {'response': []}, the
merge breaks Session hooks entirely.
response)getr6   )request_hookssession_hooksr/   s      r5   merge_hooksr<   R   sM      1 1* = C 1 1* = CzBB    c                   @    \ rS rSrS rS r  S
S jrS rS rS r	S	r
g)SessionRedirectMixina   c                     UR                   (       a7  UR                  S   n[        (       a  UR                  S5      n[	        US5      $ g)z7Receives a Response. Returns a redirect URI or ``None``locationlatin1utf8N)is_redirectheadersr   encoder   )selfresprB   s      r5   get_redirect_target(SessionRedirectMixin.get_redirect_targetc   s@     ||J/H v#??84#Hf55r=   c                    [        U5      n[        U5      nUR                  UR                  :w  a  gUR                  S:X  a1  UR                  S;   a!  UR                  S:X  a  UR                  S;   a  gUR                  UR                  :g  nUR                  UR                  :g  n[        R
                  " UR                  S5      S4nU(       d!  UR                  U;   a  UR                  U;   a  gU=(       d    U$ )zFDecide whether Authorization header should be removed when redirectingThttp)P   Nhttps)i  NFN)r
   hostnameschemeportr   r9   )rH   old_urlnew_url
old_parsed
new_parsedchanged_portchanged_schemedefault_ports           r5   should_strip_auth&SessionRedirectMixin.should_strip_authx   s    g&
g&
*"5"55
 'JOOz,I%%0Z__5S "*//9#**j.?.??%))**;*;TBDI:??l#BOO|3 -~-r=   Nc	           
   +   N  #    / n
U R                  U5      n[        UR                  5      R                  nU(       Ga2  UR	                  5       nU
R                  U5        U
SS Ul         UR                    [        UR                  5      U R                  :  a#  [        SR!                  U R                  5      US9eUR#                  5         UR%                  S5      (       a;  [        UR                  5      nSR'                  [)        UR*                  5      U/5      n[        U5      nUR                  S	:X  a  U(       a  UR-                  US
9nOUR                  (       a  UR                  nUR/                  5       nUR0                  (       d   [3        UR                  [5        U5      5      nO[5        U5      n[)        U5      Ul        U R7                  X5        UR8                  [:        R<                  [:        R>                  4;  a.  SnU H  nUR@                  RC                  US5        M!     SUl"        UR@                  nURC                  SS5        [G        URH                  X!R                  5        [K        URH                  U RL                  5        URO                  URH                  5        U RQ                  X5      nU RS                  X5        URT                  SL=(       a    SU;   =(       d    SU;   nU(       a  [W        U5        UnU(       a  Uv   OOU RX                  " U4UUUUUSS.U	D6n[G        U RL                  XR                  5        U R                  U5      nUv   U(       a  GM1  gg! [        [        [        4 a    UR                  R                  SS9   GN,f = f7f)zBReceives a Response. Returns a generator of Responses or Requests.r   NF)decode_contentzExceeded {} redirects.)r8   z//: )fragment)Content-LengthzContent-TypeTransfer-EncodingCookiera   rb   )streamtimeoutverifycertproxiesallow_redirects)-rJ   r
   urlr`   copyappendhistorycontentr   r   RuntimeErrorrawreadlenmax_redirectsr   formatclose
startswithjoinr   rQ   _replacegeturlnetlocr	   r   rebuild_methodstatus_coder&   temporary_redirectpermanent_redirectrF   popbodyr   _cookiesr   cookiesprepare_cookiesrebuild_proxiesrebuild_auth_body_positionr$   send)rH   rI   reqrd   re   rf   rg   rh   yield_requestsadapter_kwargshistrj   previous_fragmentprepared_requestparsed_rurlparsedpurged_headersheaderrF   
rewindables                       r5   resolve_redirects&SessionRedirectMixin.resolve_redirects   s     &&t,$SWW-66"xxz KK8DL4 4<< D$6$66&'?'F'FtGYGY'Zeijj JJL ~~d##&txx0hh 01C1C DcJK c]F"$):2CD$*OO!--/C
 ==dhhC(89!#&#3C#8  07 (@(@%BZBZ'[[!X,F$,,00> -(, %&..GKK$'
 ##3#<#<c88L*33T\\B,,-=-F-FG **+;EG.5 !//t; P!W,N0Cw0N  ,- #C	 yy	!#!#$)	 %	 't||5ExxP ..t4
I c )*>M 4U34s1   A&N%)M0 5K6N%.N%0.N"N%!N""N%c                    UR                   nUR                  nSU;   a.  U R                  UR                  R                  U5      (       a  US	 U R                  (       a  [        U5      OSnUb  UR                  U5        gg)zWhen being redirected we may want to strip authentication from the
request to avoid leaking credentials. This method intelligently removes
and reapplies authentication where possible to avoid credential loss.
AuthorizationN)rF   rj   rZ   request	trust_envr!   prepare_auth)rH   r   r8   rF   rj   new_auths         r5   r   !SessionRedirectMixin.rebuild_auth   sx    
 #**""g%$*@*@AQAQAUAUWZ*[*[ ( +/..>#&d))(3  r=   c                    UR                   n[        UR                  5      R                  n[	        XU R
                  5      nSU;   a  US	  [        XT   5      u  pgU(       a  U(       a  [        Xg5      US'   U$ ! [         a    Su  pg N.f = f)ap  This method re-evaluates the proxy configuration by considering the
environment variables. If we are redirected to a URL covered by
NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
proxy keys for this URL (in case they were stripped by a previous
redirect).

This method also replaces the Proxy-Authorization header where
necessary.

:rtype: dict
zProxy-AuthorizationNN)	rF   r
   rj   rQ   r%   r   r#   KeyErrorr   )rH   r   rh   rF   rQ   new_proxiesusernamepasswords           r5   r   $SessionRedirectMixin.rebuild_proxies  s     #***../66%&6P G+-.	,!2;3F!GH -<X-PG)*  	,!+Hh	,s   A9 9B
	B
c                    UR                   nUR                  [        R                  :X  a  US:w  a  SnUR                  [        R                  :X  a  US:w  a  SnUR                  [        R
                  :X  a  US:X  a  SnX1l         g)zrWhen being redirected we may want to change the method of the request
based on certain specs or browser behavior.
HEADGETPOSTN)methodr|   r&   	see_otherfoundmoved)rH   r   r8   r   s       r5   r{   #SessionRedirectMixin.rebuild_method.  su     "(( 5??2v7GF 5;;.6V3CF 5;;.6V3CF"(r=    )FNTNNF)__name__
__module____qualname____firstlineno__rJ   rZ   r   r   r   r{   __static_attributes__r   r=   r5   r?   r?   a   s,    *.2 BFOTl\4$:)r=   r?   c                       \ rS rSrSr/ SQrS rS rS rS r	   SS	 jr
S
 rS rS rSS jrSS jrSS jrS rS rS rS rS rS rS rS rSrg)SessioniE  aT  A Requests session.

Provides cookie persistence, connection-pooling, and configuration.

Basic Usage::

  >>> import requests
  >>> s = requests.Session()
  >>> s.get('https://httpbin.org/get')
  <Response [200]>

Or as a context manager::

  >>> with requests.Session() as s:
  ...     s.get('https://httpbin.org/get')
  <Response [200]>
)rF   r   authrh   hooksparamsrf   rg   adaptersrd   r   rs   c                 ^   [        5       U l        S U l        0 U l        [	        5       U l        0 U l        SU l        SU l        S U l	        [        U l        SU l        [        0 5      U l        [        5       U l        U R#                  S[%        5       5        U R#                  S[%        5       5        g )NFTzhttps://zhttp://)r   rF   r   rh   r   r   r   rd   rf   rg   r   rs   r   r   r   r   r   mountr   rH   s    r5   __init__Session.__init__^  s    
 '( 	
  #_

    	 4  +2. $

:{}-

9km,r=   c                     U $ Nr   r   s    r5   	__enter__Session.__enter__  s    r=   c                 $    U R                  5         g r   )ru   )rH   argss     r5   __exit__Session.__exit__  s    

r=   c                    UR                   =(       d    0 n[        U[        R                  5      (       d  [	        U5      n[        [        [        5       U R                   5      U5      nUR                  nU R                  (       a-  U(       d&  U R                  (       d  [        UR                  5      n[        5       nUR                  UR                  R                  5       UR                  UR                  UR                   UR"                  [%        UR&                  U R&                  [(        S9[%        UR*                  U R*                  5      [%        X@R                  5      U[-        UR.                  U R.                  5      S9
  U$ )aS  Constructs a :class:`PreparedRequest <PreparedRequest>` for
transmission and returns it. The :class:`PreparedRequest` has settings
merged from the :class:`Request <Request>` instance and those of the
:class:`Session`.

:param request: :class:`Request` instance to prepare with this
    session's settings.
:rtype: requests.PreparedRequest
)r/   )
r   rj   filesdatajsonrF   r   r   r   r   )r   r*   r   	CookieJarr   r   r   r   r   r!   rj   r   preparer   upperr   r   r   r6   rF   r   r   r<   r   )rH   r   r   merged_cookiesr   ps         r5   prepare_requestSession.prepare_request  s    //'R '9#6#677)'2G '+-t||<gG ||>>$tyy!'++.D			>>'')--!'//4<<L_` =tYY/"gmmTZZ8 	 	
 r=   Nc                 .   [        UR                  5       UUUU=(       d    0 UU=(       d    0 UUUS9
nU R                  U5      nU=(       d    0 nU R                  UR                  XX5      nU	U
S.nUR                  U5        U R                  " U40 UD6nU$ )a@  Constructs a :class:`Request <Request>`, prepares it and sends it.
Returns :class:`Response <Response>` object.

:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query
    string for the :class:`Request`.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
    object to send in the body of the :class:`Request`.
:param json: (optional) json to send in the body of the
    :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the
    :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the
    :class:`Request`.
:param files: (optional) Dictionary of ``'filename': file-like-objects``
    for multipart encoding upload.
:param auth: (optional) Auth tuple or callable to enable
    Basic/Digest/Custom HTTP Auth.
:param timeout: (optional) How long to wait for the server to send
    data before giving up, as a float, or a :ref:`(connect timeout,
    read timeout) <timeouts>` tuple.
:type timeout: float or tuple
:param allow_redirects: (optional) Set to True by default.
:type allow_redirects: bool
:param proxies: (optional) Dictionary mapping protocol or protocol and
    hostname to the URL of the proxy.
:param stream: (optional) whether to immediately download the response
    content. Defaults to ``False``.
:param verify: (optional) Either a boolean, in which case it controls whether we verify
    the server's TLS certificate, or a string, in which case it must be a path
    to a CA bundle to use. Defaults to ``True``. When set to
    ``False``, requests will accept any TLS certificate presented by
    the server, and will ignore hostname mismatches and/or expired
    certificates, which will make your application vulnerable to
    man-in-the-middle (MitM) attacks. Setting verify to ``False`` 
    may be useful during local development or testing.
:param cert: (optional) if String, path to ssl client cert file (.pem).
    If Tuple, ('cert', 'key') pair.
:rtype: requests.Response
)
r   rj   rF   r   r   r   r   r   r   r   )re   ri   )r   r   r   merge_environment_settingsrj   r+   r   )rH   r   rj   r   r   rF   r   r   r   re   ri   rh   r   rd   rf   rg   r   r   prepsettingssend_kwargsrI   s                         r5   r   Session.request  s    \ <<><R
 ##C(-R22HHgv
 .
 	8$yy--r=   c                 N    UR                  SS5        U R                  " SU40 UD6$ )zSends a GET request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
ri   Tr   
setdefaultr   rH   rj   kwargss      r5   r9   Session.get  s+     	+T2||E31&11r=   c                 N    UR                  SS5        U R                  " SU40 UD6$ )zSends a OPTIONS request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
ri   TOPTIONSr   r   s      r5   optionsSession.options!  s+     	+T2||Is5f55r=   c                 N    UR                  SS5        U R                  " SU40 UD6$ )zSends a HEAD request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
ri   Fr   r   r   s      r5   headSession.head,  s+     	+U3||FC2622r=   c                 .    U R                   " SU4X#S.UD6$ )a  Sends a POST request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
    object to send in the body of the :class:`Request`.
:param json: (optional) json to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
r   )r   r   r   )rH   rj   r   r   r   s        r5   postSession.post7  s     ||FCHdHHHr=   c                 .    U R                   " SU4SU0UD6$ )aE  Sends a PUT request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
    object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
PUTr   r   rH   rj   r   r   s       r5   putSession.putD  s     ||E3<T<V<<r=   c                 .    U R                   " SU4SU0UD6$ )aG  Sends a PATCH request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
    object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
PATCHr   r   r   s       r5   patchSession.patchP  s     ||GS>t>v>>r=   c                 *    U R                   " SU40 UD6$ )zSends a DELETE request. Returns :class:`Response` object.

:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
DELETEr   r   s      r5   deleteSession.delete\  s     ||Hc4V44r=   c                    UR                  SU R                  5        UR                  SU R                  5        UR                  SU R                  5        SU;  a#  [	        XR
                  U R                  5      US'   [        U[        5      (       a  [        S5      eUR                  SS5      nUR                  S5      nUR                  nU R                  UR                  S9n[        5       nUR                   " U40 UD6n[        5       U-
  n	[#        U	S	9Ul        ['        S
XX40 UD6nUR(                  (       a>  UR(                   H.  n
[+        U R,                  U
R.                  U
R0                  5        M0     [+        U R,                  XR0                  5        U(       a%  U R2                  " X40 UD6nU V
s/ s H  oPM     nn
O/ nU(       a(  UR5                  SU5        UR                  5       nXl        U(       d$   [7        U R2                  " X4SS0UD65      Ul        U(       d  UR<                    U$ s  sn
f ! [:         a     N&f = f)z9Send a given PreparedRequest.

:rtype: requests.Response
rd   rf   rg   rh   z#You can only send PreparedRequests.ri   T)rj   )secondsr8   r   r   )r   rd   rf   rg   r%   rh   r   r*   r   
ValueErrorr   r9   r   get_adapterrj   preferred_clockr   r   elapsedr   rm   r   r   r   rp   r   insertnext_nextStopIterationrn   )rH   r   r   ri   rd   r   adapterstartrr   rI   genrm   s                r5   r   Session.sendf  s    	(DKK0(DKK0&$)),F" /t~~!F9 gw''BCC !**%6=H% ""w{{"3  ! LL+F+ "#e+g.	 *e9&9 99 		&t||T\\488L " 	t||Wee< ((>v>C(+,tG,GG NN1a AI t55a`QU`Y_`a II- -  ! s   8H7?#H< <
I	I	c                    U R                   (       a  Ub  UR                  S5      OSn[        XS9nUR                  5        H  u  pUR	                  X5        M     USL d  UcE  [
        R                  R                  S5      =(       d    [
        R                  R                  S5      n[        X R                  5      n[        X0R                  5      n[        X@R                  5      n[        XPR                  5      nXBUUS.$ )zF
Check the environment and merge it with some settings.

:rtype: dict
Nno_proxy)r  TREQUESTS_CA_BUNDLECURL_CA_BUNDLE)rf   rh   rd   rg   )r   r9   r    r,   r   osenvironr6   rh   rd   rf   rg   )
rH   rj   rh   rd   rf   rg   r  env_proxiesr1   r2   s
             r5   r   "Session.merge_environment_settings  s     >>292Ew{{:.4H-cEK%++-""1( .
 ~**..)=> ;**..)9:   6v{{3v{{3T99-  	r=   c                     U R                   R                  5        H;  u  p#UR                  5       R                  UR                  5       5      (       d  M9  Us  $    [	        SR                  U5      5      e)zf
Returns the appropriate connection adapter for the given URL.

:rtype: requests.adapters.BaseAdapter
z*No connection adapters were found for {!r})r   r,   lowerrv   r   rt   )rH   rj   prefixr   s       r5   r   Session.get_adapter  sZ     "&!4!4!6Vyy{%%flln55 "7 HOOPSTUUr=   c                 f    U R                   R                  5        H  nUR                  5         M     g)z+Closes all adapters and as such the sessionN)r   valuesru   )rH   r2   s     r5   ru   Session.close  s"    %%'AGGI (r=   c                     X R                   U'   U R                    Vs/ s H  n[        U5      [        U5      :  d  M  UPM!     nnU H+  nU R                   R                  U5      U R                   U'   M-     gs  snf )zgRegisters a connection adapter to a prefix.

Adapters are sorted in descending order by prefix length.
N)r   rr   r   )rH   r  r   r1   keys_to_mover4   s         r5   r   Session.mount  sd    
 !(f#'==I=aCFS[4H=IC!%!2!23!7DMM#   Js
   A7A7c           	      \    U R                    Vs0 s H  o[        XS 5      _M     nnU$ s  snf r   )	__attrs__getattr)rH   attrstates      r5   __getstate__Session.__getstate__  s/    =A^^L^Twt400^L Ms   )c                 N    UR                  5        H  u  p#[        XU5        M     g r   )r,   setattr)rH   r  r  values       r5   __setstate__Session.__setstate__  s     ;;=KDD& )r=   )r   r   rg   r   rF   r   rs   r   rh   rd   r   rf   )NNNNNNNTNNNNNNr   r   )r   r   r   r   __doc__r  r   r   r   r   r   r9   r   r   r   r   r   r   r   r   r   ru   r   r  r  r   r   r=   r5   r   r   E  s    $I<-|&R GKCGBFJX	2	6	3I
=
?5L\:V
	8'r=   r   c                      [        5       $ )a>  
Returns a :class:`Session` for context-management.

.. deprecated:: 1.0.0

    This method has been deprecated since version 1.0.0 and is only kept for
    backwards compatibility. New code should use :class:`~requests.sessions.Session`
    to create a session. This may be removed at a future date.

:rtype: Session
)r   r   r=   r5   sessionr#    s     9r=   )@r!  r  systimedatetimer   collectionsr   r   r   compatr   r   r	   r
   r   r   r   r   r   r   modelsr   r   r   r   r   r   _internal_utilsr   utilsr   r   r   
exceptionsr   r   r   r   
structuresr   r   r   r   r    r!   r"   r#   r$   r%   status_codesr&   r'   platformperf_counterr   AttributeErrorclockr6   r<   objectr?   r   r#  r   r=   r5   <module>r4     s    
 
   # ! A AS S D D / - B BQ Q , !  
   # <<7%++ iiO @K > :E Ca)6 a)Hp'" p'fW  %**%s   $C# #C87C8