ReG @sadZddlZddlZddlZddlmZddlmZmZm Z m Z m Z yddl Z Wne k rddlZ YnXGdddeZGdd d eZd d Zd d ZddddZGdddeZGdddeje ZddZddZddZddddZddZdS)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 urlunparseMorselMutableMappingc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZ ddZeddZeddZeddZdS) 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. cCs.||_i|_t|jjj|_dS)N)_r _new_headersrurlschemetype)selfrequestr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/cookies.py__init__%s  zMockRequest.__init__cCs|jS)N)r)rrrrget_type*szMockRequest.get_typecCst|jjjS)N)rr r netloc)rrrrget_host-szMockRequest.get_hostcCs |jS)N)r)rrrrget_origin_req_host0szMockRequest.get_origin_req_hostcCsx|jjjds|jjSt|jjddd}t|jj}t|j||j|j |j |j gS)NHostencodingzutf-8) r headersgetr rrrr pathparamsqueryfragment)rhostparsedrrr get_full_url3s zMockRequest.get_full_urlcCsdS)NTr)rrrris_unverifiableAszMockRequest.is_unverifiablecCs||jjkp||jkS)N)r rr )rnamerrr has_headerDszMockRequest.has_headerNcCs%|jjj||jj||S)N)r rrr )rr$defaultrrr get_headerGszMockRequest.get_headercCstddS)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()N)NotImplementedError)rkeyvalrrr add_headerJszMockRequest.add_headercCs||j|rrrrrget_cookie_headers  rFcCsg}x{|D]s}|j|kr%q |dk rC||jkrCq |dk ra||jkraq |j|j|j|jfq Wx*|D]"\}}}|j|||qWdS)zkUnsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). N)r$domainrappendclear) cookiejarr$rGr clearablescookierrrremove_cookie_by_names #rMc@seZdZdZdS)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)r1r2r3r4rrrrrNs rNcsceZdZdZdddddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddddZfddZddZdd Zd!d"Zfd#d$Zfd%d&Zddd'd(Zddd)d*Zd+d,Zd-d.Zd/d0Zd1d2ZS)3RequestsCookieJaraCompatibility 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). Nc Cs4y|j|||SWntk r/|SYnXdS)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). N)_find_no_duplicatesKeyError)rr$r&rGrrrrrs zRequestsCookieJar.getcKs||dkr;t||d|jdd|jddSt|trYt|}nt|||}|j||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)rMr isinstancermorsel_to_cookie create_cookie set_cookie)rr$r,kwargscrrrsets + zRequestsCookieJar.setccs#xt|D]}|jVq WdS)zDict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). N)iterr$)rrLrrriterkeysszRequestsCookieJar.iterkeyscCst|jS)zDict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). )listrZ)rrrrkeysszRequestsCookieJar.keysccs#xt|D]}|jVq WdS)zDict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). N)rYr,)rrLrrr itervaluesszRequestsCookieJar.itervaluescCst|jS)zDict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). )r[r])rrrrvaluesszRequestsCookieJar.valuesccs,x%t|D]}|j|jfVq WdS)zDict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). N)rYr$r,)rrLrrr iteritemsszRequestsCookieJar.iteritemscCst|jS)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(). )r[r_)rrrritemsszRequestsCookieJar.itemscCs@g}x3t|D]%}|j|kr|j|jqW|S)z2Utility method to list all the domains in the jar.)rYrGrH)rdomainsrLrrr list_domainss zRequestsCookieJar.list_domainscCs@g}x3t|D]%}|j|kr|j|jqW|S)z0Utility method to list all the paths in the jar.)rYrrH)rpathsrLrrr list_pathss zRequestsCookieJar.list_pathscCsSg}xFt|D]8}|jdk r;|j|kr;dS|j|jqWdS)zvReturns True if there are multiple domains in the jar. Returns False otherwise. :rtype: bool NTF)rYrGrH)rrarLrrrmultiple_domainss z"RequestsCookieJar.multiple_domainscCsgi}xZt|D]L}|dks4|j|kr|dksO|j|kr|j||jnew_jarrLrrr_copy_cookie_jars    rcKsddd|d|ddddd d d d d ddddddddddidd i }t|t|}|rd}t|t||j|t|d|d s z'cookiejar_from_dict..)rOrUrT) cookie_dictrJ overwritenames_from_jarr$rrrcookiejar_from_dicts    rc Cst|tjstdt|trHt|d|dd}nVt|tjry|j|Wn0tk rx|D]}|j|qWYnX|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 CookieJarrJrF) rRrrtrdictrrvAttributeErrorrU)rJcookies cookie_in_jarrrr merge_cookiess   r)r4rurr_internal_utilsrcompatrrrrrr ImportErrordummy_threadingobjectr r6rBrFrM RuntimeErrorrNrtrOrrTrSrrrrrr s*   ( H    $