kfG$dZddlZddlZddlZddlmZddlmZmZm Z m Z m Z  ddl Z n#e $rddlZ YnwxYwGddeZGdd eZd Zd Zdd ZGd deZGddeje ZdZdZdZddZdZdS)z requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. N)to_native_string) cookieliburlparse urlunparseMorselMutableMappingceZdZdZdZdZdZdZdZdZ dZ dd Z d Z d Z d ZedZedZedZd S) MockRequestaWraps a `requests.Request` to mimic a `urllib2.Request`. The code in `cookielib.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. ch||_i|_t|jjj|_dSN)_r _new_headersrurlschemetype)selfrequests p/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/requests/cookies.py__init__zMockRequest.__init__%s+TW[))0 c|jSr )rrs rget_typezMockRequest.get_type*s yrc>t|jjjSr )rrrnetlocrs rget_hostzMockRequest.get_host-s $$++rc*|Sr rrs rget_origin_req_hostzMockRequest.get_origin_req_host0s}}rc(|jjds |jjSt |jjdd}t |jj}t |j||j|j |j |j gS)NHostzutf-8)encoding) rheadersgetrrrrrpathparamsqueryfragment)rhostparseds r get_full_urlzMockRequest.get_full_url3sw""6** 7;  7'JJJ$'+&& M4fmV\ O    rcdSNTrs ris_unverifiablezMockRequest.is_unverifiableAstrc0||jjvp||jvSr )rr$rrnames r has_headerzMockRequest.has_headerDstw&C$$2C*CCrNct|jj||j||Sr )rr$r%r)rr3defaults r get_headerzMockRequest.get_headerGs/w""4):)>)>tW)M)MNNNrc td)zMcookielib has no legitimate use for this method; add it back if you find one.z=Cookie headers should be added with add_unredirected_header())NotImplementedError)rkeyvals r add_headerzMockRequest.add_headerJs!"abbbrc||j|<dSr rrr3values radd_unredirected_headerz#MockRequest.add_unredirected_headerNs"'$rc|jSr r>rs rget_new_headerszMockRequest.get_new_headersQs   rc*|Sr )r0rs r unverifiablezMockRequest.unverifiableTs##%%%rc*|Sr )r rs rorigin_req_hostzMockRequest.origin_req_hostXs'')))rc*|Sr rrs rr*zMockRequest.host\s}}rr )__name__ __module__ __qualname____doc__rrrr r,r0r4r7r<rArCpropertyrErGr*r/rrr r s#  111 ,,,    DDDOOOOccc(((!!!&&X&**X*Xrr c$eZdZdZdZdZdZdS) MockResponsezWraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`. ...what? Basically, expose the parsed HTTP headers from the server response the way `cookielib` expects to see them. c||_dS)zMake a MockResponse for `cookielib` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers N_headers)rr$s rrzMockResponse.__init__hs   rc|jSr rQrs rinfozMockResponse.infoos }rc:|j|dSr )rR getheadersr2s rrVzMockResponse.getheadersrs   &&&&&rN)rIrJrKrLrrTrVr/rrrOrOasK    '''''rrOct|dr|jsdSt|}t|jj}|||dS)zExtract the cookies from the response into a CookieJar. :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar) :param request: our own requests.Request object :param response: urllib3.HTTPResponse object _original_responseN)hasattrrXr rOmsgextract_cookies)jarrresponsereqress rextract_cookies_to_jarr`vsc H2 3 3  ' g  C x26 7 7CS!!!!!rct|}|||dS)zj Produce an appropriate Cookie header string to be sent with `request`, or None. :rtype: str Cookie)r add_cookie_headerrCr%)r\rrs rget_cookie_headerresE GA!     " "8 , ,,rcg}|D]Q}|j|kr| ||jkr| ||jkr*||j|j|jfR|D]\}}}||||dS)zkUnsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). N)r3domainr&appendclear) cookiejarr3rgr& clearablescookies rremove_cookie_by_namerms JEE ;$     &FM"9"9    3 3 6=&+v{CDDDD(,,dd++++,,rceZdZdZdS)CookieConflictErrorzThere are two cookies that meet the criteria specified in the cookie jar. Use .get and .set and include domain and path args in order to be more specific. N)rIrJrKrLr/rrrorosrroceZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZddZfdZdZdZdZfdZfdZddZddZdZdZdZdZxZS)RequestsCookieJaraCompatibility class; is a cookielib.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n). NcV ||||S#t$r|cYSwxYw)zDict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. .. warning:: operation is O(n), not O(1). )_find_no_duplicatesKeyError)rr3r6rgr&s rr%zRequestsCookieJar.getsC ++D&$?? ?   NNN s  ((c |;t|||d|ddSt|trt |}nt ||fi|}|||S)zDict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Nrgr&)rgr&)rmr% isinstancermorsel_to_cookie create_cookie set_cookie)rr3r@kwargscs rsetzRequestsCookieJar.sets = !$VZZ5I5IPVPZPZ[aPbPb c c c c F eV $ $ 5 ''AAdE44V44A rc#@Kt|D] }|jV dS)zDict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). N)iterr3rrls riterkeyszRequestsCookieJar.iterkeyss8 4jj  F+      rcDt|S)zDict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). )listrrs rkeyszRequestsCookieJar.keyss DMMOO$$$rc#@Kt|D] }|jV dS)zDict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). N)r~r@rs r itervalueszRequestsCookieJar.itervaluess8 4jj  F,      rcDt|S)zDict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). )rrrs rvalueszRequestsCookieJar.valuess DOO%%&&&rc#NKt|D]}|j|jfVdS)zDict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). N)r~r3r@rs r iteritemszRequestsCookieJar.iteritemss? 4jj , ,F+v|+ + + + + , ,rcDt|S)zDict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs. .. seealso:: keys() and values(). )rrrs ritemszRequestsCookieJar.itemssDNN$$%%%rctg}t|D]%}|j|vr||j&|S)z2Utility method to list all the domains in the jar.r~rgrhrdomainsrls r list_domainszRequestsCookieJar.list_domainssC4jj . .F}G++v}---rctg}t|D]%}|j|vr||j&|S)z0Utility method to list all the paths in the jar.)r~r&rh)rpathsrls r list_pathszRequestsCookieJar.list_pathssC4jj * *F{%'' V[))) rcg}t|D]/}|j |j|vrdS||j0dS)zvReturns True if there are multiple domains in the jar. Returns False otherwise. :rtype: bool NTFrrs rmultiple_domainsz"RequestsCookieJar.multiple_domainssU 4jj * *F}(V]g-E-Ett NN6= ) ) ) )urci}t|D]+}| |j|kr| |j|kr|j||j<,|S)zTakes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements. :rtype: dict )r~rgr&r@r3)rrgr& dictionaryrls rget_dictzRequestsCookieJar.get_dict+sU 4jj 7 7F6=F#:#:!4!4*0, 6;'rcx tt||S#t$rYdSwxYwr.)superrq __contains__ro)rr3 __class__s rrzRequestsCookieJar.__contains__;sI *D11>>tDD D"   44 s '+ 99c,||S)zDict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1). )rsr2s r __getitem__zRequestsCookieJar.__getitem__As''---rc2|||dS)zDict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead. N)r|r?s r __setitem__zRequestsCookieJar.__setitem__Js urc&t||dS)zlDeletes a cookie given a name. Wraps ``cookielib.CookieJar``'s ``remove_cookie_by_name()``. N)rmr2s r __delitem__zRequestsCookieJar.__delitem__Qs dD)))))rct|jdrT|jdr:|jdr |jdd|_t t |j|g|Ri|S)N startswith"z\")rYr@rendswithreplacerrqry)rrlargsrzrs rryzRequestsCookieJar.set_cookieWs 6< . . ;6<3J3J33O3O ;TZT`TiTijmTnTn ;!<//r::FL8u&--8Q$QQQ&QQQrct|tjr.|D])}|t j|*dSt t ||dS)zAUpdates this jar with cookies from another CookieJar or dict-likeN)rvr CookieJarrycopyrrqupdate)rotherrlrs rrzRequestsCookieJar.update\sw eY0 1 1 9 3 3 & 1 12222 3 3 #T * * 1 1% 8 8 8 8 8rct|D]0}|j|kr#| |j|kr| |j|kr |jcS1t d|d|d|)aRequests uses this method internally to get cookie values. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :return: cookie.value Nname= , domain=, path=)r~r3rgr&r@rt)rr3rgr&rls r_findzRequestsCookieJar._finddsx4jj , ,F{d"">V]f%<%<|v{d':':%|+++hfffddKLLLrcd}t|D]B}|j|kr5| |j|kr(| |j|kr|t d|z|j}C|r|St d|d|d|)aBoth ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :raises KeyError: if cookie is not found :raises CookieConflictError: if there are multiple cookies that match name and optionally domain and path :return: cookie.value Nz(There are multiple cookies with name, %rrrr)r~r3rgr&ror@rt)rr3rgr&toReturnrls rrsz%RequestsCookieJar._find_no_duplicatesxs4jj 0 0F{d"">V]f%<%<|v{d':':#/"56`dh6i"j"jj#)<  OhfffddKLLLrcb|j}|d|S)4Unlike a normal CookieJar, this class is pickleable. _cookies_lock)__dict__rpoprstates r __getstate__zRequestsCookieJar.__getstate__s, ""$$ /""" rc|j|d|jvrtj|_dSdS)rrN)rr threadingRLockrrs r __setstate__zRequestsCookieJar.__setstate__sC U### $- / /!*!2!2D    0 /rct}|||||S)z(Return a copy of this RequestsCookieJar.)rq set_policy get_policyr)rnew_cjs rrzRequestsCookieJar.copysB"$$$//++,,, d rc|jS)z&Return the CookiePolicy instance used.)_policyrs rrzRequestsCookieJar.get_policys |r)NNNNN)rIrJrKrLr%r|rrrrrrrrrrrrrrryrrrsrrrr __classcell__)rs@rrqrqs"    "%%%''',,,&&&     ...*** RRRRR 99999MMMM(MMMM2333 rrqc|dSt|dr|Stj|}||D])}|tj|*|S)Nr)rYrriry)r\new_jarrls r_copy_cookie_jarrs{ {tsFxxzzinnG MMOOO..49V,,---- Nrc d||ddddddddddidd }t|t|z }|r!d }t|t|z||t |d |d <t |d |d <|d d|d<t |d|d<t jdi|S)zMake a cookie from underspecified parameters. By default, the pair of `name` and `value` will be set for the domain '' and sent on every request (this is sometimes called a "supercookie"). rNr/FTHttpOnly) versionr3r@portrgr&secureexpiresdiscardcomment comment_urlrestrfc2109z4create_cookie() got unexpected keyword arguments: %srport_specifiedrgdomain_specified.domain_initial_dotr&path_specifiedr/)r| TypeErrorrrboolrrrb)r3r@rzresultbadargserrs rrxrxsT"F &kkCKK'G-Dd7mm+,,, MM&#F6N33F !%fX&6!7!7F #)(#3#>#>s#C#CF  #F6N33F    % %f % %%rcd}|dr^ ttjt|dz}n]#t$rtd|dzwxYw|dr/d}t jtj|d|}t|dt|dd|d||j |d dd |d idt|d |j |d pd S)zBConvert a Morsel object into a Cookie containing the one k/v pair.Nzmax-agezmax-age: %s must be integerrz%a, %d-%b-%Y %H:%M:%S GMTrFrgr&rhttponlyrrr) rrrrgrr3r&rrrrr@r) inttime ValueErrorrcalendartimegmstrptimerxrr:r@)morselr time_templates rrwrws2G i   O$)++F9,=(>(>>??GG O O O9F9z'cookiejar_from_dict.. s>>>&&+>>>r)rqryrx) cookie_dictrj overwritenames_from_jarr3s rcookiejar_from_dictrs|%'' >>I>>> M MD MT77$$]4T9J%K%KLLL rc^t|tjstdt|trt ||d}n[t|tjrA ||n*#t$r|D]}||YnwxYw|S)zAdd cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. :rtype: CookieJar z!You can only merge into CookieJarF)rjr) rvrrrdictrrAttributeErrorry)rjcookies cookie_in_jars r merge_cookiesrs i!4 5 5><==='4  4' yE;;; GY0 1 14 4   W % % % % 4 4 4!( 4 4 $$]3333 4 4 4 s-B$B*)B*rr.)rLrrr_internal_utilsrcompatrrrrr r ImportErrordummy_threadingobjectr rOr`rerm RuntimeErrorrorrqrrxrwrrr/rrrs ------KKKKKKKKKKKKKK((((''''''(EEEEE&EEEP'''''6'''*""""---,,,,&, ||||| +^|||~   !&!&!&H>*s ) 55