B
    `                  @   sd   d dl mZ d dlZd dlmZ d dlmZmZ dd Z	G dd de
ZG d	d
 d
eZdd ZdS )    )ISessionFactoryN)
DebugPanel)dictrepr	wrap_loadc             C   s   | S )N )xr   r   k/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid_debugtoolbar/panels/session.py<lambda>       r	   c               @   s   e Zd ZdS )NotInSessionN)__name__
__module____qualname__r   r   r   r   r   
   s   r   c               @   sP   e Zd ZdZdZdZedZeZdZ	e
dd ZdZd	d
 Zdd Zdd ZdS )SessionDebugPanelz9
    A panel to display Pyramid's ``ISession`` data.
    sessionz5pyramid_debugtoolbar.panels:templates/session.dbtmakoSessionTc             C   s   dS )a  
        This is too difficult to figure out under the following parameters:
        * do not trigger the ``ISession`` interface
        * The toolbar consults this attibute relatively early in the lifecycle
          to determine if ``.is_active`` should be ``True``
        Tr   )selfr   r   r   has_content   s    zSessionDebugPanel.has_contentNc          	   C   sn   ddt ddddi i tg tg dd | _}|| _y|jt}||d< W n tjj	j
k
rh   Y nX dS )z5
        Initial setup of the `data` payload
        N)prepanel_setupmain)ingressegresskeyschanged)configuration	is_activer   session_accessedsession_datar   )r   setdata_requestregistryZ
getUtilityr   zopeZ	interfaceZ
interfacesZComponentLookupError)r   requestr    configr   r   r   __init__&   s     zSessionDebugPanel.__init__c                s  | j  | jrd d< d| jjkr,d d d< | js>d| jjkrdy$| jj d d sdd d d< W n tk
rz   Y nX dk	rx6tD ]*\}}| d d	 |<  d d
 | qW d| jjkr| jjd=  fdd}| jj|ddd n fdd}t	| jd|dd |S )a  
        ``wrap_handler`` allows us to monitor the entire lifecycle of
        the  ``Request``.

        Instead of using this hook to create a new wrapped handler, we can just
        do the required analysis right here, and then invoke the original
        handler.

        Request | "ingress"
        Pre-process the ``Request`` if the panel is active, or if the
        ``Session`` has already been accessed, as the ``Request`` requires
        activating the ``Session`` interface.
        If pre-processing does not happen, the ``.session`` property will be
        replaced with a wrapped function which will invoke the ingress
        processing if the session is accessed.
        Tr   r   r   r   Nr   r   r   r   c                s   d d d< S )NTr   r   r   )r   )r    r   r   r   _session_accessed   s    z9SessionDebugPanel.wrap_handler.<locals>._session_accessed)namereifyc                sH   d d d< x6t | D ]*\}}| d d |<  d d | qW | S )NTr   r   r   r   r   )r   add)_sessionkv)r    r   r   _process_session_accessed   s
    zASessionDebugPanel.wrap_handler.<locals>._process_session_accessed)r)   )
r    r   r!   __dict__r   AttributeErrorr   r*   Zset_propertyr   )r   handlerr,   r-   r'   r.   r   )r    r   r   wrap_handlerD   s:    

	zSessionDebugPanel.wrap_handlerc             C   s   | j dkrdS | j}d}| js*d| j jkry|d d }| j j}W n tk
rV   Y nX |dk	r||d d< xlt|D ]`\}}||d d |< |d d | ||d d ks|d d | |krv|d d	 | qvW dS )
z
        ``Response`` | "egress"

        Only process the ``Response``` if the panel is active OR if the
        session was accessed, as processing the ``Response`` requires
        opening the session.
        Nr   r   r   r   r   r   r   r   )r!   r    r   r/   r   r0   r   r*   )r   responser    r   Z_accessed_mainr,   r-   r   r   r   process_response   s$    
z"SessionDebugPanel.process_response)r   r   r   __doc__r(   template_titleZ	nav_titleZuser_activatepropertyr   r!   r&   r2   r4   r   r   r   r   r      s   mr   c             C   s   |  t d S )N)Zadd_debugtoolbar_panelr   )r%   r   r   r   	includeme   s    r:   )Zpyramid.interfacesr   Zzope.interface.interfacesr#   Zpyramid_debugtoolbar.panelsr   Zpyramid_debugtoolbar.utilsr   r   r7   objectr   r   r:   r   r   r   r   <module>   s    J