o
    QDi$                     @   sZ   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 G dd dZd	S )
    )ASGIRequest)render_to_string)classproperty)settings)GetResponse)get_name_from_objc                   @   s"  e Zd ZdZdZdefddZedef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/d0 Z d1d2 Z!d3d4 Z"ed5d6 Z#d7S )8Panelz 
    Base class for panels.
    Fget_responsec                 C   s   || _ || _d| _d S )NF)toolbarr	   
from_store)selfr
   r	    r   V/var/www/Datamplify/venv/lib/python3.10/site-packages/debug_toolbar/panels/__init__.py__init__   s   
zPanel.__init__returnc                 C      | j S )N)__name__clsr   r   r   panel_id   s   zPanel.panel_idc                 C   s|   | j st| jjtrdS | jrt|  S | jjj	d| j
 }|d ur(|dkS t d }t| }||vo=|dd|vS )NFdjdtonDISABLE_PANELSz.panel..)is_async
isinstancer
   requestr   r   bool	get_statsCOOKIESgetr   dt_settings
get_configr   replace)r   cookie_valuedisabled_panels
panel_pathr   r   r   enabled   s   zPanel.enabledc                 C   r   )zI
        Title shown in the side bar. Defaults to :attr:`title`.
        )titler   r   r   r   	nav_title<   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_subtitleC      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_contentJ   s   zPanel.has_contentc                 C   r   )zg
        Panel supports rendering historical values.

        Defaults to :attr:`has_content`.
        )r/   r)   r   r   r   is_historicalR   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(   [   s   zPanel.titlec                 C   r1   )z
        Template used to render :attr:`content`.

        Mandatory, unless the panel sets :attr:`has_content` to ``False`` or
        overrides :attr:`content`.
        r2   r)   r   r   r   templated   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   r4   r   r)   r   r   r   contentn   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   scriptsz   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   r   r   r   r   ready       zPanel.readyc                 C   r6   )zE
        Return URLpatterns, if the panel has its own views.
        r   r   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   r9   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   r9   zPanel.disable_instrumentationc                 C   s>   | j j| ji | | j j| j j| j| j j| j  dS )a  
        Store data gathered by the panel. ``stats`` is a :class:`dict`.

        Each call to ``record_stats`` updates the store's data for
        the panel.

        To support backwards compatibility, it will also update the
        panel's statistics dictionary.
        N)r
   stats
setdefaultr   updatestore
save_panel
request_id)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   r         zPanel.get_statsc                 C   s*   |||di}| j j| ji | dS )z
        Store data gathered by the panel. ``stats`` is a :class:`dict`.

        Each call to ``record_stats`` updates the statistics dictionary.
        )r(   valueN)r
   server_timing_statsr>   r   r?   )r   keyr(   rG   datar   r   r   record_server_timing   s   zPanel.record_server_timingc                 C   rD   rE   )r
   rH   r    r   r)   r   r   r   get_server_timing_stats   rF   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="{}"rG   r(   N)formatr   r    ).0rI   recordr)   r   r   	<genexpr>   s    
z$Panel.get_headers.<locals>.<genexpr>zServer-Timing)rL   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  r9   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   rV   r   r   r   generate_server_timing  r9   zPanel.generate_server_timingc                 C   s"   | j j| ji | d| _dS )za
        Instantiate the panel from serialized data.

        Return the panel instance.
        TN)r
   r=   r>   r   r?   r   )r   rJ   r   r   r   load_stats_from_store  s   
zPanel.load_stats_from_storec                 C   r6   )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   r   r   r   r   
run_checks"  s   
zPanel.run_checksN)$r   
__module____qualname____doc__r   r   r   r   strr   propertyr   r'   r*   r-   r/   r0   r(   r4   r5   r7   classmethodr8   r:   r;   r<   rC   r   rK   rL   rM   rU   rX   rY   rZ   r[   r   r   r   r   r   
   sR    





	



	
	r   N)django.core.handlers.asgir   django.template.loaderr   django.utils.functionalr   debug_toolbarr   r!   debug_toolbar._stubsr   debug_toolbar.utilsr   r   r   r   r   r   <module>   s    