o
    >h!                     @   sB   d dl mZ d dlmZ d dlmZ d dlmZ G dd dZ	dS )    )ASGIRequest)render_to_string)settings)get_name_from_objc                   @   s  e Zd ZdZdZdd Zedd Zedefdd	Z	ed
d Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zed2d3 Zd4S )5Panelz 
    Base class for panels.
    Fc                 C   s   || _ || _d S N)toolbarget_response)selfr   r	    r   }/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/debug_toolbar/panels/__init__.py__init__   s   
zPanel.__init__c                 C   s   | j jS r   )	__class____name__r
   r   r   r   panel_id   s   zPanel.panel_idreturnc                 C   sj   | j st| jjtrdS | jjjd| j }|d ur|dkS t	 d }t
| }||vo4|dd|vS )NFdjdtonDISABLE_PANELSz.panel..)is_async
isinstancer   requestr   COOKIESgetr   dt_settings
get_configr   replace)r
   cookie_valuedisabled_panels
panel_pathr   r   r   enabled   s   zPanel.enabledc                 C      | j S )zI
        Title shown in the side bar. Defaults to :attr:`title`.
        )titler   r   r   r   	nav_title2   s   zPanel.nav_titlec                 C      dS )zO
        Subtitle shown in the side bar. Defaults to the empty string.
         r   r   r   r   r   nav_subtitle9      zPanel.nav_subtitlec                 C   r&   )z
        ``True`` if the panel can be displayed in full screen, ``False`` if
        it's only shown in the side bar. Defaults to ``True``.
        Tr   r   r   r   r   has_content@   s   zPanel.has_contentc                 C   r#   )zg
        Panel supports rendering historical values.

        Defaults to :attr:`has_content`.
        )r*   r   r   r   r   is_historicalH   s   zPanel.is_historicalc                 C      t )z
        Title shown in the panel when it's displayed in full screen.

        Mandatory, unless the panel sets :attr:`has_content` to ``False``.
        NotImplementedErrorr   r   r   r   r$   Q   s   zPanel.titlec                 C   r,   )z
        Template used to render :attr:`content`.

        Mandatory, unless the panel sets :attr:`has_content` to ``False`` or
        overrides :attr:`content`.
        r-   r   r   r   r   templateZ   s   zPanel.templatec                 C   s   | j rt| j|  S dS )z
        Content of the panel when it's displayed in full screen.

        By default this renders the template defined by :attr:`template`.
        Statistics stored with :meth:`record_stats` are available in the
        template's context.
        N)r*   r   r/   	get_statsr   r   r   r   contentd   s   	zPanel.contentc                 C      g S )a  
        Scripts used by the HTML content of the panel when it's displayed.

        When a panel is rendered on the frontend, the ``djdt.panel.render``
        JavaScript event will be dispatched. The scripts can listen for
        this event to support dynamic functionality.
        r   r   r   r   r   scriptsp   s   	zPanel.scriptsc                 C   r&   )a  
        Perform early initialization for the panel.

        This should only include initialization or instrumentation that needs to
        be done unconditionally for the panel regardless of whether it is
        enabled for a particular request.  It should be idempotent.
        Nr   clsr   r   r   ready}       zPanel.readyc                 C   r2   )zE
        Return URLpatterns, if the panel has its own views.
        r   r4   r   r   r   get_urls   r)   zPanel.get_urlsc                 C   r&   )aD  
        Enable instrumentation to gather data for this panel.

        This usually means monkey-patching (!) or registering signal
        receivers. Any instrumentation with a non-negligible effect on
        performance should be installed by this method rather than at import
        time.

        Unless the toolbar or this panel is disabled, this method will be
        called early in ``DebugToolbarMiddleware``. It should be idempotent.

        Add the ``aenable_instrumentation``  method to a panel subclass
        to support async logic for instrumentation.
        Nr   r   r   r   r   enable_instrumentation   r7   zPanel.enable_instrumentationc                 C   r&   )a  
        Disable instrumentation to gather data for this panel.

        This is the opposite of :meth:`enable_instrumentation`.

        Unless the toolbar or this panel is disabled, this method will be
        called late in the middleware. It should be idempotent.
        Nr   r   r   r   r   disable_instrumentation   r7   zPanel.disable_instrumentationc                 C   s   | j j| ji | dS )
        Store data gathered by the panel. ``stats`` is a :class:`dict`.

        Each call to ``record_stats`` updates the statistics dictionary.
        N)r   stats
setdefaultr   update)r
   r<   r   r   r   record_stats   s   zPanel.record_statsc                 C      | j j| ji S zK
        Access data stored by the panel. Returns a :class:`dict`.
        )r   r<   r   r   r   r   r   r   r0         zPanel.get_statsc                 C   s*   |||di}| j j| ji | dS )r;   )r$   valueN)r   server_timing_statsr=   r   r>   )r
   keyr$   rC   datar   r   r   record_server_timing   s   zPanel.record_server_timingc                 C   r@   rA   )r   rD   r   r   r   r   r   r   get_server_timing_stats   rB   zPanel.get_server_timing_statsc                 C   s
   |  |S )z
        Like __call__ in Django's middleware.

        Write panel logic related to the request there. Save data with
        :meth:`record_stats`.

        Return the existing response or overwrite it.
        )r	   )r
   r   r   r   r   process_request   s   
	zPanel.process_requestc                    s4   i }   }|rd fdd| D |d< |S )a  
        Get headers the panel needs to set.

        Called after :meth:`process_request
        <debug_toolbar.panels.Panel.generate_stats>` and
        :meth:`process_request<debug_toolbar.panels.Panel.generate_stats>`

        Header values will be appended if multiple panels need to set it.

        By default it sets the Server-Timing header.

        Return dict of headers to be appended.
        z, c              	   3   s2    | ]\}}d   j||d|dV  qdS )z{}_{};dur={};desc="{}"rC   r$   N)formatr   r   ).0rE   recordr   r   r   	<genexpr>   s    
z$Panel.get_headers.<locals>.<genexpr>zServer-Timing)rH   joinitems)r
   r   headersr<   r   r   r   get_headers   s   zPanel.get_headersc                 C   r&   )a*  
        Write panel logic related to the response there. Post-process data
        gathered while the view executed. Save data with :meth:`record_stats`.

        Called after :meth:`process_request
        <debug_toolbar.panels.Panel.process_request>`.


        Does not return a value.
        Nr   r
   r   responser   r   r   generate_stats   r7   zPanel.generate_statsc                 C   r&   )z
        Similar to :meth:`generate_stats
        <debug_toolbar.panels.Panel.generate_stats>`,

        Generate stats for Server Timing https://w3c.github.io/server-timing/

        Does not return a value.
        Nr   rR   r   r   r   generate_server_timing   r7   zPanel.generate_server_timingc                 C   r2   )a  
        Check that the integration is configured correctly for the panel.

        This will be called as a part of the Django checks system when the
        application is being setup.

        Return a list of :class:`django.core.checks.CheckMessage` instances.
        r   r4   r   r   r   
run_checks  s   
zPanel.run_checksN) r   
__module____qualname____doc__r   r   propertyr   boolr"   r%   r(   r*   r+   r$   r/   r1   r3   classmethodr6   r8   r9   r:   r?   r0   rG   rH   rI   rQ   rT   rU   rV   r   r   r   r   r      sP    






	



	
r   N)
django.core.handlers.asgir   django.template.loaderr   debug_toolbarr   r   debug_toolbar.utilsr   r   r   r   r   r   <module>   s
    