ó •abc@s·dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej eƒZejdƒZd „Zd efd „ƒYZdS( s7 The httplib2 algorithms ported for use with requests. iÿÿÿÿN(t parsedate_tz(tCaseInsensitiveDicti(t DictCache(t Serializers9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs<tj|ƒjƒ}|d|d|d|d|dfS(s‡Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) iiiii(tURItmatchtgroups(turiR((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt parse_uristCacheControllercBsneZdZd ed d„Zed„ƒZed„ƒZd„Z d„Z d„Z d d„Z d„Z RS( s9An interface to see if request should cached or not. cCs1|p tƒ|_||_|p'tƒ|_dS(N(Rtcachet cache_etagsRt serializer(tselfR R R ((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt__init__!s c Csšt|ƒ\}}}}}| s)| r<td|ƒ‚n|jƒ}|jƒ}|scd}n|r~dj||gƒp|}|d||}|S(s4Normalize the URL to create a safe key for the caches(Only absolute URIs are allowed. uri = %st/t?s://(Rt Exceptiontlowertjoin( tclsRtschemet authoritytpathtquerytfragmentt request_urit defrag_uri((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt_urlnorm&s   !cCs |j|ƒS(N(R(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt cache_url:sc Csöi}d}d|kr!d}n||krò||jdƒ}g|D]R}d|jdƒkrGtg|jddƒD]}|jƒjƒ^qxƒ^qG}g|D]3}d|jdƒkr¦|jƒjƒdf^q¦} t|| ƒ}n|S(sz Parse the cache control headers returning a dictionary with values for the different directives. s cache-controls Cache-Controlt,iÿÿÿÿt=i(tsplittfindttupletstripRtdict( R theaderstretvalt cc_headertpartstparttxtparts_with_argstnamet parts_wo_args((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pytparse_cache_control>s   \=cCs^|j|jƒ}tjd|ƒ|j|jƒ}d|krQtjdƒtSd|kr~|ddkr~tjdƒtS|jj|ƒ}|dkr­tjdƒtS|j j ||ƒ}|sÙtj dƒtS|j d krÿd }tj|ƒ|St|jƒ}| s!d |kr^d |krMtjd ƒ|jj|ƒntjdƒtStjƒ}tjt|d ƒƒ} td|| ƒ} tjd| ƒ|j|ƒ} d} d| krú| djƒrút| dƒ} tjd| ƒn`d|krZt|dƒ} | dk rZtj| ƒ| }td|ƒ} tjd| ƒqZnd|kr§y$t|dƒ} tjd| ƒWq§tk r£d} q§Xnd|krþyt|dƒ}Wntk ràd}nX| |7} tjd| ƒn| | kr.tjdƒtjd| | ƒ|Sd |krZtjdƒ|jj|ƒntS(se Return a cached response if it exists in the cache, otherwise return False. sLooking up "%s" in the cachesno-caches-Request header has "no-cache", cache bypassedsmax-ageis1Request header has "max_age" as 0, cache bypassedsNo cache entry availables1Cache entry deserialization failed, entry ignoredi-sVReturning cached "301 Moved Permanently" response (ignoring date and etag information)tdatetetags(Purging cached response: no date or etags!Ignoring cached response: no datesCurrent age based on date: %is#Freshness lifetime from max-age: %itexpiress#Freshness lifetime from expires: %is+Freshness lifetime from request max-age: %is min-freshs'Adjusted current age from min-fresh: %is2The response is "fresh", returning cached responses%i > %is4The cached response is "stale" with no etag, purgingN(RturltloggertdebugR.R%tFalseR tgettNoneR tloadstwarningtstatusRtdeletettimetcalendarttimegmRtmaxtisdigittintt ValueError(R trequestRtcct cache_datatresptmsgR%tnowR/t current_agetresp_cctfreshness_lifetimeR1t expire_timet min_fresh((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pytcached_requestVsŒ                                cCs|j|jƒ}|jj||jj|ƒƒ}i}|r‹t|jƒ}d|krk|d|d 0R1sCaching b/c of expires header(R:R3R4RR%R7R@RAtlenR.RR2R5R6tTrueR R;R tsetR tdumps( R RCtresponseRRtcacheable_status_codestresponse_headerstcc_reqRDRtno_store((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pytcache_responseßsd        &  "    cs¤|j|jƒ}|jj||jj|ƒƒ}|s=|Sdg‰|jjt‡fd†|jj ƒDƒƒƒd|_ |jj ||jj ||ƒƒ|S(séOn a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response. scontent-lengthc3s3|])\}}|jƒˆkr||fVqdS(N(R(t.0tktv(texcluded_headers(sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pys Ts iÈ( RR2R R8R R6R%tupdateR$titemsR:RURV(R RCRWRtcached_response((R`sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pytupdate_cached_response6s   &  N(t__name__t __module__t__doc__R7RTRt classmethodRRR.RNRQR\Rd(((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyR s  y  W(RgtloggingtreR=R<t email.utilsRtpip._vendor.requests.structuresRR Rt serializeRt getLoggerReR3tcompileRRtobjectR (((sG/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyts