fwdZddlZddlZddlZddlmZddlmZddlm 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/m0Z0m1Z1m2Z2m3Z3ejhdk(r ejjZ6n ejZ6efdZ7efdZ8GddZ9Gdde9Z:dZ;y)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|}|jt||j Dcgc] \}}| | }}}|D]}||=|Scc}}w)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&updateitems)request_settingsession_setting dict_classmerged_settingkv none_keyskeys Z/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/requests/sessions.py merge_settingr5=s  ?G,OW1U @AN//:;"0!5!5!7Ev119EIE 3   Fs ) B4Bc|||jdgk(r|S||jdgk(r|St|||S)zProperly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. response)getr5) request_hooks session_hooksr.s r4 merge_hooksr;[sO  1 1* = C 1 1* = C  z BBc>eZdZdZdZ ddZdZdZdZy) SessionRedirectMixinct|jr,|jd}|jd}t|dSy)z7Receives a Response. Returns a redirect URI or ``None``locationlatin1utf8N) is_redirectheadersencoder)selfrespr@s r4get_redirect_targetz(SessionRedirectMixin.get_redirect_targetks;   ||J/H x0H#Hf5 5r<ct|}t|}|j|jk7ry|jdk(r,|jdvr|jdk(r|jdvry|j|jk7}|j|jk7}t j |jddf}|s|j|vr|j|vry|xs|S)zFDecide whether Authorization header should be removed when redirectingThttp)PNhttps)iNFN)r hostnameschemeportrr8)rFold_urlnew_url old_parsed new_parsed changed_portchanged_scheme default_ports r4should_strip_authz&SessionRedirectMixin.should_strip_authsg& g&   *"5"5 5    ':-!!W,;."*//9 #**j.?.??%))**;*;TBDI </</-~-r<Nc +Kg} |j|} t|jj} | r|j } | j || dd|_ |jt|j |jk\rtd|jd||j!| j#dr;t|j}d j%t'|j(| g} t| }|jd k(r| r|j+| }n|jr |j} |j-} |j.s t1|jt3| } n t3| } t'| | _|j5| ||j6t8j:t8j<fvr,d }|D]}| j>jA|d d| _!| j>}|jAd dtE| jF||jtI| jF|jJ| jM| jF|jO| |}|jQ| || jRduxr d|vxsd|v}|r tU| | }|r|nP|jV|f|||||dd| }tE|jJ| |j|j|} || ryy#tttf$r |jjdYwxYww)zBReceives a Response. Returns a generator of Responses or Requests.rNF)decode_contentz Exceeded z redirects.)r7z//:)fragment)Content-Lengthz Content-TypeTransfer-EncodingCookier]r^)streamtimeoutverifycertproxiesallow_redirects),rHr urlr\copyappendhistorycontentrr RuntimeErrorrawreadlen max_redirectsrclose startswithjoinrrN_replacegeturlnetlocr r"rebuild_method status_codertemporary_redirectpermanent_redirectrDpopbodyr_cookiesrcookiesprepare_cookiesrebuild_proxies rebuild_auth_body_positionr$send)rFrGreqr`rarbrcrdyield_requestsadapter_kwargshistrfprevious_fragmentprepared_request parsed_rurlparsedpurged_headersheaderrD rewindables r4resolve_redirectsz&SessionRedirectMixin.resolve_redirectss-&&t,$SWW-66"xxz  KK 8DL 4 4<< D$6$66& 2 23;?$ JJL~~d#&txx0 hh 01C1C DcJKc]F"$):2CD$*OO!--/C ==dhh C(89!#&#3C#8     0$ 7((((( "Y,F$,,00>-(, %&..G KK$ ' ##3#<# M 4 U 3 4s1A!M,$ L50KM,3M,50M)%M,(M))M,c|j}|j}d|vr)|j|jj|r|d=|jr t |nd}||j |yy)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)rDrfrWrequest trust_envr! prepare_auth)rFrr7rDrfnew_auths r4rz!SessionRedirectMixin.rebuild_authsw #**"" g %$*@*@    #+ (+/..>#&d    ) )( 3 r<c,|j}t|jj}t |||j }d|vr|d= t ||\}}|jds|r|rt|||d<|S#t$rd\}}Y6wxYw)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-AuthorizationNNrL) rDr rfrNr#rrKeyErrorrqr)rFrrdrDrN new_proxiesusernamepasswords r4rz$SessionRedirectMixin.rebuild_proxies.s#***../66%&6P G +-. ,!2;v3F!G Hh   )h8-r>js7(.H yv4(>)r<r>ceZdZdZgdZdZdZdZdZ ddZ d Z d Z d Z dd Z dd ZddZdZdZdZdZdZdZdZdZy)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') ) rDr}authrdhooksparamsrbrcadaptersr`rroc^t|_d|_i|_t |_i|_d|_d|_d|_ t|_ d|_ ti|_t|_|j#dt%|j#dt%y)NFTzhttps://zhttp://)rrDrrdrrrr`rbrcrrorrr}rrmountrrFs r4__init__zSession.__init__s'(   #_     4 +2. $   :{}- 9km,r<c|SNrrs r4 __enter__zSession.__enter__s r<c$|jyr)rp)rFargss r4__exit__zSession.__exit__s  r<c|jxsi}t|tjs t |}t t t |j|}|j}|jr#|s!|jst|j}t}|j|jj|j|j|j |j"t%|j&|j&t(t%|j*|j*t%||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 )r.) rrffilesdatajsonrDrrr}r)r}r)r CookieJarrrr rrr!rfrpreparerupperrrrr5rDrrr;r)rFrr}merged_cookiesrps r4prepare_requestzSession.prepare_requests//'R'9#6#67)'2G' +-t|| >$tyy!'++.D   >>'') --!:M!=tTYY/"gmmTZZ8  r<Nc t|j||||xsi||xsi|||  }|j|}| xsi} |j|j| | ||}| | d}|j ||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 ) rrfrDrrrrrr}r)rare)rrrmerge_environment_settingsrfr*r)rFrrfrrrDr}rrrarerdrr`rbrcrrprepsettings send_kwargsrGs r4rzSession.requests~<<>t>v>>r<c *|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 r4deletezSession.deletest||Hc4V44r<c f|jd|j|jd|j|jd|jd|vr$t ||j |j |d<t|tr td|jdd}|jd}|j}|j|j}t}|j |fi|}t|z } t#| |_t'd ||fi|}|j(r<|j(D]-} t+|j,| j.| j0/t+|j,||j0|r$|j2||fi|} | D cgc]} | } } ng} | r)| j5d || j}| |_|s% t7|j2||fd di||_|s |j<|Scc} w#t:$rY wxYw) zISend a given PreparedRequest. :rtype: requests.Response r`rbrcrdz#You can only send PreparedRequests.reT)rf)secondsr7rr)rr`rbrcr#rdrr)r ValueErrorrzr8r get_adapterrfpreferred_clockrrelapsedrrirr}rrlrinsertnext_next StopIterationrj) rFrrrer`radapterstartrrrGgenris r4rz Session.sends  (DKK0(DKK0&$)), F " /t~~ VF9  gw 'BC C!**%6=H% ""w{{"3 ! GLL +F +"#e+g.  *eQ 9& 9 99 &t||T\\488L" t||Waee< ($((G>v>C(+,t,G,G  NN1a  AAI *D**1gUdUfU  II1-$!  s/ H+$H$$ H0/H0c|jr||jdnd}t||}|jD]\}} |j || |dus|Dt j jdxs#t j jdxs|}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)rdr`rbrc) rr8r r+rosenvironr5rdr`rbrc) rFrfrdr`rbrcr env_proxiesr0r1s r4rz"Session.merge_environment_settingss >>292Ew{{:.4H-cHEK#))+1""1a(, ~JJNN#78zz~~&67 6vt{{3vt{{3T499-"fPTUUr<c|jjD]6\}}|jj|js4|cSt d|)z~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter z&No connection adapters were found for )rr+lowerrqr)rFrfprefixrs r4rzSession.get_adapter sS $}}224OFGyy{%%flln5 5 DSGLMMr<cb|jjD]}|jy)z+Closes all adapters and as such the sessionN)rvaluesrp)rFr1s r4rpz Session.closes"%%'A GGI(r<c||j|<|jDcgc]}t|t|ks|}}|D]*}|jj||j|<,ycc}w)zwRegisters a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. N)rrnrz)rFrrr0 keys_to_mover3s r4rz Session.mountse !( f#'==IaCFS[4HI IC!%!2!23!7DMM#  Js A1A1c Z|jDcic]}|t||d}}|Scc}wr) __attrs__getattr)rFattrstates r4 __getstate__zSession.__getstate__*s2=A^^LTwtT400LL Ms(cN|jD]\}}t|||yr)r+setattr)rFrrvalues r4 __setstate__zSession.__setstate__.s" ;;=KD% D$ &)r<)NNNNNNNTNNNNNNrr)rrr__doc__rrrrrrr8rrrrrrrrrrprrrrr<r4rrds$ I;-z)^    #[z 2 6 3 I = ?5KZV> N 8'r<rctS)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 )rrr<r4sessionr3s  9r<)rrrr<r4rs #-!!99  0  +   <<7''OiiO@K<:E Cw)w)tL'"L'^ r<