
0c@_                 @   s   d  d l  Z  d  d l Z d  d l m Z m Z m Z d  d l m Z m Z d Z d d d  Z	 d d   Z
 Gd	 d
   d
 e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z d S)    N)
formatdate	parsedateparsedate_tz)datetime	timedeltaz%a, %d %b %Y %H:%M:%S GMTc             C   s   | p t  j   } | |  S)N)r   utcnow)deltadate r
   B/tmp/pip-build-jynh7p1z/pip/pip/_vendor/cachecontrol/heuristics.pyexpire_after   s    r   c             C   s   t  t j |  j     S)N)r   calendartimegm	timetuple)dtr
   r
   r   datetime_to_header   s    r   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)BaseHeuristicc             C   s   d S)a!  
        Return a valid 1xx warning header value describing the cache
        adjustments.

        The response is provided too allow warnings like 113
        http://tools.ietf.org/html/rfc7234#section-5.5.4 where we need
        to explicitly say response is over 24 hours old.
        z110 - "Response is Stale"r
   )selfresponser
   r
   r   warning   s    	zBaseHeuristic.warningc             C   s   i  S)zUpdate the response headers with any new headers.

        NOTE: This SHOULD always include some Warning header to
              signify that the response was cached by the client, not
              by way of the provided headers.
        r
   )r   r   r
   r
   r   update_headers!   s    zBaseHeuristic.update_headersc             C   sZ   |  j  |  } | rV | j j |  |  j |  } | d  k	 rV | j j d | i  | S)NWarning)r   headersupdater   )r   r   Zupdated_headersZwarning_header_valuer
   r
   r   apply*   s    zBaseHeuristic.applyN)__name__
__module____qualname__r   r   r   r
   r
   r
   r   r      s   	r   c               @   s"   e  Z d  Z d Z d d   Z d S)OneDayCachezM
    Cache the response by providing an expires 1 day in the
    future.
    c             C   sq   i  } d | j  k rm t | j  d  } t t d d  d t | d  d    } t |  | d <d | d <| S)Nexpiresr	   days      publiczcache-control)r   r   r   r   r   r   )r   r   r   r	   r   r
   r
   r   r   <   s    +
zOneDayCache.update_headersN)r   r   r   __doc__r   r
   r
   r
   r   r   6   s   r   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	ExpiresAfterz;
    Cache **all** requests for a defined time period.
    c             K   s   t  |   |  _ d  S)N)r   r   )r   kwr
   r
   r   __init__L   s    zExpiresAfter.__init__c             C   s%   t  |  j  } d t |  d d i S)Nr   zcache-controlr#   )r   r   r   )r   r   r   r
   r
   r   r   O   s    zExpiresAfter.update_headersc             C   s   d } | |  j  S)Nz:110 - Automatically cached for %s. Response might be stale)r   )r   r   tmplr
   r
   r   r   S   s    zExpiresAfter.warningN)r   r   r   r$   r'   r   r   r
   r
   r
   r   r%   G   s   r%   c               @   sU   e  Z d  Z d Z d d d d d d d d	 d
 d d h Z d d   Z d d   Z d S)LastModifieda  
    If there is no Expires header already, fall back on Last-Modified
    using the heuristic from
    http://tools.ietf.org/html/rfc7234#section-4.2.2
    to calculate a reasonable value.

    Firefox also does something like this per
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching_FAQ
    http://lxr.mozilla.org/mozilla-release/source/netwerk/protocol/http/nsHttpResponseHead.cpp#397
    Unlike mozilla we limit this to 24-hr.
                i,  i-  i  i  i  i  i  c       
      C   s7  | j  } d | k r i  Sd | k r9 | d d k r9 i  S| j |  j k rO i  Sd | k sg d | k rk i  St j t | d   } t | d  } | d  k s | d  k r i  St j   } t d | |  } | t j |  } t d t	 | d d
   } | | k ri  S| | }	 d t j
 t t j |	   i S)Nr   zcache-controlr#   r	   zlast-modifiedr   
      i  iQ )r   statuscacheable_by_default_statusesr   r   r   r   timemaxminstrftimeTIME_FMTgmtime)
r   respr   r	   Zlast_modifiednowcurrent_ager   freshness_lifetimer   r
   r
   r   r   h   s*    	
zLastModified.update_headersc             C   s   d  S)Nr
   )r   r8   r
   r
   r   r      s    zLastModified.warningN)r   r   r   r$   r1   r   r   r
   r
   r
   r   r)   X   s   'r)   )r   r2   email.utilsr   r   r   r   r   r6   r   r   objectr   r   r%   r)   r
   r
   r
   r   <module>   s   "