B
    ì¹`  ã               @   sì   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZmZmZmZ dZG d	d
„ d
eƒZdd„ Zd#dd„Zdd„ Zeddddd„ ƒZedddeddddd„ ƒƒZe
dƒZe
dƒZeddd d!„ ƒZd"S )$é    )ÚOrderedDict)ÚConfigurator)Ú	Interface)Úview_config)ÚjsonÚtext_)Ú	IPanelMap)ÚROOT_ROUTE_NAMEÚSETTINGS_PREFIXÚSTATIC_PATHÚget_setting)z#pyramid_debugtoolbar.panels.headersz)pyramid_debugtoolbar.panels.introspectionz"pyramid_debugtoolbar.panels.loggerz'pyramid_debugtoolbar.panels.performancez&pyramid_debugtoolbar.panels.renderingsz(pyramid_debugtoolbar.panels.request_varsz"pyramid_debugtoolbar.panels.routesz#pyramid_debugtoolbar.panels.sessionz$pyramid_debugtoolbar.panels.settingsz pyramid_debugtoolbar.panels.sqlaz%pyramid_debugtoolbar.panels.tracebackz"pyramid_debugtoolbar.panels.tweensz$pyramid_debugtoolbar.panels.versionsc               @   s   e Zd ZdZdS )ÚIParentActionszC Marker interface for registered parent actions in the toolbar app.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úh/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid_debugtoolbar/toolbar_app.pyr       s   r   c             C   s"  t | d}||j_|j tƒ t¡ | dt¡ | dt¡ | 	d¡ |j
ddd |jdd	„ d
dd |jdd	„ ddd | dt¡ |jtddd | dd¡ | dd¡ | dd¡ | dd¡ | t¡ xtD ]}| 	|¡ qÖW | ¡  |  td d¡}x|D ]}| 	|¡ qW | ¡ S )z2 WSGI application for rendering the debug toolbar.)ÚsettingsÚadd_debugtoolbar_panelÚinject_parent_actionZpyramid_makoz.dbtmakozdbtmako.)Zsettings_prefixc             S   s   | j  d¡S )NÚ
request_id)Ú	matchdictÚget)Úrr   r   r   Ú<lambda>0   ó    z"make_toolbar_app.<locals>.<lambda>Zpdtb_idT)Zreifyc             S   s
   | j jjS )N)ÚregistryÚparent_registryÚpdtb_history)r   r   r   r   r   5   r   r   Ústaticú/)r    zdebugtoolbar.ssez/ssezdebugtoolbar.redirectz	/redirectzdebugtoolbar.requestz/{request_id}zdebugtoolbar.mainÚincludesr   )r   r   r   ÚregisterUtilityr   r   Zadd_directiver   r   ÚincludeZadd_mako_rendererZadd_request_methodZadd_static_viewr   Z	add_router	   Úscanr   Úbundled_includesÚcommitr   r
   Zmake_wsgi_app)r   r   Úconfigr$   r"   r   r   r   Úmake_toolbar_app$   s:    




r)   Fc             C   s,   |   |¡}|j}| j t¡}||||f< dS )aA  
    Register a new panel into the debugtoolbar.

    This is a Pyramid config directive that is accessible as
    ``config.add_debugtoolbar_panel`` within the debugtoolbar application.
    It should be used from ``includeme`` functions via the
    ``debugtoolbar.includes`` setting.

    The ``panel_class`` should be a subclass of
    :class:`pyramid_debugtoolbar.panels.DebugPanel`.

    If ``is_global`` is ``True`` then the panel will be added to the global
    panel list which includes application-wide panels that do not depend
    on per-request data to operate.

    N)Zmaybe_dottedÚnamer   Z
getUtilityr   )r(   Zpanel_classÚ	is_globalr*   Z	panel_mapr   r   r   r   O   s    
r   c             C   s4   | j  t¡}|dkr&g }| j  |t¡ | |¡ dS )a   
    Inject an action into the parent application.

    This is a Pyramid config directive that is accessible as
    ``config.inject_parent_action`` within the debugtoolbar application.
    It should be used from ``includeme`` functions via the
    ``debugtoolbar.includes`` setting.

    The ``action`` should be a callable that accepts the parent app's
    ``config`` object. It will be executed after the parent app is created
    to ensure that configuration is set prior to the actions being executed.

    N)r   ZqueryUtilityr   r#   Úappend)r(   ÚactionÚactionsr   r   r   r   g   s
    r   zdebugtoolbar.redirectz/pyramid_debugtoolbar:templates/redirect.dbtmako)Ú
route_nameZrendererc             C   s   | j  d¡| j  d¡dœS )NÚredirect_toÚredirect_code)r0   r1   )Úparamsr   )Úrequestr   r   r   Úredirect_view|   s    
r4   zdebugtoolbar.mainz.pyramid_debugtoolbar:templates/toolbar.dbtmakozdebugtoolbar.requestc          	   C   sÜ   | j }y| d¡d }W n tk
r4   d }d }Y n
X |d }| j d|¡}| |d ¡}|rndd„ |jD ƒ| _|  t¡}|  	t
¡}t| jjdƒ}t| jjdƒ}	| |	¡}
|r²|jng ||||
|rÆ|jng |rÒ|jng |dœS )	Né   r   r   c             S   s   i | ]}||j “qS r   )r*   )Ú.0Zpanelr   r   r   ú
<dictcomp>    s   z request_view.<locals>.<dictcomp>Úbutton_styleÚmax_visible_requests)ÚpanelsÚstatic_pathÚ	root_pathr8   ÚhistoryÚdefault_active_panelsÚglobal_panelsr   )r   ÚlastÚ
IndexErrorr   r   r:   Ztoolbar_panelsZ
static_urlr   Z	route_urlr	   r   r   r   r>   r?   )r3   r=   Úlast_request_pairÚlast_request_idr   Útoolbarr;   r<   r8   r9   Zhist_toolbarsr   r   r   Úrequest_view‡   s4    	



rE   Ú z$id:{0}
event: new_request
data:{1}

zdebugtoolbar.sse)r/   c                sž   | j }d|_| j}t|_t| j d¡ƒ‰ t| j dd¡ƒ}t	| j
jdƒ}|rš| d¡d }|d }||ksš‡ fdd„| |¡D ƒ}|ršt |t |¡¡|_|S )	Nztext/event-streamr   zLast-Event-Idr   r9   r5   c                s.   g | ]&\}}|j r||jˆ |kr$d ndg‘qS )ÚactiverF   )Zvisibler   )r6   Ú_idrD   )Úactive_request_idr   r   ú
<listcomp>Ð   s   zsse.<locals>.<listcomp>)ÚresponseÚcontent_typer   ÚU_BLANKÚtextr   ÚGETr   Úheadersr   r   r   r@   ÚU_SSE_PAYLOADÚformatr   Údumps)r3   rK   r=   Zclient_last_request_idr9   rB   rC   Údatar   )rI   r   Ússe¾   s$    
rU   N)F)Úcollectionsr   Zpyramid.configr   Zpyramid.interfacesr   Zpyramid.viewr   Zpyramid_debugtoolbar.compatr   r   Zpyramid_debugtoolbar.toolbarr   Zpyramid_debugtoolbar.utilsr	   r
   r   r   r&   r   r)   r   r   r4   rE   rM   rQ   rU   r   r   r   r   Ú<module>   s.   +
	-