U o aG@sdZddlZddlZddlZddlmZddlmZmZm Z m Z m Z z ddl Z Wne k rlddlZ YnXGdddeZGdd d eZd d Zd d ZdddZGdddeZGdddeje ZddZddZddZd ddZddZdS)!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|_dSN)_r _new_headersrurlschemetype)selfrequestr]C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\requests\cookies.py__init__%szMockRequest.__init__cCs|jSr )rrrrrget_type*szMockRequest.get_typecCst|jjjSr )rr r netlocrrrrget_host-szMockRequest.get_hostcCs|Sr rrrrrget_origin_req_host0szMockRequest.get_origin_req_hostcCsT|jjds|jjSt|jjddd}t|jj}t|j||j|j |j |j gS)NHostzutf-8)encoding) r headersgetr rrrrpathparamsqueryfragment)rhostparsedrrr get_full_url3s zMockRequest.get_full_urlcCsdSNTrrrrris_unverifiableAszMockRequest.is_unverifiablecCs||jjkp||jkSr )r rr rnamerrr has_headerDszMockRequest.has_headerNcCs|jj||j||Sr )r rrr )rr)defaultrrr get_headerGszMockRequest.get_headercCs tddS)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|<dSr r rr)valuerrradd_unredirected_headerNsz#MockRequest.add_unredirected_headercCs|jSr r1rrrrget_new_headersQszMockRequest.get_new_headerscCs|Sr )r'rrrr unverifiableTszMockRequest.unverifiablecCs|Sr )rrrrrorigin_req_hostXszMockRequest.origin_req_hostcCs|Sr rrrrrr#\szMockRequest.host)N)__name__ __module__ __qualname____doc__rrrrr%r'r*r,r0r4r5propertyr6r7r#rrrrr s$    r c@s(eZdZdZddZddZddZdS) 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. cCs ||_dS)zMake a MockResponse for `cookielib` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers N_headers)rrrrrrhszMockResponse.__init__cCs|jSr r>rrrrinfooszMockResponse.infocCs|j|dSr )r? getheadersr(rrrrArszMockResponse.getheadersN)r8r9r:r;rr@rArrrrr=asr=cCs8t|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)hasattrrBr r=msgextract_cookies)jarrresponsereqresrrrextract_cookies_to_jarvs  rJcCs t|}|||dS)zj Produce an appropriate Cookie header string to be sent with `request`, or None. :rtype: str Cookie)r add_cookie_headerr5r)rFrrrrrget_cookie_headers rNcCszg}|D]N}|j|krq|dk r,||jkr,q|dk r@||jkr@q||j|j|jfq|D]\}}}||||q\dS)zkUnsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). N)r)domainrappendclear) cookiejarr)rOr clearablescookierrrremove_cookie_by_names rUc@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)r8r9r:r;rrrrrVsrVcseZdZdZd3ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZd4ddZfddZddZdd Zd!d"Zfd#d$Zfd%d&Zd5d'd(Zd6d)d*Zd+d,Zd-d.Zd/d0Zd1d2ZZS)7RequestsCookieJaraCompatibility 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). NcCs.z||||WStk r(|YSXdS)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+rOrrrrrszRequestsCookieJar.getcKsX|dkr(t|||d|dddSt|tr|j|kr |dk rRtd||j}q |rb|Std|||fdS)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, %rr)rar)rOrrVr3rY)rr)rOrtoReturnrTrrrrXxs    z%RequestsCookieJar._find_no_duplicatescCs|j}|d|S)4Unlike a normal CookieJar, this class is pickleable. _cookies_lock)__dict__rpoprstaterrr __getstate__s  zRequestsCookieJar.__getstate__cCs$|j|d|jkr t|_dS)rrN)rr threadingRLockrrrrr __setstate__s  zRequestsCookieJar.__setstate__cCs"t}|||||S)z(Return a copy of this RequestsCookieJar.)rW set_policy get_policyr)rnew_cjrrrrs zRequestsCookieJar.copycCs|jS)z&Return the CookiePolicy instance used.)_policyrrrrrszRequestsCookieJar.get_policy)NNN)NN)NN)NN)r8r9r:r;rr`rcrerfrgrhrirmrorprrrtrwrxryr]rrrXrrrr __classcell__rrrurrWs2            rWcCsN|dkr dSt|dr|St|}||D]}|t|q4|S)Nr)rCrrQr])rFnew_jarrTrrr_copy_cookie_jars  rcKsd||ddddddddddidd }t|t|}|rLd }t|t|||t|d |d <t|d |d <|d d|d<t|d|d<tjf|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) versionr)r3portrOrsecureexpiresdiscardcomment comment_urlrestrfc2109z4create_cookie() got unexpected keyword arguments: %srport_specifiedrOdomain_specified.domain_initial_dotrpath_specified)r` TypeErrorrdrboolrzrrK)r)r3r^resultbadargserrrrrr\s0 r\cCsd}|drPzttt|d}Wqrtk rLtd|dYqrXn"|drrd}tt|d|}t|dt|dd|d||j |d dd |d idt|d |j |d pdd 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 GMTrFrOrrhttponlyrrr) rrrrOrr)rrrrrr3r) inttime ValueErrorrcalendartimegmstrptimer\rr.r3)morselr time_templaterrrr[s4    r[TcCsR|dkrt}|dk rNdd|D}|D]$}|s8||kr(|t|||q(|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 NcSsg|] }|jqSr)r)).0rTrrr sz'cookiejar_from_dict..)rWr]r\) cookie_dictrR overwritenames_from_jarr)rrrcookiejar_from_dicts  rcCsvt|tjstdt|tr.t||dd}nDt|tjrrz||Wn(tk rp|D]}||q\YnX|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)rRr) rZrrrdictrrAttributeErrorr])rRcookies cookie_in_jarrrr merge_cookiess   r)NN)NT)r;rrr_internal_utilsrcompatrrrrrr ImportErrorZdummy_threadingobjectr r=rJrNrU RuntimeErrorrVrrWrr\r[rrrrrrs.   H $