� ��abc@sQdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z yddl Z Wne k r�ddlZ nXdefd��YZdefd ��YZd �Zd �Zddd �Zd efd��YZdejejfd��YZd�Zd�Zd�Zded�Zd�Z 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. i����Ni(tto_native_string(t cookielibturlparset urlunparsetMorselt MockRequestcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z dd�Z d �Z d �Z d �Zed ��Zed ��Zed��ZRS(s�Wraps 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|jj�j|_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|jj�jS(N(RRRtnetloc(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_host.scCs |j�S(N(R(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_origin_req_host1scCsx|jjjd�s|jjSt|jjddd�}t|jj�}t|j||j|j |j |j g�S(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_headerHscCstd��dS(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.pyRO�s0   cCs!d}|dr_y$ttj�t|d��}Wq�tk r[td|d��q�Xn2|dr�d}tjtj|d|��}ntd|ddt |d�dt d|dd|d |j d |d d dd i|d d6dt dt |d�d|j d|dpd� S(sBConvert a Morsel object into a Cookie containing the one k/v pair.smax-agesmax-age: %s must be integerR�s%a, %d-%b-%Y %H:%M:%S GMTR�R�R�RBRRR�R�thttponlyR�R�R�R'R�iN( R/tintttimet ValueErrorR�tcalendarttimegmtstrptimeROR�R`R$R'(tmorselR�t time_template((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRN�s0 $       cCs�|dkrt�}n|dk r�g|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_dict�s    $cCs�t|tj�s!td��nt|t�rKt|d|dt�}nXt|tj�r�y|j|�Wq�tk r�x|D]}|j |�q�Wq�Xn|S(s�Add 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�( RMRRoR�R�R�R`RqtAttributeErrorRP(REtcookiest cookie_in_jar((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt merge_cookies s  (!R.RpR�R�t collectionst_internal_utilsRtcompatRRRRRzt ImportErrortdummy_threadingtobjectRR1R=RAR/RHt RuntimeErrorRIRotMutableMappingRJRRORNRR�R�(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt s,    " H  �  #