o
    >h                     @   s   d dl Z d dl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mZ G dd	 d	Zed
Ze ZG dd dZG dd dejZdS )    N)
ContextVar)joinnormpath)findersstorage)Signal)gettext_lazyngettext)panelsc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )
StaticFilezA
    Representing the different properties of a static file.
    c                C   s   || _ || _d S N)path_url)selfr   url r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/debug_toolbar/panels/staticfiles.py__init__   s   
zStaticFile.__init__c                 C      | j S r   )r   r   r   r   r   __str__      zStaticFile.__str__c                 C   s   t | jS r   )r   findr   r   r   r   r   	real_path   s   zStaticFile.real_pathc                 C   r   r   )r   r   r   r   r   r      r   zStaticFile.urlN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s    r   djdt_request_id_storec                       s   e Zd Z fddZ  ZS )URLMixinc                    s`   t  |}tt t }tj| t	t
||d|d W d    |S 1 s)w   Y  |S )N)r   r   )sender
staticfile
request_id)superr   
contextlibsuppressLookupErrorrequest_id_context_vargetrecord_static_file_signalsendr   str)r   r   r   r"   	__class__r   r   r   '   s   
zURLMixin.url)r   r   r   r   __classcell__r   r   r,   r   r   &   s    r   c                       s   e Zd ZdZdZdZdZedd Z fddZ	e
d	d
 Zdd Zdd Zdd Zedd ZedZedd Zdd Zdd Zdd Zdd Z  ZS )StaticFilesPanelz3
    A panel to display the found staticfiles.
    TzStatic filesz%debug_toolbar/panels/staticfiles.htmlc                 C   s   t d| j| jd S )Nz5Static files (%(num_found)s found, %(num_used)s used))	num_foundnum_used)_r0   r1   r   r   r   r   title@   s   zStaticFilesPanel.titlec                    s0   t  j|i | d| _g | _tt | _d S )Nr   )r#   r   r0   
used_pathsr+   uuiduuid4r"   )r   argskwargsr,   r   r   r   G   s   zStaticFilesPanel.__init__c                 C   s,   t jj} t|  vrtg| jR | _d S d S r   )r   staticfiles_storager-   r   mro	__bases__)clsr   r   r   readyM   s   zStaticFilesPanel.readyc                 K   s"   t  | jkr| j| d S d S r   )r'   r(   r"   r4   append)r   r    r!   r8   r   r   r   "_store_static_files_signal_handlerS   s   z3StaticFilesPanel._store_static_files_signal_handlerc                 C   s   t | j| _t| j d S r   )r'   setr"   	ctx_tokenr)   connectr?   r   r   r   r   enable_instrumentation\   s   z'StaticFilesPanel.enable_instrumentationc                 C   s   t | j t| j d S r   )r)   
disconnectr?   r'   resetrA   r   r   r   r   disable_instrumentation`   s   z(StaticFilesPanel.disable_instrumentationc                 C   s   |   }|o	|d S )Nr1   )	get_stats)r   statsr   r   r   r1   d   s   zStaticFilesPanel.num_usedc                 C   s   | j }tdd|d|i S )Nz%(num_used)s file usedz%(num_used)s files usedr1   )r1   r	   )r   r1   r   r   r   nav_subtitlek   s   zStaticFilesPanel.nav_subtitlec              	   C   s2   |  | jt| j| j|  |  |  d d S )N)r0   r1   staticfilesstaticfiles_appsstaticfiles_dirsstaticfiles_finders)record_statsr0   lenr4   get_staticfiles_appsget_staticfiles_dirsget_staticfiles_finders)r   requestresponser   r   r   generate_statsr   s   zStaticFilesPanel.generate_statsc           
   	   C   s   i }t  D ]K}z@|g D ]8\}}t|ddrt|j|}n|}|j}d|j|jg}|	|}||f}	|
|g |	 |  jd7  _qW q tyQ   Y qw |S )z
        Returns a sorted mapping between the finder path and the list
        of relative and file system paths which that finder was able
        to find.
        prefixN.   )r   get_finderslistgetattrr   rV   r-   r   r   r   
setdefaultr>   r0   OSError)
r   finders_mappingfinderr   finder_storageprefixed_path
finder_clsfinder_pathr   payloadr   r   r   rR   ~   s$   
z(StaticFilesPanel.get_staticfiles_findersc                 C   s8   g }t  D ]}t|t jr||j qdd |D S )zP
        Returns a list of paths to inspect for additional static files
        c                 S   s   g | ]
\}}|t |fqS r   )r   ).0rV   dirr   r   r   
<listcomp>   s    z9StaticFilesPanel.get_staticfiles_dirs.<locals>.<listcomp>)r   rY   
isinstanceFileSystemFinderextend	locations)r   dirsr_   r   r   r   rQ      s   z%StaticFilesPanel.get_staticfiles_dirsc                 C   s@   g }t  D ]}t|t jr|jD ]}||vr|| qq|S )zJ
        Returns a list of app paths that have a static directory
        )r   rY   rh   AppDirectoriesFinderappsr>   )r   rn   r_   appr   r   r   rP      s   

z%StaticFilesPanel.get_staticfiles_apps)r   r   r   r   is_asyncnametemplatepropertyr3   r   classmethodr=   r?   rC   rF   r1   r2   	nav_titlerI   rU   rR   rQ   rP   r.   r   r   r,   r   r/   7   s,    

	


r/   )r$   r5   contextvarsr   os.pathr   r   django.contrib.staticfilesr   r   django.dispatchr   django.utils.translationr   r2   r	   debug_toolbarr
   r   r'   r)   r   Panelr/   r   r   r   r   <module>   s    