abc@sQdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z yddl Z Wne k rddlZ nXdefdYZdefd YZd Zd Zddd Zd efdYZdejejfdYZdZdZdZdedZdZ dS(s requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. iNi(tto_native_string(t cookielibturlparset urlunparsetMorselt MockRequestcBseZdZdZdZdZdZdZdZdZ ddZ d Z d Z d Zed Zed ZedZRS(sWraps 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(t_rt _new_headersRturltschemettype(tselftrequest((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__init__&s  cCs|jS(N(R (R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_type+scCst|jjjS(N(RRRtnetloc(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_host.scCs |jS(N(R(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_origin_req_host1scCsx|jjjds|jjSt|jjddd}t|jj}t|j||j|j |j |j gS(NtHosttencodingsutf-8( RtheaderstgetRRRRR tpathtparamstquerytfragment(R thosttparsed((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_full_url4s cCstS(N(tTrue(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytis_unverifiableBscCs||jjkp||jkS(N(RRR(R tname((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt has_headerEscCs%|jjj||jj||S(N(RRRR(R Rtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_headerHscCstddS(sMcookielib has no legitimate use for this method; add it back if you find one.s=Cookie headers should be added with add_unredirected_header()N(tNotImplementedError(R tkeytval((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt add_headerKscCs||j|(RR'RQtresulttbadargsterr((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyROs0   cCs!d}|dr_y$ttjt|d}Wqtk r[td|dqXn2|drd}tjtj|d|}ntd|ddt |ddt d|dd|d |j d |d d dd i|d d6dt dt |dd|j d|dpd S(sBConvert a Morsel object into a Cookie containing the one k/v pair.smax-agesmax-age: %s must be integerRs%a, %d-%b-%Y %H:%M:%S GMTRRRRBRRRRthttponlyRRRR'RiN( R/tintttimet ValueErrorRtcalendarttimegmtstrptimeRORR`R$R'(tmorselRt time_template((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRNs0 $       cCs|dkrt}n|dk rg|D]}|j^q+}x@|D]5}|s_||krG|jt|||qGqGWn|S(s-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. N(R/RJRRPRO(t cookie_dictREt overwriteRGtnames_from_jarR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytcookiejar_from_dicts    $cCst|tjs!tdnt|trKt|d|dt}nXt|tjry|j|Wqtk rx|D]}|j |qWqXn|S(sAdd 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. s!You can only merge into CookieJarRER( RMRRoRRRR`RqtAttributeErrorRP(REtcookiest cookie_in_jar((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt merge_cookies s  (!R.RpRRt collectionst_internal_utilsRtcompatRRRRRzt ImportErrortdummy_threadingtobjectRR1R=RAR/RHt RuntimeErrorRIRotMutableMappingRJRRORNRRR(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt s,    " H    #