kfudZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZddlmZmZmZmZdd lmZmZmZdd lmZmZdd lmZdd lmZm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddlm+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4dkr ej5Z6n#e7$r ej8Z6Yn wxYwejZ6efdZ9efdZ:Gdde;Z<Gdde<Z=dZ>dS)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) cookielibis_py3urljoinurlparseMapping)cookiejar_from_dictextract_cookies_to_jarRequestsCookieJar merge_cookies)RequestPreparedRequestDEFAULT_REDIRECT_LIMIT) default_hooks dispatch_hook)to_native_string)to_key_val_listdefault_headers DEFAULT_PORTS)TooManyRedirects InvalidSchemaChunkedEncodingErrorContentDecodingError)CaseInsensitiveDict) HTTPAdapter) requote_uriget_environ_proxiesget_netrc_authshould_bypass_proxiesget_auth_from_url rewind_body)codes)REDIRECT_STATIwin32c.||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 q/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/requests/sessions.py z!merge_setting..JsEEEv119999) isinstancer rupdateitems)request_settingsession_setting dict_classmerged_setting none_keyskeys r/ merge_settingr;2s   0 0  0 0Z @ @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_hooksrAQs^  1 1* = = C C 1 1* = = C C  z B BBr1c8eZdZdZdZ d dZdZdZd ZdS) SessionRedirectMixinc|jr9|jd}tr|d}t |dSdS)z7Receives a Response. Returns a redirect URI or ``None``locationlatin1utf8N) is_redirectheadersrencoder)selfresprEs r/get_redirect_targetz(SessionRedirectMixin.get_redirect_targetbsK   6|J/H 5#??844#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_authwsg&& g&&  *"5 5 54   ' 'JOz,I,I%00Z_ 5S5S5"*/9 #*j.??%)**;TBBDI  :?l#B#BO|335-~-r1FNTc +Kg} ||} t|jj} | r6|} | || dd|_ |jn8#tttf$r|j dYnwxYwt|j|jkr)td|j||| dr=t|j}dt)|j| g} t| }|jd kr| r|| }n|jr|j} |} |js#t3|jt5| } nt5| } t)| | _|| ||jt:jt:jfvr)d }|D]}| j !|dd| _"| j }|!d dtG| j$||j tK| j$|j&| '| j$|(| |}|)| || j*duod |vpd|v}|rtW| | }|r|VnI|j,|f|||||dd| }tG|j&| |j ||} |V| 4dSdS)zBReceives a Response. Returns a generator of Responses or Requests.rNF)decode_contentzExceeded {} redirects.)r=z//:)fragment)Content-Lengthz Content-TypeTransfer-EncodingCookierbrc)streamtimeoutverifycertproxiesallow_redirects)-rMr urlracopyappendhistorycontentrr RuntimeErrorrawreadlen max_redirectsrformatclose startswithjoinrrS_replacegeturlnetlocr rrebuild_method status_coder%temporary_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--6d "xxzz  KK   8DL 4 (*> M 4 4 4 U 33333 44<  D$666&'?'F'FtGY'Z'Zeijjjj JJLLL~~d## L&tx00 hh 01C D DcJKKc]]F"$$):$2CDD 4$*O!--//C = 'dh C(8(899!#&&#3C#8#8     0$ 7 7 7(@%BZ'[[[!X,??F$,00>>>>(, %&.G KK$ ' ' ' ##3##&&&d    ) )( 3 3 3 3 3 r1c||ni}|j}|j}t|j}|}|d}t ||}|jrT|sRt||} | || d} | r| || d|vr|d= t||\} } n#t$rd\} } YnwxYw| 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 Nno_proxyrallzProxy-AuthorizationNN) rIrkr rSrlr>r"rr setdefaultr#KeyErrorr) rKrrirIrkrS new_proxiesr bypass_proxyenviron_proxiesproxyusernamepasswords r/rz$SessionRedirectMixin.rebuild_proxiessM%0''b"*"#%llnn ;;z**,S8DDD > 6, 61#IIIO#''0C0CE0J0JKKE 6&&vu555 G + +-. ,!2;v3F!G!G Hhh , , ,!+ Hhhh ,  Q Q->> 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://)rrIrrirrrrergrhrrtrr rrrmountrrKs r/__init__zSession.__init__js '((   #__     4 +2.. $   :{}}--- 9kmm,,,,,r1c|Sr*r+rs r/ __enter__zSession.__enter__s r1c.|dSr*)rv)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 CookieJarr rrrrr!rkrpreparerupperrrrr;rIrrrAr)rKrrmerged_cookiesrps r/prepare_requestzSession.prepare_requests./'R'9#677 3)'22G' +--t| <  /$ /ty /!'+..D    >'')) -!'/4`, 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 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.get"s7 +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.head8s7 +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.postCs'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.putPs%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.deletehs t|Hc44V444r1c H|d|j|d|j|d|j|d|||jt |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 t5|j||fd di||_n#t8$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)rrergrhrrir2r ValueErrorrr>r get_adapterrkpreferred_clockrrelapsedrrnr rrrqrinsertnext_next StopIterationro) rKrrrjreradapterstartrrrLgenrns r/rz Session.sendrs (DK000(DK000&$),,,)T%9%9'4<%P%PQQQ 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  5t5a``QU`Y_``aa       IIs%#H HHc|jr||dnd}t||}|D]\}} ||| |dus|>t jdpt jd}t||j}t||j }t||j }t||j }||||dS)z^ Check the environment and merge it with some settings. :rtype: dict NrrTREQUESTS_CA_BUNDLECURL_CA_BUNDLE)rgrirerh) rr>r r4rosenvironr;rirergrh) rKrkrirergrhr env_proxiesr-r.s r/rz"Session.merge_environment_settingss > <292Ew{{:...4H-cHEEEK%++-- ) )A""1a((((~~*..)=>>;*..)9:: 66vt{33vt{33T49-- W r1c|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 {!r})rr4lowerrwrru)rKrkprefixrs r/rzSession.get_adaptersz "&!4!4!6!6   VWyy{{%%fllnn55  HOOPSTTUUUr1cf|jD]}|dS)z+Closes all adapters and as such the sessionN)rvaluesrv)rKr.s r/rvz 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)rKr rvalues r/ __setstate__zSession.__setstate__s< ;;== ' 'KD% D$ & & & & ' 'r1)NNNNNNNTNNNNNNrr*)rrr__doc__r rrrrrr>rrrrrrrrrrvrr rr+r1r/rrQs$I <-<-<-|&&&RGKCGBFJJJJX 2 2 2 6 6 6 3 3 3 I I I I = = = = ? ? ? ?555IIIV: V V V 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/sessionrs 99r1)?rrsystimedatetimer collectionsrrrcompatrrr r r rr r rrmodelsrrrrrr_internal_utilsrutilsrrr exceptionsrrrr structuresrrrrr r!r"r#r$ status_codesr%r&platform perf_counterrAttributeErrorclockr;rAobjectrCrrr+r1r/r#s& ######!!!!!!AAAAAAAAAAAAAASSSSSSSSSSSSDDDDDDDDDD////////------BBBBBBBBBBQQQQQQQQQQQQ,+++++!!!!!!  #"""""<7%+ %%%*%iO@K>:E C C C Cn)n)n)n)n)6n)n)n)bm'm'm'm'm'"m'm'm'`     sB%% B43B4