U
    M}g                     @  sp   d dl mZ ddlmZ ddlmZ dd ZG dd deeZG d	d
 d
eeZG dd deZ	ddl
mZ dS )    )annotations   )ImmutableDictMixin)UpdateDictMixinc                   s2   t  fddfddfdddS )zReturn a new property object for a cache header. Useful if you
    want to add support for a cache extension in a subclass.

    .. versionchanged:: 2.0
        Renamed from ``cache_property``.
    c                   s   |   S N)_get_cache_valuexemptykeytype I/tmp/pip-unpacked-wheel-s46b54kd/werkzeug/datastructures/cache_control.py<lambda>       z(cache_control_property.<locals>.<lambda>c                   s   |   |S r   )_set_cache_value)r	   v)r   r   r   r   r      r   c                   s
   |   S r   )_del_cache_valuer   )r   r   r   r      r   zaccessor for )property)r   r   r   r   r
   r   cache_control_property   s    
r   c                   @  s   e Zd ZdZedddZeddeZeddeZ	edddZ
dd
dZdd Zdd Zdd Zdd Zdd Zdd ZeeZdS )_CacheControla  Subclass of a dict that stores values for a Cache-Control header.  It
    has accessors for all the cache-control directives specified in RFC 2616.
    The class does not differentiate between request and response directives.

    Because the cache-control directives in the HTTP header use dashes the
    python descriptors use underscores for that.

    To get a header of the :class:`CacheControl` object again you can convert
    the object into a string or call the :meth:`to_header` method.  If you plan
    to subclass it and add your own items have a look at the sourcecode for
    that class.

    .. versionchanged:: 2.1.0
        Setting int properties such as ``max_age`` will convert the
        value to an int.

    .. versionchanged:: 0.4

       Setting `no_cache` or `private` to boolean `True` will set the implicit
       none-value which is ``*``:

       >>> cc = ResponseCacheControl()
       >>> cc.no_cache = True
       >>> cc
       <ResponseCacheControl 'no-cache'>
       >>> cc.no_cache
       '*'
       >>> cc.no_cache = None
       >>> cc
       <ResponseCacheControl ''>

       In versions before 0.5 the behavior documented here affected the now
       no longer existing `CacheControl` class.
    zno-cache*Nzno-storezmax-agezno-transformr   c                 C  s$   t | |pd || _|d k	| _d S )Nr   )dict__init__	on_updateprovided)selfvaluesr   r   r   r   r   ?   s    z_CacheControl.__init__c                 C  s^   |t kr|| kS || krZ| | }|dkr,|S |dk	rVz||}W n tk
rT   Y nX |S dS +Used internally by the accessor properties.N)bool
ValueError)r   r   r   r   valuer   r   r   r   D   s    z_CacheControl._get_cache_valuec                 C  sn   |t kr$|rd| |< qj| |d nF|dkr:| |d n0|dkrLd| |< n|dk	rb||| |< n|| |< dS )r!   NT)r"   pop)r   r   r$   r   r   r   r   r   T   s    

z_CacheControl._set_cache_valuec                 C  s   || kr| |= dS r    r   )r   r   r   r   r   r   f   s    z_CacheControl._del_cache_valuec                 C  s
   t | S )z6Convert the stored values into a cache control header.)httpZdump_headerr   r   r   r   	to_headerk   s    z_CacheControl.to_headerc                 C  s   |   S r   )r(   r'   r   r   r   __str__o   s    z_CacheControl.__str__c                 C  s4   d dd t|  D }dt| j d| dS )N c                 s  s    | ]\}}| d |V  qdS )=Nr   ).0kr   r   r   r   	<genexpr>s   s     z)_CacheControl.__repr__.<locals>.<genexpr><>)joinsorteditemsr   __name__)r   Zkv_strr   r   r   __repr__r   s    z_CacheControl.__repr__)r   N)r4   
__module____qualname____doc__r   no_cacher"   no_storeintZmax_ageZno_transformr   r   r   r   r(   r)   r5   staticmethodZcache_propertyr   r   r   r   r      s   #
r   c                   @  s4   e Zd ZdZeddeZeddeZeddeZ	dS )RequestCacheControla  A cache control for requests.  This is immutable and gives access
    to all the request-relevant cache control headers.

    To get a header of the :class:`RequestCacheControl` object again you can
    convert the object into a string or call the :meth:`to_header` method.  If
    you plan to subclass it and add your own items have a look at the sourcecode
    for that class.

    .. versionchanged:: 2.1.0
        Setting int properties such as ``max_age`` will convert the
        value to an int.

    .. versionadded:: 0.5
       In previous versions a `CacheControl` class existed that was used
       both for request and response.
    z	max-staler   z	min-freshzonly-if-cachedN)
r4   r6   r7   r8   r   r;   Z	max_stale	min_freshr"   Zonly_if_cachedr   r   r   r   r=   y   s   r=   c                   @  sX   e Zd ZdZeddeZedddZeddeZeddeZ	edde
Zed	deZdS )
ResponseCacheControla  A cache control for responses.  Unlike :class:`RequestCacheControl`
    this is mutable and gives access to response-relevant cache control
    headers.

    To get a header of the :class:`ResponseCacheControl` object again you can
    convert the object into a string or call the :meth:`to_header` method.  If
    you plan to subclass it and add your own items have a look at the sourcecode
    for that class.

    .. versionchanged:: 2.1.1
        ``s_maxage`` converts the value to an int.

    .. versionchanged:: 2.1.0
        Setting int properties such as ``max_age`` will convert the
        value to an int.

    .. versionadded:: 0.5
       In previous versions a `CacheControl` class existed that was used
       both for request and response.
    publicNprivater   zmust-revalidatezproxy-revalidatezs-maxage	immutable)r4   r6   r7   r8   r   r"   r@   rA   Zmust_revalidateZproxy_revalidater;   Zs_maxagerB   r   r   r   r   r?      s   r?      )r&   N)
__future__r   Zmixinsr   r   r   r   r   r=   r?    r&   r   r   r   r   <module>   s   c