o
    h                     @   s   d Z ddl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 ddlmZmZ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ddZ%dS )zA
The main DebugToolbar class that loads and renders the Toolbar.
    N)OrderedDict)	lru_cache)apps)settings)ImproperlyConfigured)Signal)TemplateSyntaxError)render_to_string)includepathre_pathresolve)Resolver404import_string)get_languageoverride)APP_NAMEr   c                   @   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-   S/var/www/html/ictaz-jobs/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*   4   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    r1   r2   r-   r-   r.   enabled_panels;   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_idB   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_toolbarJ   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.   r8   _   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.   r9   q   s   zDebugToolbar.storec                 C   s   | j |S )N)rH   rA   )clsr%   r-   r-   r.   fetchz   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   )r3   
panel_pathr-   r-   r.   r4      s    z2DebugToolbar.get_panel_classes.<locals>.<listcomp>)_panel_classesr   
get_panels)rM   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 rT   r   rU   r   get_urls)rM   rT   urlpatternsr+   r-   r-   r.   rY      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   )rM   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*   r5   r6   r>   r8   r   rH   r9   classmethodrN   rP   r   rW   rY   r`   staticmethodr   rf   r-   r-   r-   r.   r      s2    

	

	

r   c                 C   s   dS )zM
    Determine whether to update the toolbar from a client side request.
    Tr-   )r   r-   r-   r.   observe_request   s   rm   	__debug__c                 C   s6   | st dtjsg S tdt| d tdgS )a  
    Return a URL pattern for serving toolbar in debug mode.

    from django.conf import settings
    from debug_toolbar.toolbar import debug_toolbar_urls

    urlpatterns = [
        # ... the rest of your URLconf goes here ...
    ] + debug_toolbar_urls()
    zEmpty urls prefix not permittedz^%s//zdebug_toolbar.urls)r   r   DEBUGr   reescapelstripr
   )prefixr-   r-   r.   debug_toolbar_urls   s   ru   )rn   )&__doc__rq   rE   collectionsr   	functoolsr   django.appsr   django.confr   django.core.exceptionsr   django.dispatchr   django.templater   django.template.loaderr	   django.urlsr
   r   r   r   django.urls.exceptionsr   django.utils.module_loadingr   django.utils.translationr   r   r:   debug_toolbarr   r   r   rm   ru   r-   r-   r-   r.   <module>   s(     #