7Re.Ac @s:dZddlZddlZddlmZmZmZmZyddlZeWne k rtddl ZYnXGddde Z Gddde Z d d Zd d Zddd dZGdddeZGdddejejZddZddZddddZddZdS(u Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. iNi(u cookielibuurlparseu urlunparseuMorselcBs|EeZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZddZeddZeddZeddZdS(u MockRequestuWraps 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(u_ru _new_headersuurlparseuurluschemeutype(uselfurequest((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu__init__!s  uMockRequest.__init__cCs|jS(N(utype(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuget_type&suMockRequest.get_typecCst|jjjS(N(uurlparseu_ruurlunetloc(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuget_host)suMockRequest.get_hostcCs |jS(N(uget_host(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuget_origin_req_host,suMockRequest.get_origin_req_hostcCsl|jjjds|jjS|jjd}t|jj}t|j||j|j|j |j gS(NuHost( u_ruheadersugetuurluurlparseu urlunparseuschemeupathuparamsuqueryufragment(uselfuhostuparsed((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu get_full_url/s uMockRequest.get_full_urlcCsdS(NT(uTrue(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuis_unverifiable=suMockRequest.is_unverifiablecCs||jjkp||jkS(N(u_ruheadersu _new_headers(uselfuname((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu has_header@suMockRequest.has_headercCs%|jjj||jj||S(N(u_ruheadersugetu _new_headers(uselfunameudefault((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu get_headerCsuMockRequest.get_headercCstddS(uMcookielib has no legitimate use for this method; add it back if you find one.u=Cookie headers should be added with add_unredirected_header()N(uNotImplementedError(uselfukeyuval((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu add_headerFsuMockRequest.add_headercCs||j||EeZdZdZddZddZddZdS( u MockResponseuWraps 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(uMake a MockResponse for `cookielib` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers N(u_headers(uselfuheaders((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu__init__dsuMockResponse.__init__cCs|jS(N(u_headers(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuinfoksuMockResponse.infocCs|jj|dS(N(u_headersu getheaders(uselfuname((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu getheadersnsuMockResponse.getheadersN(u__name__u __module__u __qualname__u__doc__u__init__uinfou getheaders(u __locals__((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu MockResponse]s  u MockResponsecCsNt|do|jsdSt|}t|jj}|j||dS(uExtract 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 u_original_responseN(uhasattru_original_responseu MockRequestu MockResponseumsguextract_cookies(ujarurequesturesponseurequres((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuextract_cookies_to_jarrs   uextract_cookies_to_jarcCs,t|}|j||jjdS(uOProduce an appropriate Cookie header string to be sent with `request`, or None.uCookie(u MockRequestuadd_cookie_headeruget_new_headersuget(ujarurequestur((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuget_cookie_headers  uget_cookie_headercCsg}x{|D]s}|j|kr |dks=||jkr|dksX||jkr}|j|j|j|jfq}qq q Wx*|D]"\}}}|j|||qWdS(ukUnsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). N(unameuNoneudomainupathuappenduclear(u cookiejarunameudomainupathu clearablesucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuremove_cookie_by_names ,uremove_cookie_by_namecBs|EeZdZdZdS(uCookieConflictErroruThere 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(u__name__u __module__u __qualname__u__doc__(u __locals__((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuCookieConflictErrorsuCookieConflictErrorcsI|EeZdZdZd.d.d.ddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZd.d.ddZddZddZddZfd d!Zfd"d#Zd.d.d$d%Zd.d.d&d'Zd(d)Zd*d+Zd,d-ZS(/uRequestsCookieJaruCompatibility 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. Don't use the dict interface internally; it's just for compatibility with with external client code. All `requests` code should work out of the box with externally provided instances of CookieJar, e.g., LWPCookieJar and FileCookieJar. Caution: dictionary operations that are normally O(1) may be O(n). Unlike a regular CookieJar, this class is pickleable. c Cs4y|j|||SWntk r/|SYnXdS(uDict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Caution: operation is O(n), not O(1).N(u_find_no_duplicatesuKeyError(uselfunameudefaultudomainupath((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyugets uRequestsCookieJar.getcKs||dkr;t||d|jdd|jddSt|trYt|}nt|||}|j||S(uDict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.udomainupathN(uNoneuremove_cookie_by_nameugetu isinstanceuMorselumorsel_to_cookieu create_cookieu set_cookie(uselfunameuvalueukwargsuc((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyusets + uRequestsCookieJar.setccs#xt|D]}|jVq WdS(uyDict-like iterkeys() that returns an iterator of names of cookies from the jar. See itervalues() and iteritems().N(uiteruname(uselfucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuiterkeyssuRequestsCookieJar.iterkeyscCst|jS(uhDict-like keys() that returns a list of names of cookies from the jar. See values() and items().(ulistuiterkeys(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyukeyssuRequestsCookieJar.keysccs#xt|D]}|jVq WdS(uzDict-like itervalues() that returns an iterator of values of cookies from the jar. See iterkeys() and iteritems().N(uiteruvalue(uselfucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu itervaluessuRequestsCookieJar.itervaluescCst|jS(uiDict-like values() that returns a list of values of cookies from the jar. See keys() and items().(ulistu itervalues(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuvaluessuRequestsCookieJar.valuesccs,x%t|D]}|j|jfVq WdS(uzDict-like iteritems() that returns an iterator of name-value tuples from the jar. See iterkeys() and itervalues().N(uiterunameuvalue(uselfucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu iteritemssuRequestsCookieJar.iteritemscCst|jS(uDict-like items() that returns a list of name-value tuples from the jar. See keys() and values(). Allows client-code to call "dict(RequestsCookieJar) and get a vanilla python dict of key value pairs.(ulistu iteritems(uself((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyuitemssuRequestsCookieJar.itemscCsCg}x6t|D](}|j|kr|j|jqqW|S(u2Utility method to list all the domains in the jar.(uiterudomainuappend(uselfudomainsucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu list_domainss uRequestsCookieJar.list_domainscCsCg}x6t|D](}|j|kr|j|jqqW|S(u0Utility method to list all the paths in the jar.(uiterupathuappend(uselfupathsucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu list_pathss uRequestsCookieJar.list_pathscCsSg}xFt|D]8}|jdk r;|j|kr;dS|j|jqWdS(uWReturns True if there are multiple domains in the jar. Returns False otherwise.NTF(uiterudomainuNoneuTrueuappenduFalse(uselfudomainsucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyumultiple_domainss u"RequestsCookieJar.multiple_domainscCsji}x]t|D]O}|dks4|j|kr|dksO|j|kr|j||j|jt|||q>q>Wn|S(u-Returns 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. cSsg|]}|jqS((uname(u.0ucookie((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu s u'cookiejar_from_dict..N(uNoneuRequestsCookieJaru set_cookieu create_cookie(u cookie_dictu cookiejaru overwriteunames_from_jaruname((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyucookiejar_from_dicts    $ucookiejar_from_dictc Cst|tjs!tdnt|trKt|d|dd}nYt|tjry|j|Wqtk rx|D]}|j |qWYqXn|S(uAdd 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. u!You can only merge into CookieJaru cookiejaru overwriteF( u isinstanceu cookielibu CookieJaru ValueErrorudictucookiejar_from_dictuFalseuupdateuAttributeErroru set_cookie(u cookiejarucookiesu cookie_in_jar((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyu merge_cookiess  u merge_cookiesT(u__doc__utimeu collectionsucompatu cookielibuurlparseu urlunparseuMorselu threadingu ImportErrorudummy_threadinguobjectu MockRequestu MockResponseuextract_cookies_to_jaruget_cookie_headeruNoneuremove_cookie_by_nameu RuntimeErroruCookieConflictErroru CookieJaruMutableMappinguRequestsCookieJaru create_cookieumorsel_to_cookieuTrueucookiejar_from_dictu merge_cookies(((u5/tmp/pip-zej_zi-build/pip/_vendor/requests/cookies.pyus&  "  H   #