8fwdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZmZmZdd lmZmZmZmZdd lmZmZmZmZdd lmZmZdd l m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3ej4dkrej5Z6nejZ6efdZ7efdZ8GddZ9Gdde9Z:dZ;dS)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 cookieliburljoinurlparse)RequestsCookieJarcookiejar_from_dictextract_cookies_to_jar merge_cookies)ChunkedEncodingErrorContentDecodingError InvalidSchemaTooManyRedirects) default_hooks dispatch_hook)DEFAULT_REDIRECT_LIMITREDIRECT_STATIPreparedRequestRequest)codes)CaseInsensitiveDict) DEFAULT_PORTSdefault_headersget_auth_from_urlget_environ_proxiesget_netrc_auth requote_uriresolve_proxies rewind_bodyshould_bypass_proxiesto_key_val_listwin32c.||S||St|trt|ts|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` Ncg|] \}}|| SN).0kvs }/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/requests/sessions.py z!merge_setting..TsEEEv119999) isinstancer r&updateitems)request_settingsession_setting dict_classmerged_setting none_keyskeys r/ merge_settingr;=s  ?G,,1;OW1U1UZ @ @AAN//::;;;FE!5!5!7!7EEEI   3   r1c||dgkr|S||dgkr|St|||S)zProperly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. Nresponse)getr;) request_hooks session_hooksr7s r/ merge_hooksrA[s^  1 1* = = C C 1 1* = = C C  z B BBr1c@eZdZdZdZ d dZdZdZd ZdS) SessionRedirectMixincx|jr2|jd}|d}t|dSdS)z7Receives a Response. Returns a redirect URI or ``None``locationlatin1utf8N) is_redirectheadersencoder)selfresprEs r/get_redirect_targetz(SessionRedirectMixin.get_redirect_targetksC   6|J/H x00H#Hf55 5tr1cbt|}t|}|j|jkrdS|jdkr|jdvr|jdkr |jdvrdS|j|jk}|j|jk}t j|jddf}|s|j|vr |j|vrdS|p|S)zFDecide whether Authorization header should be removed when redirectingThttp)PNhttps)iNFN)r hostnameschemeportrr>)rKold_urlnew_url old_parsed new_parsed changed_portchanged_scheme default_ports r/should_strip_authz&SessionRedirectMixin.should_strip_authsg&& g&&  *"5 5 54   ' ':--!W,,;..5"*/9 #*j.??%)**;TBBDI  <//<//5-~-r1FNTc +Kg} ||} t|jj} | r'|} | || dd|_ |jn8#tttf$r|j dYnwxYwt|j|jkrtd|jd||| dr=t|j}d t'|j| g} t| }|jd kr| r|| }n|jr|j} |} |js#t1|jt3| } nt3| } t'| | _|| ||jt8jt8jfvr)d }|D]}| j |dd| _!| j}| d dtE| j#||j tI| j#|j%| &| j#|'| |}|(| || j)duod|vpd|v}|rtU| | }|r|VnI|j+|f|||||dd| }tE|j%| |j ||} |V| %dSdS)zBReceives a Response. Returns a generator of Responses or Requests.rNF)decode_contentz Exceeded z redirects.)r=z//:)fragment)Content-Lengthz Content-TypeTransfer-EncodingCookierbrc)streamtimeoutverifycertproxiesallow_redirects),rMr urlracopyappendhistorycontentrr RuntimeErrorrawreadlen max_redirectsrclose startswithjoinrrS_replacegeturlnetlocr r"rebuild_method status_codertemporary_redirectpermanent_redirectrIpopbodyr_cookiesrcookiesprepare_cookiesrebuild_proxies rebuild_auth_body_positionr$send)rKrLreqrerfrgrhriyield_requestsadapter_kwargshistrkprevious_fragmentprepared_request parsed_rurlparsedpurged_headersheaderrI rewindables r/resolve_redirectsz&SessionRedirectMixin.resolve_redirectss&&t,,$SW--6g "xxzz  KK   8DL 4 (*> M 4 4 4 U 33333 44<  D$666&? 2???$ JJLLL~~d## L&tx00 hh 01C D DcJKKc]]F"$$):$2CDD 4$*O!--//C = 'dh C(8(899!#&&#3C#8#8     0$ 7 7 7((( "Y,??F$,00>>>>(, %&.G KK$ ' ' ' ##3##&&&d    ) )( 3 3 3 3 3 r1c6|j}t|jj}t |||j}d|vr|d= t ||\}}n#t$rd\}}YnwxYw|ds|r|rt|||d<|S)aThis 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 zProxy-AuthorizationNNrQ) rIr rkrSr#rrKeyErrorrvr)rKrrirIrS new_proxiesusernamepasswords r/rz$SessionRedirectMixin.rebuild_proxies.s#**.//6%&6PP G + +-. ,!2;v3F!G!G Hhh , , ,!+ Hhhh ,   )) Qh Q8 Q-)))))r1rCceZdZdZgdZdZdZdZdZ dd Z d Z d Z d Z dd Z ddZddZdZdZdZdZdZdZdZdZdS)SessionaA Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('https://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: ... s.get('https://httpbin.org/get') ) rIrauthrihooksparamsrgrhadaptersrerrtct|_d|_i|_t |_i|_d|_d|_d|_ t|_ d|_ ti|_t|_|dt%|dt%dS)NFTzhttps://zhttp://)rrIrrirrrrergrhrrtrrrrrmountrrKs r/__init__zSession.__init__s'((   #__     4 +2.. $   :{}}--- 9kmm,,,,,r1c|Sr*r+rs r/ __enter__zSession.__enter__s r1c.|dSr*)ru)rKargss r/__exit__zSession.__exit__s r1c|jpi}t|tjst |}t t t |j|}|j}|jr|s|jst|j }t}| |j |j |j|j|jt%|j|jt(t%|j|jt%||j|t-|j|j |S)aConstructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest )r7) rrkfilesdatajsonrIrrrr)rr2r CookieJarrrr rrr!rkrpreparerupperrrrr;rIrrrAr)rKrrmerged_cookiesrps r/prepare_requestzSession.prepare_requests5/'R'9#677 3)'22G' +--t| <  /$ /ty /!'+..D    >'')) -!:M!==tTY//"gmTZ88  r1NTc "t|||||pi||pi|||  }||}| pi} ||j| | ||}| | d}|||j|fi|}|S)a Constructs a :class:`Request `, prepares it and sends it. Returns :class:`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) ` 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 hooks: (optional) Dictionary mapping hook name to one event or list of events, event must be callable. :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 ) rrkrIrrrrrrr)rfrj)rrrmerge_environment_settingsrkr3r)rKrrkrrrIrrrrfrjrirrergrhrrprepsettings send_kwargsrLs r/rzSession.requests~<<>>z Session.getQs7 +T222t|E311&111r1c L|dd|jd|fi|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 rjTOPTIONSrrs r/optionszSession.options\s7 +T222t|Is55f555r1c L|dd|jd|fi|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 rjFrrrs r/headz Session.headgs7 +U333t|FC226222r1c &|jd|f||d|S)aSends 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)rrr)rKrkrrrs r/postz Session.postrs't|FCHdHHHHHr1c $|jd|fd|i|S)auSends 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 PUTrrrKrkrrs r/putz Session.puts%t|E3<>t>v>>>r1c |jd|fi|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 DELETErrs r/deletezSession.deletes t|Hc44V444r1c .|d|j|d|j|d|jd|vrt ||j|j|d<t|trtd| dd}| d}|j }| |j}t}|j|fi|}t|z } t#| |_t'd ||fi|}|jr*|jD]"} t+|j| j| j#t+|j||j|r|j||fi|} d | D} ng} | r1| d || }| |_|s5 t7|j||fd di||_n#t:$rYnwxYw|s|j|S)zISend a given PreparedRequest. :rtype: requests.Response rergrhriz#You can only send PreparedRequests.rjT)rk)secondsr=cg|]}|Sr+r+)r,rLs r/r0z Session.send..s,,,t,,,r1rr)rrergrhr#rirr2r ValueErrorrr>r get_adapterrkpreferred_clockrrelapsedrrnrrrrqrinsertnext_next StopIterationro) rKrrrjreradapterstartrrrLgenrns r/rz Session.sends (DK000(DK000&$),,, F " " /t~ V VF9  gw ' ' DBCC C!**%6==H%% ""w{"33 !! GL + +F + +"##e+g...  *eQ 9 9& 9 9 9 M  M M&t|T\48LLLLt|Wae<<<  ($(G>>v>>C,,,,,GGG  NN1a  AAI  *D*1gUUdUfUU!      IIs#G<< H H c|jr||dnd}t||}|D]\}} ||| |dus|@t jdp t jdp|}t||j}t||j }t||j }t||j }||||dS)z^ Check the environment and merge it with some settings. :rtype: dict Nno_proxy)rTREQUESTS_CA_BUNDLECURL_CA_BUNDLE)rirergrh) rr>r r4rosenvironr;rirergrh) rKrkrirergrhr env_proxiesr-r.s r/rz"Session.merge_environment_settingss > 292Ew{{:...4H-cHEEEK#))++ ) )1""1a((((~~JNN#788z~~&677 66vt{33vt{33T49--"fPTUUUr1c|jD]B\}}||r|cSCt d|)z~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter z&No connection adapters were found for )rr4lowerrvr)rKrkprefixrs r/rzSession.get_adapter sr $}2244  OFGyy{{%%fllnn55  LSLLMMMr1cf|jD]}|dS)z+Closes all adapters and as such the sessionN)rvaluesru)rKr.s r/ruz Session.closes8%%''  A GGIIII  r1c||j<fd|jD}|D]$}|j||j|<%dS)zwRegisters a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. cTg|]$}t|tk"|%Sr+)rs)r,r-rs r/r0z!Session.mount..%s/IIIaCFFS[[4H4H4H4H4Hr1N)rr)rKrr keys_to_mover:s ` r/rz Session.mountsd !( fIIII4=III  8 8C!%!2!23!7!7DM#   8 8r1c.fdjD}|S)Nc4i|]}|t|dSr*)getattr)r,attrrKs r/ z(Session.__getstate__..+s'LLLTwtT400LLLr1) __attrs__)rKstates` r/ __getstate__zSession.__getstate__*s#LLLLT^LLL r1c\|D]\}}t|||dSr*)r4setattr)rKrrvalues r/ __setstate__zSession.__setstate__.s< ;;== ' 'KD% D$ & & & & ' 'r1)NNNNNNNTNNNNNNrr*)rrr__doc__rrrrrrr>rrrrrrrrrrurrr r+r1r/rrds$   I;-;-;-z)))^    #[[[[z 2 2 2 6 6 6 3 3 3 I I I I = = = = ? ? ? ?555KKKZVVV> N N N 8 8 8'''''r1rctS)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 )rr+r1r/sessionr 3s 99r1)rs ######------!!!!!!!!!!!!999999999999  0///////  ++++++                        <7'OOiO@K<:E C C C Cw)w)w)w)w)w)w)w)tL'L'L'L'L'"L'L'L'^     r1