a
    Ig                     @   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
 | _|rr| }|| j|j< qXi | _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statsZserver_timing_statsstore_id_createdsend)selfr   Zget_responsepanelspanel_classpanel r+   Q/var/www/html/django/DPS/env/lib/python3.9/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>@       z/DebugToolbar.enabled_panels.<locals>.<listcomp>)r    r/   r0   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|   zPd| i}| jd p(t }t| td|W  d   W S 1 sT0    Y  W n* ty   tdst	ddn Y n0 dS )zA
        Renders the overall Toolbar with panels inside.
        r   Z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.
        ZRENDER_PANELSNzwsgi.multiprocessT)r   r   ZMETAget)r'   Z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 q8d S )NZRESULTS_CACHE_SIZEF)last)	r$   uuiduuid4hex_storeranger   lenpopitem)r'   _r+   r+   r,   r7   q   s    zDebugToolbar.storec                 C   s   | j |S )N)rB   r=   )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   )r1   Z
panel_pathr+   r+   r,   r2      s   z2DebugToolbar.get_panel_classes.<locals>.<listcomp>)_panel_classesr   Z
get_panels)rG   Zpanel_classesr+   r+   r,   r      s    
zDebugToolbar.get_panel_classesc                 C   sN   | j d u rHddlm} td|jddg}|  D ]}|| 7 }q0|| _ | j S )N   )viewszrender_panel/render_panel)name)_urlpatterns rK   r   rL   r   get_urls)rG   rK   Zurlpatternsr)   r+   r+   r,   rP      s    
zDebugToolbar.get_urlsc                 C   sH   z|j pt|jt|dd}W n ty2   Y dS 0 |joF|jd tkS )zF
        Determine if the request is for a DebugToolbar view.
        ZurlconfNF)resolver_matchr   r   getattrr   
namespacesr   )rG   r   rR   r+   r+   r,   is_toolbar_request   s    zDebugToolbar.is_toolbar_request)maxsizec                  C   s&   t  d } t| trt| S | S d S )NZOBSERVE_REQUEST_CALLBACK)r   r   
isinstancestrr   )Zfunc_or_pathr+   r+   r,   get_observe_request   s    
z DebugToolbar.get_observe_request)__name__
__module____qualname__r   r%   r-   propertyr(   r4   r5   r<   r6   r   rB   r7   classmethodrH   rI   r   rN   rP   rU   staticmethodr   rY   r+   r+   r+   r,   r      s0   

	

	

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    r`   	__debug__c                 C   s8   | st dn
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    
rh   )ra   )&__doc__rd   r?   collectionsr   	functoolsr   Zdjango.appsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.dispatchr   Zdjango.templater   Zdjango.template.loaderr	   Zdjango.urlsr
   r   r   r   Zdjango.urls.exceptionsr   Zdjango.utils.module_loadingr   Zdjango.utils.translationr   r   r8   Zdebug_toolbarr   r   r   r`   rh   r+   r+   r+   r,   <module>   s&    #