o
    ^"<f~(                     @   s  d dl Z d dl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 d dlmZmZmZ d dlmZ d d	lmZmZ d d
lmZ g ZG dd dZG dd deZG dd deZG dd deZG dd deZdddZdd Ze jdddd Z dS )    N)apps)settings)utils)Error)ImproperlyConfigured)FileSystemStorageStoragedefault_storage)	safe_join)
LazyObjectempty)import_stringc                   @   s*   e Zd ZdZdd Zd
ddZdd Zd	S )
BaseFinderzN
    A base file finder to be used for custom staticfiles finder classes.
    c                 K      t d)NzUsubclasses may provide a check() method to verify the finder is configured correctly.NotImplementedError)selfkwargs r   Y/var/www/html/kck/venv/lib/python3.10/site-packages/django/contrib/staticfiles/finders.pycheck   s   zBaseFinder.checkFc                 C   r   )z
        Given a relative file path, find an absolute file path.

        If the ``all`` parameter is False (default) return only the first found
        file path; if True, return a list of all found files paths.
        z5subclasses of BaseFinder must provide a find() methodr   )r   pathallr   r   r   find   s   zBaseFinder.findc                 C   r   )z
        Given an optional list of paths to ignore, return a two item iterable
        consisting of the relative path and storage instance.
        z5subclasses of BaseFinder must provide a list() methodr   )r   ignore_patternsr   r   r   list'   s   zBaseFinder.listNF)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s
    
	r   c                       sF   e Zd ZdZd fdd	Zdd Zddd	Zdd
dZdd Z  Z	S )FileSystemFinderz_
    A static files finder that uses the ``STATICFILES_DIRS`` setting
    to locate files.
    Nc                    s   g | _ i | _tjD ]}t|ttfr|\}}nd}||f| j vr(| j ||f q	| j D ]\}}t|d}||_	|| j|< q,t
 j|i | d S )N )location)	locationsstoragesr   STATICFILES_DIRS
isinstancer   tupleappendr   prefixsuper__init__)r   	app_namesargsr   rootr*   filesystem_storage	__class__r   r   r,   4   s   


zFileSystemFinder.__init__c                 K   s   g }t tjttfs|tdddd tjD ]6}t |ttfr4|\}}|dr4|td| dd tjrMt	j
tjt	j
|krM|td	d
d q|S )Nz4The STATICFILES_DIRS setting is not a tuple or list.z$Perhaps you forgot a trailing comma?zstaticfiles.E001)hintid/zHThe prefix %r in the STATICFILES_DIRS setting must not end with a slash.zstaticfiles.E003)r4   zHThe STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.zstaticfiles.E002)r'   r   r&   r   r(   r)   r   endswithSTATIC_ROOTosr   abspath)r   r   errorsr/   r*   r   r   r   r   F   s0   

 zFileSystemFinder.checkFc                 C   sR   g }| j D ]!\}}|tvrt| | |||}|r&|s!|  S || q|S )zW
        Look for files in the extra locations as defined in STATICFILES_DIRS.
        )r$   searched_locationsr)   find_location)r   r   r   matchesr*   r/   matched_pathr   r   r   r   _   s   

zFileSystemFinder.findc                 C   sN   |rd|t jf }||sdS |t|d }t||}t j|r%|S dS )z
        Find a requested static file in a location and return the found
        absolute path (or ``None`` if no match).
        z%s%sN)r8   sep
startswithlenr
   r   exists)r   r/   r   r*   r   r   r   r<   n   s   

zFileSystemFinder.find_locationc                 c   s<    | j D ]\}}| j| }t||D ]}||fV  qqdS )z2
        List all files in all locations.
        N)r$   r%   r   	get_files)r   r   r*   r/   storager   r   r   r   r   |   s   
zFileSystemFinder.listNr   )
r   r   r   r    r,   r   r   r<   r   __classcell__r   r   r1   r   r!   /   s    

r!   c                       sD   e Zd ZdZeZdZd fdd	Zdd Zdd	d
Z	dd Z
  ZS )AppDirectoriesFinderzu
    A static files finder that looks in the directory of each app as
    specified in the source_dir attribute.
    staticNc                    s   g | _ i | _t  } rt   fdd|D }|D ](}| tj|j| j}tj	|j
rC|| j|j< |j| j vrC| j |j qt j|i | d S )Nc                    s   g | ]	}|j  v r|qS r   )name).0acr-   r   r   
<listcomp>   s    z1AppDirectoriesFinder.__init__.<locals>.<listcomp>)r   r%   get_app_configssetstorage_classr8   r   join
source_dirisdirr#   rI   r)   r+   r,   )r   r-   r.   r   app_configs
app_configapp_storager1   rL   r   r,      s    zAppDirectoriesFinder.__init__c                 c   s<    | j  D ]}|drt||D ]}||fV  qqdS )z5
        List all files in all app storages.
        r"   N)r%   valuesrB   r   rC   )r   r   rD   r   r   r   r   r      s   
zAppDirectoriesFinder.listFc                 C   sX   g }| j D ]$}| j| j}|tvrt| | ||}|r)|s$|  S || q|S )z8
        Look for files in the app directories.
        )r   r%   r#   r;   r)   find_in_app)r   r   r   r=   appapp_locationmatchr   r   r   r      s   


zAppDirectoriesFinder.findc                 C   s8   | j |}|r||r||}|r|S dS dS dS )zL
        Find a requested static file in an app's static locations.
        N)r%   getrB   r   )r   rY   r   rD   r>   r   r   r   rX      s   
z AppDirectoriesFinder.find_in_apprE   r   )r   r   r   r    r   rP   rR   r,   r   r   rX   rF   r   r   r1   r   rG      s    
	rG   c                       s8   e Zd ZdZdZd
 fdd	ZdddZdd	 Z  ZS )BaseStorageFinderzZ
    A base static files finder to be used to extended
    with an own storage class.
    Nc                    sV   |d ur|| _ | j d u rtd| j t| j ttfs |   | _ t j|i | d S )NzHThe staticfiles storage finder %r doesn't have a storage class assigned.)rD   r   r2   r'   r   r   r+   r,   )r   rD   r.   r   r1   r   r   r,      s   

zBaseStorageFinder.__init__Fc                 C   sj   z| j d W n
 ty   Y g S w | j jtvr t| j j | j |r3| j |}|r1|g}|S g S )zL
        Look for files in the default file storage, if it's local.
        r"   )rD   r   r   r#   r;   r)   rB   )r   r   r   r[   r   r   r   r      s   	zBaseStorageFinder.findc                 c   s&    t | j|D ]}|| jfV  qdS )z0
        List all files of the storage.
        N)r   rC   rD   )r   r   r   r   r   r   r      s   zBaseStorageFinder.listrE   r   )	r   r   r   r    rD   r,   r   r   rF   r   r   r1   r   r]      s    
r]   c                       s$   e Zd ZdZeZ fddZ  ZS )DefaultStorageFinderzF
    A static files finder that uses the default storage backend.
    c                    s6   t  j|i | t| jdt}|std| j d S )Nbase_locationzOThe storage backend of the staticfiles finder %r doesn't have a valid location.)r+   r,   getattrrD   r   r   r2   )r   r.   r   r_   r1   r   r   r,      s   zDefaultStorageFinder.__init__)r   r   r   r    r	   rD   r,   rF   r   r   r1   r   r^      s    r^   Fc                 C   sl   g t dd< g }t D ] }|j| |d}|s|r|  S t|ttfs&|g}|| q|r0|S |r4g S dS )z
    Find a static file with the given path using all enabled finders.

    If ``all`` is ``False`` (default), return the first matching
    absolute path (or ``None`` if no match). Otherwise return a list.
    N)r   )r;   get_findersr   r'   r   r(   extend)r   r   r=   finderresultr   r   r   r     s   
r   c                  c   s    t jD ]} t| V  qd S rE   )r   STATICFILES_FINDERS
get_finder)finder_pathr   r   r   ra     s   
ra   )maxsizec                 C   s(   t | }t|tstd|tf | S )z
    Import the staticfiles finder class described by import_path, where
    import_path is the full Python path to the class.
    z%Finder "%s" is not a subclass of "%s")r   
issubclassr   r   )import_pathFinderr   r   r   rf     s   
rf   r   )!	functoolsr8   django.appsr   django.confr   django.contrib.staticfilesr   django.core.checksr   django.core.exceptionsr   django.core.files.storager   r   r	   django.utils._osr
   django.utils.functionalr   r   django.utils.module_loadingr   r;   r   r!   rG   r]   r^   r   ra   	lru_cacherf   r   r   r   r   <module>   s*    W?-

