
    fXfu                        d 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 dd
lmZmZmZmZ ddlmZmZmZmZ ddlmZmZ ddl 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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ej4        dk    rej5        Z6nej        Z6efdZ7efdZ8 G d d          Z9 G d de9          Z:d Z;dS )z
requests.sessions
~~~~~~~~~~~~~~~~~

This module provides a Session object to manage and persist settings across
requests (cookies, auth, proxies).
    N)OrderedDict)	timedelta   )to_native_string)HTTPAdapter)_basic_auth_str)Mapping	cookieliburljoinurlparse)RequestsCookieJarcookiejar_from_dictextract_cookies_to_jarmerge_cookies)ChunkedEncodingErrorContentDecodingErrorInvalidSchemaTooManyRedirects)default_hooksdispatch_hook)DEFAULT_REDIRECT_LIMITREDIRECT_STATIPreparedRequestRequest)codes)CaseInsensitiveDict)
DEFAULT_PORTSdefault_headersget_auth_from_urlget_environ_proxiesget_netrc_authrequote_uriresolve_proxiesrewind_bodyshould_bypass_proxiesto_key_val_listwin32c                 .   || S | |S t          |t                    rt          | t                    s| S  |t          |                    }|                    t          |                      d |                                D             }|D ]}||= |S )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`
    Nc                     g | ]	\  }}||
S N ).0kvs      V/var/www/html/Qu*py/bism/lib/python3.11/site-packages/pip/_vendor/requests/sessions.py
<listcomp>z!merge_setting.<locals>.<listcomp>T   s    EEEv119999    )
isinstancer	   r&   updateitems)request_settingsession_setting
dict_classmerged_setting	none_keyskeys         r/   merge_settingr;   =   s      	?G,,1;OW1U1U Z @ @AAN//::;;; FE!5!5!7!7EEEI    3r1   c                     ||                     d          g k    r| S | |                      d          g k    r|S t          | ||          S )zProperly merges both requests and session hooks.

    This is necessary because when request_hooks == {'response': []}, the
    merge breaks Session hooks entirely.
    Nresponse)getr;   )request_hookssession_hooksr7   s      r/   merge_hooksrA   [   s^      1 1* = = C C 1 1* = = C CzBBBr1   c                   @    e Zd Zd Zd Z	 	 	 	 	 	 d
dZd Zd Zd	 ZdS )SessionRedirectMixinc                 x    |j         r2|j        d         }|                    d          }t          |d          S dS )z7Receives a Response. Returns a redirect URI or ``None``locationlatin1utf8N)is_redirectheadersencoder   )selfresprE   s      r/   get_redirect_targetz(SessionRedirectMixin.get_redirect_targetk   sC      		6|J/H  x00H#Hf555tr1   c                 b   t          |          }t          |          }|j        |j        k    rdS |j        dk    r|j        dv r|j        dk    r|j        dv rdS |j        |j        k    }|j        |j        k    }t	          j        |j        d          df}|s|j        |v r|j        |v rdS |p|S )zFDecide whether Authorization header should be removed when redirectingThttp)P   Nhttps)i  NFN)r   hostnameschemeportr   r>   )rK   old_urlnew_url
old_parsed
new_parsedchanged_portchanged_schemedefault_ports           r/   should_strip_authz&SessionRedirectMixin.should_strip_auth   s    g&&
g&&
*"5554 '':--!W,,;..5 "*/9#*j.??%)**;TBBDI	<//<//5 -~-r1   FNTc	           
   +     K   g }
|                      |          }t          |j                  j        }|r'|                                }|
                    |           |
dd         |_        	 |j         n8# t          t          t          f$ r |j                            d           Y nw xY wt          |j                  | j        k    rt          d| j         d|          |                                 |                    d          r=t          |j                  }d	                    t'          |j                  |g          }t          |          }|j        d
k    r|r|                    |          }n|j        r|j        }|                                }|j        s#t1          |j        t3          |                    }nt3          |          }t'          |          |_        |                     ||           |j        t8          j        t8          j        fvr)d}|D ]}|j                             |d           d|_!        |j        }|                     dd           tE          |j#        ||j                   tI          |j#        | j%                   |&                    |j#                   | '                    ||          }| (                    ||           |j)        duod|v pd|v }|rtU          |           |}|r|V  nI | j+        |f|||||dd|	}tE          | j%        ||j                   |                      |          }|V  |%dS dS )zBReceives a Response. Returns a generator of Responses or Requests.r   NF)decode_contentz	Exceeded z redirects.)r=   z//: )fragment)Content-LengthzContent-TypeTransfer-EncodingCookierb   rc   )streamtimeoutverifycertproxiesallow_redirects),rM   r   urlra   copyappendhistorycontentr   r   RuntimeErrorrawreadlenmax_redirectsr   close
startswithjoinr   rS   _replacegeturlnetlocr   r"   rebuild_methodstatus_coder   temporary_redirectpermanent_redirectrI   popbodyr   _cookiesr   cookiesprepare_cookiesrebuild_proxiesrebuild_auth_body_positionr$   send)rK   rL   reqre   rf   rg   rh   ri   yield_requestsadapter_kwargshistrk   previous_fragmentprepared_requestparsed_rurlparsedpurged_headersheaderrI   
rewindables                       r/   resolve_redirectsz&SessionRedirectMixin.resolve_redirects   s      &&t,,$SW--6 h	"xxzz KK8DL4(*>M 4 4 4U333334 4<  D$666&? 2???$   
 JJLLL ~~d## L&tx00hh 01C D DcJKK c]]F"$$):$2CDD 4$*O!--//C
 = 'dhC(8(899!#&&#3C#8#8  0$777 (((  
 "Y, ? ?F$,00>>>>(, %&.GKK$'''
 ##3#<c48LLL*3T\BBB,,-=-FGGG **+;WEEG.555
 *8D  G+M/Bg/M 
  .,--- #C 				 !ty	!#!#$)	 	 %	 	 't|5EtxPPP ..t44


Q  h	 h	 h	 h	 h	s   /A7 72B,+B,c                     |j         }|j        }d|v r#|                     |j        j        |          r|d= | j        rt          |          nd}||                    |           dS dS )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)rI   rk   r\   request	trust_envr!   prepare_auth)rK   r   r=   rI   rk   new_auths         r/   r   z!SessionRedirectMixin.rebuild_auth  s    
 #*"g%%$*@*@ #+
 +
%
 ( +/.B>#&&&d))(33333  r1   c                    |j         }t          |j                  j        }t	          ||| j                  }d|v r|d= 	 t          ||                   \  }}n# t          $ r d\  }}Y nw xY w|r|rt          ||          |d<   |S )a  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)	rI   r   rk   rS   r#   r   r   KeyErrorr   )rK   r   ri   rI   rS   new_proxiesusernamepasswords           r/   r   z$SessionRedirectMixin.rebuild_proxies/  s     #**.//6%&6PP G++-.	,!2;v3F!G!GHhh 	, 	, 	,!+Hhhh	,  	Q 	Q-<Xx-P-PG)*s   A A*)A*c                     |j         }|j        t          j        k    r|dk    rd}|j        t          j        k    r|dk    rd}|j        t          j        k    r|dk    rd}||_         dS )zWhen 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)rK   r   r=   r   s       r/   r{   z#SessionRedirectMixin.rebuild_methodL  s~     "( 5?22v7G7GF 5;..6V3C3CF 5;..6V3C3CF"(r1   )FNTNNF)	__name__
__module____qualname__rM   r\   r   r   r   r{   r+   r1   r/   rC   rC   j   s          (. . .H z z z zx4 4 4(  :) ) ) ) )r1   rC   c                       e Zd ZdZg dZd Zd Zd Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Z	d
 Z
d Zd ZddZddZddZd Zd Zd Zd Zd Zd Zd Zd ZdS )Sessiona  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]>
    )rI   r   authri   hooksparamsrg   rh   adaptersre   r   rt   c                    t                      | _        d | _        i | _        t	                      | _        i | _        d| _        d| _        d | _	        t          | _        d| _        t          i           | _        t                      | _        |                     dt%                                 |                     dt%                                 d S )NFTzhttps://zhttp://)r   rI   r   ri   r   r   r   re   rg   rh   r   rt   r   r   r   r   r   mountr   rK   s    r/   __init__zSession.__init__  s    
 '(( 	
  #__

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

:{}}---

9kmm,,,,,r1   c                     | S r*   r+   r   s    r/   	__enter__zSession.__enter__  s    r1   c                 .    |                                   d S r*   )ru   )rK   argss     r/   __exit__zSession.__exit__  s    

r1   c                    |j         pi }t          |t          j                  st	          |          }t          t          t                      | j                   |          }|j        }| j        r|s| j        st          |j
                  }t                      }|                    |j                                        |j
        |j        |j        |j        t%          |j        | j        t(                    t%          |j        | j                  t%          || j                  |t-          |j        | j                  
  
         |S )a  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
        )r7   )
r   rk   filesdatajsonrI   r   r   r   r   )r   r2   r
   	CookieJarr   r   r   r   r   r!   rk   r   preparer   upperr   r   r   r;   rI   r   r   rA   r   )rK   r   r   merged_cookiesr   ps         r/   prepare_requestzSession.prepare_request  s5    /'R '9#677 	3)'22G '+--t|<<g
 

 |> 	/$ 	/ty 	/!'+..D			>''))-!:M   !==tTY//"gmTZ88 	 	
 	
 	
 r1   NTc                 "   t          |                                ||||pi ||pi |||
  
        }|                     |          }|pi }|                     |j        ||||          }|	|
d}|                    |            | j        |fi |}|S )aw	  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   rk   rI   r   r   r   r   r   r   r   )rf   rj   )r   r   r   merge_environment_settingsrk   r3   r   )rK   r   rk   r   r   rI   r   r   r   rf   rj   ri   r   re   rg   rh   r   r   prepsettingssend_kwargsrL   s                         r/   r   zSession.request  s    z <<>><R
 
 
 ##C((-R22Hgvvt
 
 .
 
 	8$$$ty----r1   c                 L    |                     dd            | j        d|fi |S )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
        rj   Tr   
setdefaultr   rK   rk   kwargss      r/   r>   zSession.getO  s7     	+T222t|E311&111r1   c                 L    |                     dd            | j        d|fi |S )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
        rj   TOPTIONSr   r   s      r/   optionszSession.optionsZ  s7     	+T222t|Is55f555r1   c                 L    |                     dd            | j        d|fi |S )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
        rj   Fr   r   r   s      r/   headzSession.heade  s7     	+U333t|FC226222r1   c                 &     | j         d|f||d|S )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   )rK   rk   r   r   r   s        r/   postzSession.postp  s'     t|FCHdHHHHHr1   c                 $     | j         d|fd|i|S )au  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   rK   rk   r   r   s       r/   putzSession.put}  s%     t|E3<<T<V<<<r1   c                 $     | j         d|fd|i|S )aw  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       r/   patchzSession.patch  s%     t|GS>>t>v>>>r1   c                       | j         d|fi |S )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      r/   deletezSession.delete  s      t|Hc44V444r1   c                 .   |                     d| j                   |                     d| j                   |                     d| j                   d|vrt	          || j        | j                  |d<   t          |t                    rt          d          |
                    dd          }|                    d          }|j        }|                     |j                  }t                      } |j        |fi |}t                      |z
  }	t#          |		          |_        t'          d
||fi |}|j        r*|j        D ]"}
t+          | j        |
j        |
j                   #t+          | j        ||j                   |r | j        ||fi |}d |D             }ng }|r1|                    d|           |
                                }||_        |s5	 t7           | j        ||fddi|          |_        n# t:          $ r Y nw xY w|s|j         |S )zISend a given PreparedRequest.

        :rtype: requests.Response
        re   rg   rh   ri   z#You can only send PreparedRequests.rj   T)rk   )secondsr=   c                     g | ]}|S r+   r+   )r,   rL   s     r/   r0   z Session.send.<locals>.<listcomp>  s    ,,,t,,,r1   r   r   )r   re   rg   rh   r#   ri   r   r2   r   
ValueErrorr   r>   r   get_adapterrk   preferred_clockr   r   elapsedr   rn   r   r   r   rq   r   insertnext_nextStopIterationro   )rK   r   r   rj   re   r   adapterstartrr   rL   genrn   s                r/   r   zSession.send  s    	(DK000(DK000&$),,,F"" /t~ V VF9 gw'' 	DBCCC !**%6==H%% ""w{"33  !! GL++F++ "##e+g...	 *eQ99&99 9 	M 	 M M&t|T\48LLLLt|Wae<<<  	($(G>>v>>C,,,,,GGG  	 NN1a   AAI  	*D*1gUUdUfUU  !     	IIs   #G< <
H	H	c                    | j         r||                    d          nd}t          ||          }|                                D ]\  }}	|                    ||	           |du s|@t
          j                            d          p t
          j                            d          p|}t          || j                  }t          || j	                  }t          || j
                  }t          || j                  }||||dS )z^
        Check the environment and merge it with some settings.

        :rtype: dict
        Nno_proxy)r   TREQUESTS_CA_BUNDLECURL_CA_BUNDLE)ri   re   rg   rh   )r   r>   r    r4   r   osenvironr;   ri   re   rg   rh   )
rK   rk   ri   re   rg   rh   r   env_proxiesr-   r.   s
             r/   r   z"Session.merge_environment_settings  s    > 	292Ew{{:...4H-cHEEEK%++-- ) )A""1a(((( ~~JNN#788 z~~&677   66vt{33vt{33T49--"fPTUUUr1   c                     | j                                         D ]B\  }}|                                                    |                                          r|c S Ct	          d|          )z~
        Returns the appropriate connection adapter for the given URL.

        :rtype: requests.adapters.BaseAdapter
        z&No connection adapters were found for )r   r4   lowerrv   r   )rK   rk   prefixr   s       r/   r   zSession.get_adapter  ss     "&!4!4!6!6 	 	VWyy{{%%fllnn55  LSLLMMMr1   c                 f    | j                                         D ]}|                                 dS )z+Closes all adapters and as such the sessionN)r   valuesru   )rK   r.   s     r/   ru   zSession.close  s8    %%'' 	 	AGGIIII	 	r1   c                     || j         <   fd| j         D             }|D ]$}| j                             |          | j         |<   %dS )zwRegisters a connection adapter to a prefix.

        Adapters are sorted in descending order by prefix length.
        c                 T    g | ]$}t          |          t                    k     "|%S r+   )rs   )r,   r-   r   s     r/   r0   z!Session.mount.<locals>.<listcomp>%  s/    IIIaCFFS[[4H4H4H4H4Hr1   N)r   r   )rK   r   r   keys_to_mover:   s    `   r/   r   zSession.mount  sd    
 !(fIIII4=III 	8 	8C!%!2!23!7!7DM#	8 	8r1   c                 .      fd j         D             }|S )Nc                 4    i | ]}|t          |d           S r*   )getattr)r,   attrrK   s     r/   
<dictcomp>z(Session.__getstate__.<locals>.<dictcomp>+  s'    LLLTwtT400LLLr1   )	__attrs__)rK   states   ` r/   __getstate__zSession.__getstate__*  s#    LLLLT^LLLr1   c                 \    |                                 D ]\  }}t          | ||           d S r*   )r4   setattr)rK   r  r  values       r/   __setstate__zSession.__setstate__.  s<     ;;== 	' 	'KD%D$&&&&	' 	'r1   )NNNNNNNTNNNNNNr   r*   )r   r   r   __doc__r  r   r   r   r   r   r>   r   r   r   r   r   r   r   r   r   ru   r   r  r	  r+   r1   r/   r   r   c  s        $  I<- <- <-|    ) ) )^ #Y Y Y Yv	2 	2 	2	6 	6 	6	3 	3 	3I I I I
= 
= 
= 
=
? 
? 
? 
?5 5 5L L L\V V V>N N N  
	8 	8 	8  ' ' ' ' 'r1   r   c                      t                      S )aZ  
    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+   r1   r/   sessionr  3  s     99r1   )<r
  r   systimecollectionsr   datetimer   _internal_utilsr   r   r   r   r   compatr	   r
   r   r   r   r   r   r   r   
exceptionsr   r   r   r   r   r   r   modelsr   r   r   r   status_codesr   
structuresr   utilsr   r   r   r    r!   r"   r#   r$   r%   r&   platformperf_counterr   r;   rA   rC   r   r  r+   r1   r/   <module>r     s    
			 



  # # # # # #       - - - - - - ! ! ! ! ! ! ! ! ! ! ! ! 9 9 9 9 9 9 9 9 9 9 9 9                       0 / / / / / / /                   + + + + + +                        <7'OOiO @K    < :E C C C Cv) v) v) v) v) v) v) v)rM' M' M' M' M'" M' M' M'`    r1   