
    ]j)                     <   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 d dlmZmZ d d	lmZ d d
lmZ 	 d dlZ G d d      Z G d de      Z e       Z G d de      Ze	j>                  Z  G d dejB                        Z"y# e$ r dZY Rw xY w)    )OrderedDict)joinnormpath)settings)findersstorage)Warning)get_storage_class)
LazyObject)gettext_lazyngettext)panels)ThreadCollectorNc                   (    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     J/root/env/lib/python3.12/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   c                         e Zd Zd fd	Z xZS )FileCollectorc                 \    |j                  d      ry t        | 	  t        |      |       y )N/)endswithsupercollectr   )r   r   thread	__class__s      r   r.   zFileCollector.collect'   s%    ==
4(&1r   r   )r#   r$   r%   r.   __classcell__r0   s   @r   r)   r)   &   s    2 2r   r)   c                       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                 n    t        t        j                        } G d d|      } |t              | _        y )Nc                   (     e Zd Z fdZ fdZ xZS )>DebugConfiguredStorage._setup.<locals>.DebugStaticFilesStoragec                 2    t        |   |i | || _        y r   )r-   r   	collector)r   r9   argskwargsr0   s       r   r   zGDebugConfiguredStorage._setup.<locals>.DebugStaticFilesStorage.__init__=   s     $1&1!*r   c                 X    | j                   j                  |       t        |   |      S r   )r9   r.   r-   r"   )r   r   r0   s     r   r"   zBDebugConfiguredStorage._setup.<locals>.DebugStaticFilesStorage.urlA   s$    &&t,w{4((r   )r#   r$   r%   r   r"   r1   r2   s   @r   DebugStaticFilesStorager7   <   s    +) )r   r=   )r
   r   STATICFILES_STORAGEr9   _wrapped)r   configured_storage_clsr=   s      r   _setupzDebugConfiguredStorage._setup8   s.    !283O3O!P	)&< 	) 0	:r   N)r#   r$   r%   r&   rA   r'   r   r   r4   r4   1   s    ;r   r4   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)_rE   rF   r   s    r   titlezStaticFilesPanel.titleS   s)    HIM
 
 	
r   c                 @    t        |   |i | d| _        i | _        y )Nr   )r-   r   rE   _paths)r   r:   r;   r0   s      r   r   zStaticFilesPanel.__init__Z   s#    $)&)r   c                 *    t               t        _        y r   )r4   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_instrumentationb   s
    &7#r   c                 4    | j                         }|xr |d   S )NrF   )	get_stats)r   statss     r   rF   zStaticFilesPanel.num_usede   s     *z**r   c                 >    | j                   }t        dd|      d|iz  S )Nz%(num_used)s file usedz%(num_used)s files usedrF   )rF   __)r   rF   s     r   nav_subtitlezStaticFilesPanel.nav_subtitlel   s.    ==*,ExPT
 
 	
r   c                 J    t         j                          t        |   |      S r   )r9   clear_collectionr-   process_request)r   requestr0   s     r   rX   z StaticFilesPanel.process_requests   s    ""$w&w//r   c           	         t         j                         }|| j                  t        j                         <   | j                  | j                  t        |      || j                         | j                         | j                         d       y )N)rE   rF   staticfilesstaticfiles_appsstaticfiles_dirsstaticfiles_finders)r9   get_collectionrJ   	threadingcurrentThreadrecord_statsrE   lenget_staticfiles_appsget_staticfiles_dirsget_staticfiles_finders)r   rY   response
used_pathss       r   generate_statszStaticFilesPanel.generate_statsw   so    --/
1;I++-.!^^
O)$($=$=$?$($=$=$?'+'C'C'E		
r   c                    t               }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   r   get_finderslistgetattrr   rk   r0   r$   r#   r   
setdefaultappendrE   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$$	C0/C0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   rn   
isinstanceFileSystemFinderextend	locationsr   )r   dirsru   rk   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   rn   r|   AppDirectoriesFinderappsrr   )r   r   ru   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   rn   ro   r   rs   rr   r	   )clserrorsru   r   rv   s        r   
run_checkszStaticFilesPanel.run_checks   s     ))+ 	F
,2KKO .(D."''-.	   [Z;s   *A		&A21A2)r#   r$   r%   r&   nametemplatepropertyrH   r   rL   rO   rF   rG   	nav_titlerU   rX   ri   rf   re   rd   classmethodr   r1   r2   s   @r   rC   rC   K   s     D6H
 

?8 + + .!I
 
0
2A
  r   rC   )#collectionsr   os.pathr   r   django.confr   django.contrib.staticfilesr   r   django.core.checksr	   django.core.files.storager
   django.utils.functionalr   django.utils.translationr   rG   r   rT   debug_toolbarr   debug_toolbar.utilsr   r`   ImportErrorr   r)   r9   r4   r!   rN   PanelrC   r'   r   r   <module>r      s    # "   7 & 7 . F   /
: :$2O 2 O	;Z ;. // @v|| @w  Is   B BB