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 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$ ddl%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)cache)apps)settings)ImproperlyConfigured)ASGIRequest)Signal)TemplateSyntaxError)render_to_string)includepathre_pathresolve)Resolver404import_string)get_languageoverride)APP_NAMEr   )Panelc                   @   s   e Zd Ze Zdd Ze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 ZdS )DebugToolbarc                 C   s   || _ t  | _g }t|  D ]}|| |}|| |jr$|j	}q|| _	t
ttf  | _|r>| }|| j|j< |s2i | _i | _d | _| jj|| d d S )N)toolbar)requestdt_settings
get_configcopyconfigreversedget_panel_classesappendenabledprocess_requestr   strr   _panelspoppanel_idstatsserver_timing_statsstore_id_createdsend)selfr   get_responsepanelspanel_classpanel r0   u/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/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+   r0   r0   r1   r-   6   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 r0   )r    ).0r/   r0   r0   r1   
<listcomp>B   s    z/DebugToolbar.enabled_panels.<locals>.<listcomp>)r#   r4   r5   r0   r0   r1   enabled_panels=   s   zDebugToolbar.enabled_panelsc                 C   s   t | jddS )z
        Look up the Content Security Policy nonce if there is one.

        This is built specifically for django-csp, which may not always
        have a nonce associated with the request.
        	csp_nonceN)getattrr   r5   r0   r0   r1   r9   D   s   zDebugToolbar.csp_noncec                 C   s
   | j | S )zV
        Get the panel with the given id, which is the class name by default.
        )r#   )r+   r%   r0   r0   r1   get_panel_by_idN   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langr0   r0   r1   render_toolbarV   s"   
(
zDebugToolbar.render_toolbarc                 C   s:   | j d  }du rt| jtrd}|S | 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_PANELSNFzwsgi.multiprocessT)r   
isinstancer   r   METAget)r+   render_panelsr0   r0   r1   r=   k   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+   _r0   r0   r1   r>      s   zDebugToolbar.storec                 C   s   | j |S )N)rN   rG   )clsr(   r0   r0   r1   fetch   s   zDebugToolbar.fetchNc                 C   s(   | j d u rdd t D }|| _ | j S )Nc                 S   s   g | ]}t |qS r0   r   )r6   
panel_pathr0   r0   r1   r7      s    z2DebugToolbar.get_panel_classes.<locals>.<listcomp>)_panel_classesr   
get_panels)rS   panel_classesr0   r0   r1   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 rZ   r   r[   r   get_urls)rS   rZ   urlpatternsr.   r0   r0   r1   r_      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   	path_infor:   r   
namespacesr   )rS   r   rc   r0   r0   r1   is_toolbar_request   s   zDebugToolbar.is_toolbar_requestc                  C   s"   t  d } t| trt| S | S )NOBSERVE_REQUEST_CALLBACK)r   r   rE   r"   r   )func_or_pathr0   r0   r1   get_observe_request   s   
z DebugToolbar.get_observe_request)__name__
__module____qualname__r   r)   r2   propertyr-   r8   r9   r;   rC   r=   r   rN   r>   classmethodrT   rV   r   r]   r_   rf   staticmethodr   ri   r0   r0   r0   r1   r      s6    


		

	

r   c                 C   s   dS )zM
    Determine whether to update the toolbar from a client side request.
    Tr0   )r   r0   r0   r1   observe_request   s   rp   	__debug__c                 C   s8   | 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^{}//zdebug_toolbar.urls)	r   r   DEBUGr   formatreescapelstripr   )prefixr0   r0   r1   debug_toolbar_urls   s   ry   )rq   )*__doc__ru   rK   collectionsr   	functoolsr   django.appsr   django.confr   django.core.exceptionsr   django.core.handlers.asgir   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   debug_toolbar.panelsr   r   rp   ry   r0   r0   r0   r1   <module>   s,     3