o
    QDi"                     @  sl  d Z ddlmZ ddl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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+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 e3e4Z5G dd dZ6d+ddZ7d,d!d"Z8G d#d$ d$e6Z9d-d.d)d*Z:dS )/zA
The main DebugToolbar class that loads and renders the Toolbar.
    )annotationsN)Callable)cache)apps)settings)ImproperlyConfigured)Signal)HttpRequest)TemplateSyntaxError)render_to_string)
URLPatternURLResolverincludepathre_pathresolve)Resolver404import_string)get_languageoverride)APP_NAMEr   )GetResponse)	BaseStore	get_store   )Panel)get_csp_noncec                   @  s   e Zd ZU e ZdZded< 	d2d3d
dZed4ddZ	ed4ddZ
ed5ddZd6ddZd7ddZd8ddZdd Ze	d2d9d!d"ZdZd#ed$< ed:d&d'ZdZd(ed)< ed;d+d,Zed<d-d.Zeed=d0d1ZdS )>DebugToolbarNr   storerequestr	   get_responser   
request_id
str | Nonec                 C  s   || _ t  | _g }t|  D ]}|| |}|| |jr$|j	}q|| _	dd t|D | _
i | _i | _|| _|   | jj|| d d S )Nc                 S  s   i | ]}|j |qS  panel_id.0panelr$   r$   N/var/www/Datamplify/venv/lib/python3.10/site-packages/debug_toolbar/toolbar.py
<dictcomp>7   s    z)DebugToolbar.__init__.<locals>.<dictcomp>)toolbar)r    dt_settings
get_configcopyconfigreversedget_panel_classesappendenabledprocess_request_panelsstatsserver_timing_statsr"   
init_store_createdsend)selfr    r!   r"   panelspanel_classr)   r$   r$   r*   __init__(   s    

zDebugToolbar.__init__returnlist[Panel]c                 C  s   t | j S )z5
        Get a list of all available panels.
        )listr6   valuesr<   r$   r$   r*   r=   @      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$   )r4   r'   r$   r$   r*   
<listcomp>L   s    z/DebugToolbar.enabled_panels.<locals>.<listcomp>)r6   rC   rD   r$   r$   r*   enabled_panelsG   s   zDebugToolbar.enabled_panelsc                 C  s
   t | jS )zL
        Look up the Content Security Policy nonce if there is one.
        )r   r    rD   r$   r$   r*   	csp_nonceN   s   
zDebugToolbar.csp_noncer&   strr   c                 C  s
   | j | S )zV
        Get the panel with the given id, which is the class name by default.
        )r6   )r<   r&   r$   r$   r*   get_panel_by_idU   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_panelsr9   r0   r   lang_overrider   r
   r   is_installedr   )r<   contextlangr$   r$   r*   render_toolbar]   s"   
(
zDebugToolbar.render_toolbarboolc                 C  s   | j d pdS )zDetermine whether the panels should be rendered during the request

        If False, the panels will be loaded via Ajax.
        RENDER_PANELSF)r0   rD   r$   r$   r*   rL   r   rE   z!DebugToolbar.should_render_panelsc                 C  s:   | j d u r	t | _ | jrd S t j| _| j | j d S N)r   r   r"   uuiduuid4hexsetrD   r$   r$   r*   r9   {   s   
zDebugToolbar.init_storeStoredDebugToolbar | Nonec                 C  s   t  |rtj||dS d S )Nr%   )r   existsStoredDebugToolbar
from_store)clsr"   r&   r$   r$   r*   fetch   s   zDebugToolbar.fetchzlist[Panel] | None_panel_classeslist[type[Panel]] | Nonec                 C  s(   | j d u rdd t D }|| _ | j S )Nc                 S  s   g | ]}t |qS r$   r   )r(   
panel_pathr$   r$   r*   rF      s    z2DebugToolbar.get_panel_classes.<locals>.<listcomp>)r_   r-   
get_panels)r]   panel_classesr$   r$   r*   r2      s   
zDebugToolbar.get_panel_classesz%list[URLPattern | URLResolver] | None_urlpatternslist[URLPattern | URLResolver]c                 C  sN   | j d u r$ddlm} td|jddg}|  D ]}|| 7 }q|| _ | j S )Nr   )viewszrender_panel/render_panel)name)rd    rf   r   rg   r2   get_urls)r]   rf   urlpatternsr>   r$   r$   r*   rj      s   
zDebugToolbar.get_urlsc                 C  sL   z|j pt|jt|dd}W n
 ty   Y dS w t|jo%|jd tkS )zF
        Determine if the request is for a DebugToolbar view.
        urlconfNF)resolver_matchr   	path_infogetattrr   rR   
namespacesr   )r]   r    rn   r$   r$   r*   is_toolbar_request   s   
zDebugToolbar.is_toolbar_requestr   c                  C  s"   t  d } t| trt| S | S )NOBSERVE_REQUEST_CALLBACK)r-   r.   
isinstancerI   r   )func_or_pathr$   r$   r*   get_observe_request   s   
z DebugToolbar.get_observe_requestrT   )r    r	   r!   r   r"   r#   )r@   rA   )r@   r#   )r&   rI   r@   r   )r@   rI   )r@   rR   )r"   rI   r&   r#   r@   rY   )r@   r`   )r@   re   r    r	   r@   rR   )r@   r   )__name__
__module____qualname__r   r:   r   __annotations__r?   propertyr=   rG   rH   rJ   rQ   rL   r9   classmethodr^   r_   r2   rd   rj   rr   staticmethodr   rv   r$   r$   r$   r*   r   #   s:   
 


	
		r   r    r	   r@   rR   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   HttpRequest | NoneNonec                 C  s   t d d S )Nzget_response was called for debug toolbar after being loaded from the store. No request exists in this scenario as the request is not stored, only the panel's data.)loggerwarningr   r$   r$   r*   from_store_get_response   s   r   c                   @  s,   e Zd Z	dddd	Ze	ddddZdS )r[   Nr    r   r!   r   r"   r#   c                 C  s8   d | _ t  | _|| _i | _i | _|| _| 	  d S rT   )
r    r-   r.   r/   r0   r5   r7   r8   r"   r9   )r<   r    r!   r"   r$   r$   r*   r?      s   zStoredDebugToolbar.__init__rI   r&   r@   c                 C  sl   t d t|d}i |_t|  D ]#}||t}|r|j|krq|j|j|j}|	| ||j|j< q|S )N)r"   )
r[   r   r6   r1   r2   r&   r   r)   r"   load_stats_from_store)r]   r"   r&   r,   r>   r)   datar$   r$   r*   r\      s   

zStoredDebugToolbar.from_storerT   )r    r   r!   r   r"   r#   )r"   rI   r&   r#   r@   r[   )rx   ry   rz   r?   r}   r\   r$   r$   r$   r*   r[      s    r[   	__debug__prefixrI   re   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   )r   r$   r$   r*   debug_toolbar_urls   s   r   rw   )r    r   r@   r   )r   )r   rI   r@   re   );__doc__
__future__r   loggingr   rU   collections.abcr   	functoolsr   django.appsr   django.confr   django.core.exceptionsr   django.dispatchr   django.httpr	   django.templater
   django.template.loaderr   django.urlsr   r   r   r   r   r   django.urls.exceptionsr   django.utils.module_loadingr   django.utils.translationr   r   rM   debug_toolbarr   r-   debug_toolbar._stubsr   debug_toolbar.storer   r   r=   r   utilsr   	getLoggerrx   r   r   r   r   r[   r   r$   r$   r$   r*   <module>   s<     
 
)
"