Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/cachecontrol/__pycache__/controller.cpython-36.pyc

3

aj2@sdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZej
eZejdZd	d
ZGdddeZdS)
z7
The httplib2 algorithms ported for use with requests.
N)parsedate_tz)CaseInsensitiveDict)	DictCache)
Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?cCs0tj|j}|d|d|d|d|dfS)zParses a URI using the regex given in Appendix B of RFC 3986.

        (scheme, authority, path, query, fragment) = parse_uri(uri)
    r)URImatchgroups)urir
r /usr/lib/python3.6/controller.py	parse_urisrc@s\eZdZdZdddZeddZedd	Zd
dZdd
Z	ddZ
dddZddZdS)CacheControllerz9An interface to see if request should cached or not.
    NTcCs"|pt|_||_|pt|_dS)N)rcachecache_etagsr
serializer)selfrrrrrr__init__!szCacheController.__init__c	Cslt|\}}}}}|s|r*td||j}|j}|sBd}|rTdj||gpV|}|d||}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %s/?z://)r	Exceptionlowerjoin)	clsrschemeZ	authoritypathZqueryZfragmentZrequest_uriZ
defrag_urirrr_urlnorm&szCacheController._urlnormcCs
|j|S)N)r )rrrrr	cache_url:szCacheController.cache_urlcCsVi}d}d|krd}||krR||jd}dd|D}dd|D}t||}|S)zz
        Parse the cache control headers returning a dictionary with values
        for the different directives.
        z
cache-controlz
Cache-Control,cSs4g|],}d|jdkrtdd|jddDqS)r=cSsg|]}|jjqSr)stripr).0xrrr
<listcomp>LszBCacheController.parse_cache_control.<locals>.<listcomp>.<listcomp>)findtuplesplit)r%partrrrr'Lsz7CacheController.parse_cache_control.<locals>.<listcomp>cSs*g|]"}d|jdkr|jjdfqS)rr#r()r)r$r)r%namerrrr'Ps)r+dict)rheadersZretvalZ	cc_headerpartsZparts_with_argsZ
parts_wo_argsrrrparse_cache_control>sz#CacheController.parse_cache_controlcCs|j|j}tjd||j|j}d|kr:tjddSd|kr\|ddkr\tjddS|jj|}|dkr~tjd	dS|jj	||}|stj
d
dS|jdkrd}tj||St|j}|sd
|krd|krtjd|jj
|tjddStj}tjt|d
}	td||	}
tjd|
|j|}d}d|krt|djrtt|d}tjd|nDd|krt|d}
|
dk	rtj|
|	}td|}tjd|d|kryt|d}tjd|Wntk
rd}YnXd|krDyt|d}Wntk
r.d}YnX|
|7}
tjd|
||
krjtjdtjd||
|Sd|krtjd|jj
|dS)ze
        Return a cached response if it exists in the cache, otherwise
        return False.
        zLooking up "%s" in the cachezno-cachez-Request header has "no-cache", cache bypassedFzmax-agerz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredi-zVReturning cached "301 Moved Permanently" response (ignoring date and etag information)dateetagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %iexpiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %iz	min-freshz'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r!urlloggerdebugr1r/rgetrloadsZwarningstatusrdeletetimecalendarZtimegmrmaxisdigitint
ValueError)rrequestr!ccZ
cache_datarespmsgr/Znowr2Zcurrent_ageZresp_ccZfreshness_lifetimer4Zexpire_timeZ	min_freshrrrcached_requestVs





















zCacheController.cached_requestcCs`|j|j}|jj||jj|}i}|r\t|j}d|krH|d|d<d|kr\|d|d<|S)Nr3ZETagz
If-None-Matchz
last-modifiedz
Last-ModifiedzIf-Modified-Since)r!r5rr9rr8rr/)rrBr!rDZnew_headersr/rrrconditional_headerss
z#CacheController.conditional_headersc
Csddddg}|j|kr*tjd|j|dSt|j}|dk	rhd|krh|djrht|dt|krhdS|j|j}|j|}|j	|j
}tjd|d	}	|jd
rd}	tjd|jd
rd}	tjd
|	r|jj|rtjd|jj
||jod|kr(tjd|jj||jj|||dn|jdkrXtjd|jj||jj||nd|kr|r|jdr|djrt|ddkrtjd|jj||jj|||dn:d|kr|drtjd|jj||jj|||ddS)zc
        Algorithm for caching requests.

        This assumes a requests Response object.
        i,i-zStatus code %s not in %sNzcontent-lengthz&Updating cache with response from "%s"Fzno-storeTzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"r3zCaching due to etag)bodyzCaching permanant redirectr2zmax-agerz'Caching b/c date exists and max-age > 0r4zCaching b/c of expires header)r:r6r7rr/r?r@lenr1r!r5r8rr;rsetrdumps)
rrBresponserJZcacheable_status_codesZresponse_headersZcc_reqrCr!Zno_storerrrcache_responsesd










 



zCacheController.cache_responsecsv|j|j}|jj||jj|}|s*|Sdg|jjtfdd|jj	Dd|_
|jj||jj|||S)zOn 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.
        zcontent-lengthc3s&|]\}}|jkr||fVqdS)N)r)r%kv)excluded_headersrr	<genexpr>Tsz9CacheController.update_cached_response.<locals>.<genexpr>rH)
r!r5rr9rr8r/updater.itemsr:rLrM)rrBrNr!Zcached_responser)rRrupdate_cached_response6s
z&CacheController.update_cached_response)NTN)N)
__name__
__module____qualname____doc__rclassmethodr r!r1rFrGrOrVrrrrrs
y
Wr)rZZloggingrer=r<Zemail.utilsrZpip._vendor.requests.structuresrrrZ	serializerZ	getLoggerrWr6compilerrobjectrrrrr<module>s

	
Back to Directory File Manager