B
    `R                 @   s   d dl Z y$d dlmZ eddZeddZW n   dZdZY nX d dlmZ d dlmZm	Z	 d dl
mZmZmZ G d	d
 d
eZG dd deZdd Zdd ZdS )    N)StackedObjectProxyzBeaker Session)namezCache Manager)CacheManager)SessionSessionObject)coerce_cache_paramscoerce_session_paramsparse_cache_config_optionsc               @   s"   e Zd ZeZdddZdd ZdS )CacheMiddlewareNbeaker.cachec             K   sl   || _ |pi }i | _| jt| | jt|dd | jsH|rH|| _| j| tf | j| _|| _dS )a  Initialize the Cache Middleware

        The Cache middleware will make a CacheManager instance available
        every request under the ``environ['beaker.cache']`` key by
        default. The location in environ can be changed by setting
        ``environ_key``.

        ``config``
            dict  All settings should be prefixed by 'cache.'. This
            method of passing variables is intended for Paste and other
            setups that accumulate multiple component settings in a
            single dictionary. If config contains *no cache. prefixed
            args*, then *all* of the config options will be used to
            intialize the Cache objects.

        ``environ_key``
            Location where the Cache instance will keyed in the WSGI
            environ

        ``**kwargs``
            All keyword arguments are assumed to be cache settings and
            will override any settings found in ``config``

        F)Zinclude_defaultsN)appoptionsupdater	   r   cache_managerenviron_key)selfr   configr   kwargs r   Y/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/beaker/middleware.py__init__   s    
zCacheMiddleware.__init__c             C   s@   | dr(|d jr(|d | j| j | j|| j< | ||S )Nzpaste.registry)getreglistregistercacher   r   r   )r   environstart_responser   r   r   __call__C   s    

zCacheMiddleware.__call__)Nr   )__name__
__module____qualname__beaker_cacher   r   r   r   r   r   r   r
      s   
/r
   c               @   s*   e Zd ZeZd	ddZdd Zdd ZdS )
SessionMiddlewareNbeaker.sessionc          
   K   s   |pi }t ddddddddd| _x||gD ]|}xv| D ]j\}}|dr^|| j|dd < |drz|| j|dd < |d	r:td
td || j|dd < q:W q,W t| j | js|r|| _| j| | | _	| _
|| _dS )a  Initialize the Session Middleware

        The Session middleware will make a lazy session instance
        available every request under the ``environ['beaker.session']``
        key by default. The location in environ can be changed by
        setting ``environ_key``.

        ``config``
            dict  All settings should be prefixed by 'session.'. This
            method of passing variables is intended for Paste and other
            setups that accumulate multiple component settings in a
            single dictionary. If config contains *no session. prefixed
            args*, then *all* of the config options will be used to
            intialize the Session objects.

        ``environ_key``
            Location where the Session instance will keyed in the WSGI
            environ

        ``**kwargs``
            All keyword arguments are assumed to be session settings and
            will override any settings found in ``config``

        TNzbeaker.session.id)Zinvalidate_corrupttypedata_dirkeytimeoutZsave_accessed_timesecretZlog_filezbeaker.session.   zsession.   Zsession_z?Session options should start with session. instead of session_.   )dictr   items
startswithwarningswarnDeprecationWarningr   r   wrap_appr   r   )r   r2   r   r   r   dctr&   valr   r   r   r   O   s*    





zSessionMiddleware.__init__c                s   t |f| j |dr4|d jr4|d | j   || j< | j|d< d|krld| jkrl |d | jd < d fdd	}| ||S )Nzpaste.registryzbeaker.get_sessionzpaste.testing_variablesZwebtest_varnamec                sJ      r>    jd d r> jd d }|r>|d|f | ||S )N_headers
set_cookieZ
cookie_outz
Set-cookie)ZaccessedZpersist__dict__append)statusheadersexc_infocookie)sessionr   r   r   session_start_response   s    z:SessionMiddleware.__call__.<locals>.session_start_response)N)	r   r   r   r   r   r=   r   _get_sessionr2   )r   r   r   r>   r   )r=   r   r   r      s    



zSessionMiddleware.__call__c             C   s   t i fddi| jS )NZuse_cookiesF)r   r   )r   r   r   r   r?      s    zSessionMiddleware._get_session)Nr#   )r   r   r    beaker_sessionr=   r   r   r?   r   r   r   r   r"   L   s   
:r"   c                s    fdd}|S )Nc                s   t |  fS )N)r"   )r   )global_confr   r   r   filter   s    z&session_filter_factory.<locals>.filterr   )rA   r   rB   r   )rA   r   r   session_filter_factory   s    rC   c             K   s   t | |f|S )N)r"   )r   rA   r   r   r   r   session_filter_app_factory   s    rD   )r/   Zpaste.registryr   r@   r!   Zbeaker.cacher   Zbeaker.sessionr   r   Zbeaker.utilr   r   r	   objectr
   r"   rC   rD   r   r   r   r   <module>   s   

;V