o
    g                     @   s   d Z ddlZ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 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 ddlmZmZ ddlmZmZ G dd dZdd Z dS )zA
The main DebugToolbar class that loads and renders the Toolbar.
    N)OrderedDict)	lru_cache)apps)ImproperlyConfigured)Signal)TemplateSyntaxError)render_to_string)pathresolve)Resolver404import_string)get_languageoverride)APP_NAMEsettingsc                   @   s   e Zd Ze Zdd Zedd Zedd Zdd Z	d	d
 Z
dd Ze Zdd Zedd ZdZedd ZdZedd Zedd Zeedddd ZdS )DebugToolbarc                 C   s   || _ t  | _g }t|  D ]}|| |}|| |jr$|j	}q|| _	t
 | _|r:| }|| j|j< |s.i | _i | _d | _| jj|| d d S )N)toolbar)requestdt_settings
get_configcopyconfigreversedget_panel_classesappendenabledprocess_requestr   _panelspoppanel_idstatsserver_timing_statsstore_id_createdsend)selfr   get_responsepanelspanel_classpanel r+   U/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/debug_toolbar/toolbar.py__init__   s&   

zDebugToolbar.__init__c                 C   s   t | j S )z5
        Get a list of all available panels.
        )listr   valuesr&   r+   r+   r,   r(   2   s   zDebugToolbar.panelsc                 C   s   dd | j  D S )zG
        Get a list of panels enabled for the current request.
        c                 S   s   g | ]}|j r|qS r+   )r   ).0r*   r+   r+   r,   
<listcomp>>   s    z/DebugToolbar.enabled_panels.<locals>.<listcomp>)r   r/   r0   r+   r+   r,   enabled_panels9   s   zDebugToolbar.enabled_panelsc                 C   s
   | j | S )zV
        Get the panel with the given id, which is the class name by default.
        )r   )r&   r    r+   r+   r,   get_panel_by_id@   s   
zDebugToolbar.get_panel_by_idc                 C   s   |   s|   z)d| i}| jd pt }t| td|W  d   W S 1 s*w   Y  W dS  tyC   tdsBt	dd w )zA
        Renders the overall Toolbar with panels inside.
        r   TOOLBAR_LANGUAGEzdebug_toolbar/base.htmlNzdjango.contrib.staticfileszThe debug toolbar requires the staticfiles contrib app. Add 'django.contrib.staticfiles' to INSTALLED_APPS and define STATIC_URL in your settings.)
should_render_panelsstorer   r   lang_overrider   r   r   is_installedr   )r&   contextlangr+   r+   r,   render_toolbarH   s"   
(
zDebugToolbar.render_toolbarc                 C   s&   | j d  }du r| jjdd}|S )zDetermine whether the panels should be rendered during the request

        If False, the panels will be loaded via Ajax.
        RENDER_PANELSNzwsgi.multiprocessT)r   r   METAget)r&   render_panelsr+   r+   r,   r6   ]   s   z!DebugToolbar.should_render_panelsc                 C   sP   | j rd S t j| _ | | j| j < t| jd t| jD ]	}| jjdd qd S )NRESULTS_CACHE_SIZEF)last)	r#   uuiduuid4hex_storeranger   lenpopitem)r&   _r+   r+   r,   r7   o   s   zDebugToolbar.storec                 C   s   | j |S )N)rF   r?   )clsr#   r+   r+   r,   fetchx   s   zDebugToolbar.fetchNc                 C   s(   | j d u rdd t D }|| _ | j S )Nc                 S   s   g | ]}t |qS r+   r   )r1   
panel_pathr+   r+   r,   r2      s    z2DebugToolbar.get_panel_classes.<locals>.<listcomp>)_panel_classesr   
get_panels)rK   panel_classesr+   r+   r,   r      s   
zDebugToolbar.get_panel_classesc                 C   sN   | j d u r$ddlm} td|jddg}|  D ]}|| 7 }q|| _ | j S )N   )viewszrender_panel/render_panel)name)_urlpatterns rR   r	   rS   r   get_urls)rK   rR   urlpatternsr)   r+   r+   r,   rW      s   
zDebugToolbar.get_urlsc                 C   sH   z|j pt|jt|dd}W n
 ty   Y dS w |jo#|jd tkS )zF
        Determine if the request is for a DebugToolbar view.
        urlconfNF)resolver_matchr
   r	   getattrr   
namespacesr   )rK   r   r[   r+   r+   r,   is_toolbar_request   s   zDebugToolbar.is_toolbar_request)maxsizec                  C   s"   t  d } t| trt| S | S )NOBSERVE_REQUEST_CALLBACK)r   r   
isinstancestrr   )func_or_pathr+   r+   r,   get_observe_request   s   
z DebugToolbar.get_observe_request)__name__
__module____qualname__r   r$   r-   propertyr(   r3   r4   r<   r6   r   rF   r7   classmethodrL   rN   r   rU   rW   r^   staticmethodr   rd   r+   r+   r+   r,   r      s2    

	

	

r   c                 C   s   t |  S )zM
    Determine whether to update the toolbar from a client side request.
    )r   r^   )r   r+   r+   r,   observe_request   s   rk   )!__doc__rC   collectionsr   	functoolsr   django.appsr   django.core.exceptionsr   django.dispatchr   django.templater   django.template.loaderr   django.urlsr	   r
   django.urls.exceptionsr   django.utils.module_loadingr   django.utils.translationr   r   r8   debug_toolbarr   r   r   r   rk   r+   r+   r+   r,   <module>   s"     #