8fH dZddlZddlZddlZddlmZddlmZmZm Z m Z m Z  ddl Z n#e $rddlZ YnwxYwGddZGdd Zd Zd Zdd ZGd deZGdde jeZdZdZdZddZdZdS)z requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `http.cookiejar.CookieJar` with requests. requests.utils imports from here, so be careful with imports. N)to_native_string)MorselMutableMapping cookieliburlparse urlunparseceZdZdZdZdZdZdZdZdZ dZ dd Z d Z d Z d ZedZedZedZd S) MockRequestaWraps a `requests.Request` to mimic a `urllib2.Request`. The code in `http.cookiejar.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 |/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/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_host.s}}rc(|jjds |jjSt |jjdd}t |jj}t |j||j|j |j |j gS)NHostzutf-8)encoding) rheadersgetrrrr rpathparamsqueryfragment)rhostparseds r get_full_urlzMockRequest.get_full_url1sw""6** 7;  7'JJJ$'+&&         rcdSNTrs ris_unverifiablezMockRequest.is_unverifiableEstrc0||jjvp||jvSr )rr$rrnames r has_headerzMockRequest.has_headerHstw&C$$2C*CCrNct|jj||j||Sr )rr$r%r)rr3defaults r get_headerzMockRequest.get_headerKs/w""4):)>)>tW)M)MNNNrc td)zMcookiejar 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_headerNs! K   rc||j|<dSr rrr3values radd_unredirected_headerz#MockRequest.add_unredirected_headerTs"'$rc|jSr r>rs rget_new_headerszMockRequest.get_new_headersWs   rc*|Sr )r0rs r unverifiablezMockRequest.unverifiableZs##%%%rc*|Sr )r rs rorigin_req_hostzMockRequest.origin_req_host^s'')))rc*|Sr rrs rr*zMockRequest.hostbs}}rr )__name__ __module__ __qualname____doc__rrrr r,r0r4r7r<rArCpropertyrErGr*r/rrr r s   111 ,,,   (DDDOOOO   (((!!!&&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 `http.cookiejar` expects to see them. c||_dS)zMake a MockResponse for `cookiejar` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers N_headers)rr$s rrzMockResponse.__init__ns   rc|jSr rQrs rinfozMockResponse.infous }rc:|j|dSr )rR getheadersr2s rrVzMockResponse.getheadersxs   &&&&&rN)rIrJrKrLrrTrVr/rrrOrOgsK    '''''rrOct|dr|jsdSt|}t|jj}|||dS)zExtract the cookies from the response into a CookieJar. :param jar: http.cookiejar.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`|sb H2 3 38S 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 http.cookiejar.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 = !d6::h#7#7fjj>P>P     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.items sDNN$$%%%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_domains%sU 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_dict2sU 4jj 7 7F&-6"9"9  t 3 3*0, 6;'rcj t|S#t$rYdSwxYwr.)super __contains__ro)rr3 __class__s rrzRequestsCookieJar.__contains__AsB 77''-- -"   44 s $ 22c,||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__Gs''---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__Ps urc&t||dS)zqDeletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s ``remove_cookie_by_name()``. N)rmr2s r __delitem__zRequestsCookieJar.__delitem__Ws dD)))))rct|jdrT|jdr:|jdr |jdd|_t j|g|Ri|S)N startswith"z\")rYr@rendswithreplacerry)rrlargsrzrs rryzRequestsCookieJar.set_cookie]s FL, / / ; '',, ; %%c** ; "<//r::FL!uww!&:4:::6:::rct|tjr.|D])}|t j|*dSt |dS)zAUpdates this jar with cookies from another CookieJar or dict-likeN)rvr CookieJarrycopyrupdate)rotherrlrs rrzRequestsCookieJar.updatefsn eY0 1 1 " 3 3 & 1 12222 3 3 GGNN5 ! ! ! ! !rct|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._findns~4jj , ,F{d"">V]f%<%<|v{d':':%|+++ItIIIIIIJJJrcd}t|D]B}|j|kr5| |j|kr(| |j|kr|t d||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, rrr)r~r3rgr&ror@rt)rr3rgr&toReturnrls rrsz%RequestsCookieJar._find_no_duplicatess4jj 0 0F{d"">V]f%<%<|v{d':':#/"5 Q Q Q##$*<  OItIIIIIIJJJrcb|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"    &%%%''',,,&&&        ...*** ;;;;;"""""KKKK(KKKK:333 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 }|rtd t|||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_urlrestrfc2109z2create_cookie() got unexpected keyword arguments: rport_specifiedrgdomain_specified.domain_initial_dotr&path_specifiedr/)r| TypeErrorrrboolrrrb)r3r@rzresultbadargss rrxrxsT"F &kkCKK'G  Pg P P    MM&#F6N33F !%fX&6!7!7F #)(#3#>#>s#C#CF  #F6N33F    % %f % %%rcd}|dr_ ttjt|dz}n^#t$rtd|ddwxYw|dr/d}t jtj|d|}t|dt|dd|d ||j |d dd |d idt|d |j |dpd S)zBConvert a Morsel object into a Cookie containing the one k/v pair.Nzmax-agez max-age: z must be integerrz%a, %d-%b-%Y %H:%M:%S GMTrFrgr&rhttponlyrrr) rrrrgrr3r&rrrrr@r) inttime ValueErrorrcalendartimegmstrptimerxrr:r@)morselr time_templates rrwrws3G iS M$)++F9,=(>(>>??GG M M MKy(9KKKLL L M  S3 /$-y0A="Q"QRR y! *++h Z F^ &, -F8$%%ly!&Q   s 6A$A'Tc|t}|@d|D}|D]1}|s||vr)|t|||2|S)aCReturns a CookieJar from a key/value dictionary. :param cookie_dict: Dict of key/values to insert into CookieJar. :param cookiejar: (optional) A cookiejar to add the cookies to. :param overwrite: (optional) If False, will not replace cookies already in the jar with new ones. :rtype: CookieJar Ncg|] }|j Sr/)r3).0rls r z'cookiejar_from_dict..s>>>&&+>>>r)rqryrx) cookie_dictrj overwritenames_from_jarr3s rcookiejar_from_dictr s|%'' >>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'9PUVVV GY0 1 14 4   W % % % % 4 4 4!( 4 4 $$]3333 4 4 4 s-B$B*)B*rr.)rLrrr_internal_utilsrcompatrrrrr r ImportErrordummy_threadingr rOr`rerm RuntimeErrorrorrqrrxrwrrr/rrrs ------KKKKKKKKKKKKKK((((''''''(MMMMMMMM`''''''''* " " " ---,,,,&, EEEEE +^EEEP   "&"&"&J:*s ) 55