ó
{Udc           @   s·   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z e j e ƒ Z e j d ƒ Z d	 „  Z d
 e f d „  ƒ  YZ d S(   s7   
The httplib2 algorithms ported for use with requests.
iÿÿÿÿN(   t   parsedate_tz(   t   CaseInsensitiveDicti   (   t	   DictCache(   t
   Serializers9   ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?c         C   s<   t  j |  ƒ j ƒ  } | d | d | d | d | d f S(   s‡   Parses a URI using the regex given in Appendix B of RFC 3986.

        (scheme, authority, path, query, fragment) = parse_uri(uri)
    i   i   i   i   i   (   t   URIt   matcht   groups(   t   uriR   (    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt	   parse_uri   s    t   CacheControllerc           B   st   e  Z d  Z d	 e d	 d	 d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d	 d	 d „ Z d „  Z RS(
   s9   An interface to see if request should cached or not.
    c         C   sL   | d  k r t ƒ  n | |  _ | |  _ | p3 t ƒ  |  _ | pB d |  _ d  S(   NiÈ   iË   i,  i-  (   iÈ   iË   i,  i-  (   t   NoneR   t   cachet   cache_etagsR   t
   serializert   cacheable_status_codes(   t   selfR   R   R   t   status_codes(    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   __init__"   s    	c   	      C   sš   t  | ƒ \ } } } } } | s) | r< t d | ƒ ‚ n  | j ƒ  } | j ƒ  } | sc d } n  | r~ d j | | g ƒ p | } | d | | } | S(   s4   Normalize the URL to create a safe key for the caches(   Only absolute URIs are allowed. uri = %st   /t   ?s   ://(   R   t	   Exceptiont   lowert   join(	   t   clsR   t   schemet	   authorityt   patht   queryt   fragmentt   request_urit
   defrag_uri(    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   _urlnorm*   s    	!c         C   s   |  j  | ƒ S(   N(   R   (   R   R   (    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt	   cache_url>   s    c   
      C   sè  i t  t f d 6t  t f d 6t  t f d 6d  t f d 6d  t f d 6d  t f d 6d  t f d 6d  t f d 6d  t f d	 6d  t f d
 6d  t f d 6t  t f d 6} | j d | j d d ƒ ƒ } i  } x| j d ƒ D]
} | j ƒ  sî qÖ n  | j d d ƒ } | d j ƒ  } y | | \ } }	 Wn$ t k
 rJt j	 d | ƒ qÖ n X| sY|	 rfd  | | <n  | rÖ y | | d j ƒ  ƒ | | <Wqàt
 k
 r¶|	 rÝt j	 d | ƒ qÝqàt k
 rÜt j	 d | | j ƒ qàXqÖ qÖ W| S(   Ns   max-ages	   max-stales	   min-freshs   no-caches   no-stores   no-transforms   only-if-cacheds   must-revalidatet   publict   privates   proxy-revalidates   s-maxages   cache-controls   Cache-Controlt    t   ,t   =i   i    s,   Ignoring unknown cache-control directive: %ss-   Missing value for cache-control directive: %ss8   Invalid value for cache-control directive %s, must be %s(   t   intt   Truet   FalseR
   t   gett   splitt   stript   KeyErrort   loggert   debugt
   IndexErrort
   ValueErrort   __name__(
   R   t   headerst   known_directivest
   cc_headerst   retvalt   cc_directivet   partst	   directivet   typt   required(    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   parse_cache_controlB   sR    c         C   s   |  j  | j ƒ } t j d | ƒ |  j | j ƒ } d | k rQ t j d ƒ t Sd | k r~ | d d k r~ t j d ƒ t S|  j j | ƒ } | d k r­ t j d ƒ t S|  j
 j | | ƒ } | sÙ t j d ƒ t S| j d	 k rÿ d
 } t j | ƒ | St | j ƒ } | s!d | k r^d | k rMt j d ƒ |  j j | ƒ n  t j d ƒ t St j ƒ  } t j t | d ƒ ƒ }	 t d | |	 ƒ }
 t j d |
 ƒ |  j | ƒ } d } d | k rä| d } t j d | ƒ n` d | k rDt | d ƒ } | d k	 rDt j | ƒ |	 } t d | ƒ } t j d | ƒ qDn  d | k rm| d } t j d | ƒ n  d | k r | d } |
 | 7}
 t j d |
 ƒ n  | |
 k rÐt j d ƒ t j d | |
 ƒ | Sd | k rüt j d ƒ |  j j | ƒ n  t S(   se   
        Return a cached response if it exists in the cache, otherwise
        return False.
        s   Looking up "%s" in the caches   no-caches-   Request header has "no-cache", cache bypasseds   max-agei    s1   Request header has "max_age" as 0, cache bypasseds   No cache entry availables1   Cache entry deserialization failed, entry ignoredi-  sV   Returning cached "301 Moved Permanently" response (ignoring date and etag information)t   datet   etags(   Purging cached response: no date or etags!   Ignoring cached response: no dates   Current age based on date: %is#   Freshness lifetime from max-age: %it   expiress#   Freshness lifetime from expires: %is+   Freshness lifetime from request max-age: %is	   min-freshs'   Adjusted current age from min-fresh: %is2   The response is "fresh", returning cached responses   %i > %is4   The cached response is "stale" with no etag, purgingN(   R    t   urlR-   R.   R;   R2   R(   R   R)   R
   R   t   loadst   warningt   statusR   t   deletet   timet   calendart   timegmR    t   max(   R   t   requestR    t   cct
   cache_datat   respt   msgR2   t   nowR<   t   current_aget   resp_cct   freshness_lifetimeR>   t   expire_timet	   min_fresh(    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   cached_requestx   sv    




c         C   s   |  j  | j ƒ } |  j j | |  j j | ƒ ƒ } i  } | r‹ t | j ƒ } d | k rk | d | d <n  d | k r‹ | d | d <q‹ n  | S(   NR=   t   ETags   If-None-Matchs   last-modifieds   Last-Modifieds   If-Modified-Since(   R    R?   R   R@   R   R)   R   R2   (   R   RH   R    RK   t   new_headersR2   (    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   conditional_headersç   s    !c         C   sÍ  | p |  j  } | j | k r8 t j d | j | ƒ d St | j ƒ } | d k	 r d | k r | d j ƒ  r t | d ƒ t	 | ƒ k r d S|  j
 | j ƒ } |  j
 | ƒ } |  j | j ƒ }	 t j d |	 ƒ t }
 d | k rú t }
 t j d ƒ n  d | k rt }
 t j d ƒ n  |
 rT|  j j |	 ƒ rTt j d ƒ |  j j |	 ƒ n  |
 r^d Sd	 | j d
 d ƒ k r‡t j d ƒ d S|  j rÔd | k rÔt j d ƒ |  j j |	 |  j j | | d | ƒƒ nõ | j d k rt j d ƒ |  j j |	 |  j j | | ƒ ƒ n´ d | k rÉd | k ru| d d k rut j d ƒ |  j j |	 |  j j | | d | ƒƒ qÉd | k rÉ| d rÆt j d ƒ |  j j |	 |  j j | | d | ƒƒ qÆqÉn  d S(   sc   
        Algorithm for caching requests.

        This assumes a requests Response object.
        s   Status code %s not in %sNs   content-lengths&   Updating cache with response from "%s"s   no-stores   Response header has "no-store"s   Request header has "no-store"s0   Purging existing cache entry to honor "no-store"t   *t   varyR#   s   Response header has "Vary: *"R=   s   Caching due to etagt   bodyi-  s   Caching permanant redirectR<   s   max-agei    s'   Caching b/c date exists and max-age > 0R>   s   Caching b/c of expires header(   R   RB   R-   R.   R   R2   R
   t   isdigitR&   t   lenR;   R    R?   R(   R'   R   R)   RC   R   t   setR   t   dumps(   R   RH   t   responseRY   R   R   t   response_headerst   cc_reqRI   R    t   no_store(    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   cache_response÷   s^    	"%	"
	c            s¤   |  j  | j ƒ } |  j j | |  j j | ƒ ƒ } | s= | Sd g ‰  | j j t ‡  f d †  | j j	 ƒ  Dƒ ƒ ƒ d | _
 |  j j | |  j j | | ƒ ƒ | 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.
        s   content-lengthc         3   s3   |  ]) \ } } | j  ƒ  ˆ  k r | | f Vq d  S(   N(   R   (   t   .0t   kt   v(   t   excluded_headers(    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pys	   <genexpr>l  s   	iÈ   (   R    R?   R   R@   R   R)   R2   t   updatet   dictt   itemsRB   R\   R]   (   R   RH   R^   R    t   cached_response(    (   Rf   sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   update_cached_responseR  s    !				"N(   R1   t
   __module__t   __doc__R
   R'   R   t   classmethodR   R    R;   RS   RV   Rb   Rk   (    (    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyR	      s   	6	o	[(   Rm   t   loggingt   reRE   RD   t   email.utilsR    t   pip._vendor.requests.structuresR   R   R   t	   serializeR   t	   getLoggerR1   R-   t   compileR   R   t   objectR	   (    (    (    sq   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.pyt   <module>   s   		