VY G @sjdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z yddl Z Wne k rddlZ YnXGdddeZGdd d eZd d Zd d ZddddZGdddeZGdddejejZddZddZddZddddZddZdS)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 urlunparseMorselc@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)selfrequestr4/tmp/pip-build-04bmskau/requests/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_host1szMockRequest.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_url4s zMockRequest.get_full_urlcCsdS)NTr)rrrris_unverifiableBszMockRequest.is_unverifiablecCs||jjkp||jkS)N)r rr )rnamerrr has_headerEszMockRequest.has_headerNcCs%|jjj||jj||S)N)r rrr )rr#defaultrrr get_headerHszMockRequest.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_headerKszMockRequest.add_headercCs||j|s z'cookiejar_from_dict..)rNrTrS) cookie_dictrI 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. z!You can only merge into CookieJarrIrF) rQrrsrrrruAttributeErrorrT)rIcookies cookie_in_jarrrr merge_cookies s   r)r3rtrr collectionsZ_internal_utilsrcompatrrrrr~ ImportErrordummy_threadingobjectrr5rArErL RuntimeErrorrMrsMutableMappingrNrrSrRrrrrrr s,    " H    #