B
    `t                 @   sl   d Z ddlZG dd deZedZedZG dd deZG d	d
 d
eZ	G dd deZ
dd ZdS )z%
Represents the Cache-Control header
    Nc               @   sZ   e Zd ZdZdZdZdd Zdd Zdd Zd	d
 Z	dd Z
dddZdd Zdd ZdS )
UpdateDictz1
    Dict that has a callback on all updates
    Nc             C   s.   | j }|dk	r*| j}|dkr"| f}||  dS )z=
        Assign to new_dict.updated to track updates
        N)updatedupdated_args)selfr   args r   Z/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/webob/cachecontrol.py_updated   s    zUpdateDict._updatedc             C   s   t | || |   d S )N)dict__setitem__r	   )r   keyitemr   r   r   r      s    zUpdateDict.__setitem__c             C   s   t | | |   d S )N)r
   __delitem__r	   )r   r   r   r   r   r      s    zUpdateDict.__delitem__c             C   s   t |  |   d S )N)r
   clearr	   )r   r   r   r   r   #   s    
zUpdateDict.clearc             O   s   t j| f|| |   d S )N)r
   updater	   )r   r   kwr   r   r   r   '   s    zUpdateDict.updatec             C   s"   t | ||}||kr|   |S )N)r
   
setdefaultr	   )r   r   valuevalr   r   r   r   +   s    zUpdateDict.setdefaultc             G   s   t j| f| }|   |S )N)r
   popr	   )r   r   vr   r   r   r   1   s    zUpdateDict.popc             C   s   t | }|   |S )N)r
   popitemr	   )r   r   r   r   r   r   6   s    
zUpdateDict.popitem)N)__name__
__module____qualname____doc__r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r      s   
r   z8([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?z[^a-zA-Z0-9._-]c               @   s4   e Zd ZdZdddZdddZdd Zd	d
 ZdS )exists_propertyzv
    Represents a property that either is listed in the Cache-Control
    header, or is not listed (has no value)
    Nc             C   s   || _ || _d S )N)proptype)r   r   r   r   r   r   __init__F   s    zexists_property.__init__c             C   s   |d kr| S | j |jkS )N)r   
properties)r   objr   r   r   r   __get__J   s    zexists_property.__get__c             C   sV   | j d k	r*| j |j kr*td| j| j f |r<d |j| j< n| j|jkrR|j| j= d S )Nz0The property %s only applies to %s Cache-Control)r   AttributeErrorr   r    )r   r!   r   r   r   r   __set__O   s    
zexists_property.__set__c             C   s   |  |d d S )NF)r$   )r   r!   r   r   r   
__delete__\   s    zexists_property.__delete__)N)N)r   r   r   r   r   r"   r$   r%   r   r   r   r   r   A   s
   

r   c               @   s4   e Zd ZdZdddZdddZdd Zd	d
 ZdS )value_propertyz
    Represents a property that has a value in the Cache-Control header.

    When no value is actually given, the value of self.none is returned.
    Nc             C   s   || _ || _|| _|| _d S )N)r   defaultnoner   )r   r   r'   r(   r   r   r   r   r   f   s    zvalue_property.__init__c             C   sB   |d kr| S | j |jkr8|j| j  }|d kr2| jS |S n| jS d S )N)r   r    r(   r'   )r   r!   r   r   r   r   r   r"   l   s    zvalue_property.__get__c             C   sr   | j d k	r*| j |j kr*td| j| j f || jkrL| j|jkrn|j| j= n"|dkrbd |j| j< n||j| j< d S )Nz0The property %s only applies to %s Cache-ControlT)r   r#   r   r'   r    )r   r!   r   r   r   r   r$   x   s    

zvalue_property.__set__c             C   s   | j |jkr|j| j = d S )N)r   r    )r   r!   r   r   r   r%      s    zvalue_property.__delete__)NNN)N)r   r   r   r   r   r"   r$   r%   r   r   r   r   r&   `   s
   

r&   c               @   s   e Zd ZdZeZdd Zed"ddZdd Z	e
d	d
ddZe
dddZedddZedddZe
dd
ddZe
dd
dZedZedZedddZedddZe
dddZe
dddZeZe
dddZe
dddZdd Zd d! ZdS )#CacheControlz
    Represents the Cache-Control header.

    By giving a type of ``'request'`` or ``'response'`` you can
    control what attributes are allowed (some Cache-Control values
    only apply to requests or responses).
    c             C   s   || _ || _d S )N)r    r   )r   r    r   r   r   r   r      s    zCacheControl.__init__Nc       	   	   C   s   |r|   }||_ni }xbt|D ]T}|d}|dpH|dpHd}|rpyt|}W n tk
rn   Y nX |||< q$W | ||d}|r|f|_|S )z
        Parse the header, returning a CacheControl object.

        The object is bound to the request or response object
        ``updates_to``, if that is given.
                 N)r   )update_dictr   token_refinditergroupint
ValueErrorr   )	clsheaderZ
updates_tor   propsmatchnamer   r!   r   r   r   parse   s"    
zCacheControl.parsec             C   s   dt |  S )Nz<CacheControl %r>)str)r   r   r   r   __repr__   s    zCacheControl.__repr__z	max-stale*request)r(   r   z	min-fresh)r   zonly-if-cachedpublicresponseprivatezno-cache)r(   zno-storezno-transformzmust-revalidatezproxy-revalidatezmax-agezs-maxagezstale-while-revalidatezstale-if-errorc             C   s
   t | jS )N)serialize_cache_controlr    )r   r   r   r   __str__   s    zCacheControl.__str__c             C   s   | j | j | jdS )z0
        Returns a copy of this object.
        )r   )	__class__r    copyr   )r   r   r   r   rD      s    zCacheControl.copy)NN)r   r   r   r   r   r-   r   classmethodr8   r:   r&   Z	max_stale	min_freshr   Zonly_if_cachedr=   r?   no_cacheno_storeZno_transformZmust_revalidateZproxy_revalidateZmax_ageZs_maxageZ	s_max_ageZstale_while_revalidateZstale_if_errorrB   rD   r   r   r   r   r)      s0   
r)   c             C   sx   t | tr| j} g }xXt|  D ]H\}}|d kr>|| q"t|}t|rXd| }|d||f  q"W d	|S )Nz"%s"z%s=%sz, )

isinstancer)   r    sorteditemsappendr9   need_quote_researchjoin)r    partsr7   r   r   r   r   rA      s    


rA   )r   rer
   r   compiler.   rM   objectr   r&   r)   rA   r   r   r   r   <module>   s   6
+P