
    7 f                         d dl Z d dl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 d dlmZ d dlmZmZ d d	lmZ  G d
 d      Z ed      Z G d de      Ze
j0                  Z G d dej4                        Zy)    N)
ContextVar)joinnormpath)settings)findersstorage)Warning)
LazyObject)gettext_lazyngettext)panelsc                   (    e Zd ZdZd Zd Zd Zd Zy)
StaticFilezA
    Representing the different properties of a static file.
    c                     || _         y Npath)selfr   s     V/var/www/equiseq/venv/lib/python3.11/site-packages/debug_toolbar/panels/staticfiles.py__init__zStaticFile.__init__   s	    	    c                     | j                   S r   r   r   s    r   __str__zStaticFile.__str__   s    yyr   c                 @    t        j                  | j                        S r   )r   findr   r   s    r   	real_pathzStaticFile.real_path   s    ||DII&&r   c                 T    t         j                  j                  | j                        S r   )r   staticfiles_storageurlr   r   s    r   r    zStaticFile.url   s    **..tyy99r   N)__name__
__module____qualname____doc__r   r   r   r     r   r   r   r      s    ':r   r   djdt_static_used_static_filesc                       e Zd ZdZd Zy)DebugConfiguredStoragez
    A staticfiles storage class to be used for collecting which paths
    are resolved by using the {% static %} template tag (which uses the
    `url` method).
    c                     	 ddl m} |d   j                  } G d d|      } |       | _        y # t        $ r ddl m}  |t
        j                        }Y ?w xY w)Nr   )storagesstaticfiles)get_storage_classc                        e Zd Z fdZ xZS )>DebugConfiguredStorage._setup.<locals>.DebugStaticFilesStoragec                     t        j                  t              5  t        j	                         j                  t        |             d d d        t        | !  |      S # 1 sw Y   xY wr   )	
contextlibsuppressLookupErrorused_static_filesgetappendr   superr    )r   r   	__class__s     r   r    zBDebugConfiguredStorage._setup.<locals>.DebugStaticFilesStorage.url9   sY    ((5 E
 &))+22:d3CDE w{4((E Es   -AA()r!   r"   r#   r    __classcell__r7   s   @r   DebugStaticFilesStorager.   8   s    ) )r   r:   )django.core.files.storager*   r7   ImportErrorr,   r   STATICFILES_STORAGE_wrapped)r   r*   configured_storage_clsr,   r:   s        r   _setupzDebugConfiguredStorage._setup+   s^    
	U ;%-m%<%F%F"	)&< 	) 01!  	UC%6x7S7S%T"		Us   / %AAN)r!   r"   r#   r$   r@   r%   r   r   r(   r(   $   s    2r   r(   c                        e Zd ZdZdZdZed        Z fdZd Z	d Z
ed        Z ed      Zed	        Z fd
Zd Zd Zd Zd Zed        Z xZS )StaticFilesPanelz3
    A panel to display the found staticfiles.
    zStatic filesz%debug_toolbar/panels/staticfiles.htmlc                 L    t        d      | j                  | j                  dz  S )Nz5Static files (%(num_found)s found, %(num_used)s used))	num_foundnum_used)_rD   rE   r   s    r   titlezStaticFilesPanel.titleP   s)    HIM
 
 	
r   c                 @    t        |   |i | d| _        g | _        y )Nr   )r6   r   rD   
used_paths)r   argskwargsr7   s      r   r   zStaticFilesPanel.__init__W   s#    $)&)r   c                 *    t               t        _        y r   )r(   r   r   r   s    r   enable_instrumentationz'StaticFilesPanel.enable_instrumentation\   s    &<&>#r   c                 "    t         t        _        y r   )_original_storager   r   r   s    r   disable_instrumentationz(StaticFilesPanel.disable_instrumentation_   s
    &7#r   c                 4    | j                         }|xr |d   S )NrE   )	get_stats)r   statss     r   rE   zStaticFilesPanel.num_usedb   s     *z**r   c                 >    | j                   }t        dd|      d|iz  S )Nz%(num_used)s file usedz%(num_used)s files usedrE   )rE   r   )r   rE   s     r   nav_subtitlezStaticFilesPanel.nav_subtitlei   s-    ==$&?
"# 	#r   c                     t         j                  g       }t        |   |      }t         j	                         j                         | _        t         j                  |       |S r   )r3   setr6   process_requestr4   copyrI   reset)r   requestreset_tokenresponser7   s       r   rX   z StaticFilesPanel.process_requestp   sR    '++B/7*73 ,//1668 	,r   c           	          | j                  | j                  t        | j                        | j                  | j	                         | j                         | j                         d       y )N)rD   rE   r+   staticfiles_appsstaticfiles_dirsstaticfiles_finders)record_statsrD   lenrI   get_staticfiles_appsget_staticfiles_dirsget_staticfiles_finders)r   r[   r]   s      r   generate_statszStaticFilesPanel.generate_stats{   sS    !^^0#$($=$=$?$($=$=$?'+'C'C'E		
r   c                    i }t        j                         D ]  }	 |j                  g       D ]  \  }}t        |dd      rt	        |j
                  |      }n|}|j                  }dj	                  |j                  |j                  g      }|j                  |      }||f}	|j                  |g       j                  |	       | xj                  dz  c_          |S # t        $ r Y w xY w)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   ri   r7   r"   r!   r   
setdefaultr5   rD   OSError)
r   finders_mappingfinderr   finder_storageprefixed_path
finder_clsfinder_pathr   payloads
             r   rf   z(StaticFilesPanel.get_staticfiles_finders   s     ))+ 	F,2KKO 
((D.~x>(,^-B-BD(I(,!'!1!1J"%((J,A,A:CVCV+W"XK . 3 3D 9I,i8G#..{B?FFwONNa'N
(	    s   B=C	C('C(c                     g }t        j                         D ]8  }t        |t         j                        s|j	                  |j
                         : |D cg c]  \  }}|t        |      f c}}S c c}}w )zP
        Returns a list of paths to inspect for additional static files
        )r   rl   
isinstanceFileSystemFinderextend	locationsr   )r   dirsrr   ri   dirs        r   re   z%StaticFilesPanel.get_staticfiles_dirs   sg     ))+ 	.F&'":":;F,,-	. <@@KFC#'@@@s   A2c                     g }t        j                         D ]D  }t        |t         j                        s|j                  D ]  }||vs|j                  |        F |S )zJ
        Returns a list of app paths that have a static directory
        )r   rl   ry   AppDirectoriesFinderappsr5   )r   r   rr   apps       r   rd   z%StaticFilesPanel.get_staticfiles_apps   s^     ))+ 	)F&'">">?!;; )C$C()	)
 r   c           	          g }t        j                         D ]-  }	 |j                  g       D ]  \  }}|j                  |        / |S # t        $ r  |j                  t        ddd             Y Zw xY w)z
        Check that the integration is configured correctly for the panel.

        Specifically look for static files that haven't been collected yet.

        Return a list of :class: `django.core.checks.CheckMessage` instances.
        zAdebug_toolbar requires the STATICFILES_DIRS directories to exist.z;Running manage.py collectstatic may help uncover the issue.zdebug_toolbar.staticfiles.W001)hintid)r   rl   rm   r   rp   r5   r	   )clserrorsrr   r   rs   s        r   
run_checkszStaticFilesPanel.run_checks   s     ))+ 	F
,2KKO .(D."''-.	   [Z;s   *A		&A21A2)r!   r"   r#   r$   nametemplatepropertyrG   r   rM   rP   rE   rF   	nav_titlerU   rX   rg   rf   re   rd   classmethodr   r8   r9   s   @r   rB   rB   H   s     D6H
 

?8 + + .!I# #	

2A
  r   rB   )r0   contextvarsr   os.pathr   r   django.confr   django.contrib.staticfilesr   r   django.core.checksr	   django.utils.functionalr
   django.utils.translationr   rF   r   debug_toolbarr   r   r3   r(   r   rO   PanelrB   r%   r   r   <module>r      se     " "   7 & . @  : :& >? 2Z 2B // Dv|| Dr   