
    hD                        d dl Z d dlZd dlZd dlZd dlZd dlmZmZ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
e      Z G d d      Z G d de      Z G d dee      Z G d de      Z e       Zy)    N)unquote	urldefragurlsplit
urlunsplit)settings)check_settingsmatches_patterns)ImproperlyConfigured)ContentFile)FileSystemStorageget_storage_class)
LazyObjectc                   .     e Zd ZdZd fd	Z fdZ xZS )StaticFilesStoragez
    Standard file system storage for static files.

    The defaults for ``location`` and ``base_url`` are
    ``STATIC_ROOT`` and ``STATIC_URL``.
    c                     |t         j                  }|t         j                  }t        |       t	        |   ||g|i | |sd | _        d | _        y y N)r   STATIC_ROOT
STATIC_URLr   super__init__base_locationlocation)selfr   base_urlargskwargs	__class__s        e/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/django/contrib/staticfiles/storage.pyr   zStaticFilesStorage.__init__   s_    ++H**Hx 8=d=f= !%D DM     c                 P    | j                   st        d      t        |   |      S )NzaYou're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.)r   r
   r   path)r   namer   s     r   r!   zStaticFilesStorage.path$   s0    }}& (G H H w|D!!r   NN)__name__
__module____qualname____doc__r   r!   __classcell__r   s   @r   r   r      s    !" "r   r   c                        e Zd ZdZdZdZdZ fdZddZddZ	d fd	Z
dd	Zdd
ZddZd Zd Zd Zd Zd Z xZS )HashedFilesMixinz	url("%s")   ))z*.css)z#(url\(['"]{0,1}\s*(.*?)["']{0,1}\)))z(@import\s*["']\s*(.*?)["'])z@import url("%s")Tc                 h   t        |   |i | i | _        i | _        | j                  D ]  \  }}|D ]{  }t        |t        t        f      r|\  }}n| j                  }t        j                  |t        j                        }| j                  j                  |g       j                  ||f       }  y r   )r   r   	_patternshashed_filespatterns
isinstancetuplelistdefault_templaterecompile
IGNORECASE
setdefaultappend)	r   r   r   	extensionr0   patterntemplatecompiledr   s	           r   r   zHashedFilesMixin.__init__7   s    $)&)#'== 	VIx# Vgt}5(/%GX#44H::gr}}=)))R8??8@TUV	Vr   c                     |yt        j                         }|j                         D ]  }|j                  |        |j	                         dd S )zU
        Return a hash of the file with the given name and optional content.
        N   )hashlibmd5chunksupdate	hexdigest)r   r"   contentrA   chunks        r   	file_hashzHashedFilesMixin.file_hashD   sL     ?kkm^^% 	EJJu	}}s##r   c                 "   t        t        |            }|j                  j                         }|xr, t        t        |            j                  j                         xs |}|d u }|r5| j	                  |      st        d|d| d      	 | j                  |      }	 | j                  ||      }|r|j                          	 t        j                  j                  |      \  }}t        j                  j                  |      \  }	}
|rd|z  nd}t        j                  j                  ||	||
      }t        |      }||d<   d|v r|d   s|dxx   d	z  cc<   t        |      S # t        $ r |cY S w xY w# |r|j                          w w xY w)
Nz
The file 'z' could not be found with .z.%s    ?#   ?)r   r   r!   stripexists
ValueErroropenOSErrorrG   closeossplitsplitextjoinr3   r   )r   r"   rE   filenameparsed_name
clean_nameopenedrG   r!   rootexthashed_nameunparsed_names                r   r_   zHashedFilesMixin.hashed_nameO   sq    wt}- %%++-
I'(*;!<!A!A!G!G!IXjD;;x( PXZ^!_``))H-	 z7;Iz2hGG$$X.	c+4UY&"	ggll4$()S*: ;[)&a 4<a 0!#-(('    s   E( E9 (E65E69Fc                 ~   t         j                  r|s|d}}nEt        |      \  }}t        |      j                  j                  d      r|}n|f}|||fz  } || }t        |   |      }	d|v }
|s|
r?t        t        |	            }|r
|d   s||d<   |
r|d   s|dxx   dz  cc<   t        |      }	t        |	      S ):
        Return the non-hashed URL in DEBUG mode.
        rJ   /rL      rM   rK   rN   )r   DEBUGr   r   r!   endswithr   urlr3   r   r   )r   hashed_name_funcr"   forcer/   r_   fragmentr[   r   	final_urlquery_fragmenturlpartsr   s               r   _urlzHashedFilesMixin._urlp   s     >>%$("K#,T? J
#((11#6""}+\O+D.5GK,	 ~HY/0H&hqks""8,Iy!!r   c                 <    | j                  | j                  ||      S )rb   )rn   stored_name)r   r"   ri   s      r   rg   zHashedFilesMixin.url   s     yy))477r   c                 :      j                    fd}|S )zJ
        Return the custom URL converter for the given file name.
        c                 0   | j                         \  }}t        j                  d|      r|S |j                  d      r!|j                  t        j
                        s|S t        |      \  }}|j                  d      r>|j                  t        j
                        sJ |t        t        j
                        d }n^t        j                  dk(  r
n
j                  t        j                  d      }t        j                  t        j                  |      |      }j                  j                  t!        |      d	      }dj                  |j#                  d      dd |j#                  d      dd z         }|r|d|v rdnd|z   z  }t!        |      z  S )	z
            Convert the matched URL to a normalized and hashed URL.

            This requires figuring out which files the matched URL resolves
            to and calling the url() method of the storage.
            z^[a-z]+:rc   NT)ri   r/   rL   #)groupsr5   match
startswithr   r   r   lenrU   sepreplace	posixpathrX   dirnamern   _stored_namer   rV   )matchobjmatchedrg   url_pathrj   target_namesource_name
hashed_urltransformed_urlr/   r"   r   r<   s            r   	converterz1HashedFilesMixin.url_converter.<locals>.converter   sm    $??,LGS xxS) ~~c"3>>(:M:M+N "+3Hh""3'**8+>+>???&s8+>+>'?'@A ')ffmdbffc9R'nnY->->{-KXV !!7;#7 # J
 "hhx~~c':3B'?*BRBRSVBWXZX[B\'\]O DCKDSH#LL go666r   )r4   )r   r"   r/   r<   r   s   ```` r   url_converterzHashedFilesMixin.url_converter   s$     ,,H+	7Z r   c              +     K   |ryi }|D cg c]  }t        || j                        r| }}| j                  |||      D ]  \  }}}	}
|||	f  |D ci c]  }|||   
 }}t        | j                        D ]2  }d}| j                  |||      D ]  \  }}}	}|||	f |xs |} |r2 n rddt        d      f | j                  j                  |       yc c}w c c}w w)a  
        Post process the given dictionary of files (called from collectstatic).

        Processing is actually two separate operations:

        1. renaming files to include a hash of their content for cache-busting,
           and copying those files to the target storage.
        2. adjusting files which contain references to other files so they
           refer to the cache-busting filenames.

        If either of these are performed on a file, then that file is considered
        post-processed.
        NFAllz!Max post-process passes exceeded.)r	   r.   _post_processrangemax_post_process_passesRuntimeErrorr/   rC   )r   pathsdry_runoptionsr/   r!   adjustable_pathsr"   r_   	processed_isubstitutionssubsts                 r   post_processzHashedFilesMixin.post_process   s:       #
dnn5 
 
 04/A/A%IY[g/h 	/+D+y!Y..	/ 0@@tuT{"@@t334 	A!M7;7I7I%Qaco7p 73k9eK22 - 67 !	 |,OPPP 	  .1
 As"   
C&C*C&C!"AC&+;C&c           	   #     K   d }t        ||d      D ]  }d}||   \  }}|j                  |      5 }	| j                  |      }
| j                  |
      }||vr| j	                  ||	      }n||   }t        |	d      r|	j                  d       | j                  |      }d}||v r+|}|	j                         j                  d      }| j                  j                         D ]C  \  }}t        ||f      s|D ]+  \  }}| j                  |||      }	 |j                  ||      }- E |r| j!                  |       t#        |j%                               }| j&                  r| j)                  ||       | j	                  ||      }| j                  |      r| j!                  |       | j)                  ||      }| j                  |      }||k(  rd}d}|s'|s%d}| j)                  ||	      }| j                  |      }|||<   ||||f d d d         y # t        $ r}|d |df Y d }~3d }~ww xY w# 1 sw Y   )xY ww)Nc                 R    t        | j                  t        j                              S r   )rx   rV   rU   ry   )r"   s    r   
path_levelz2HashedFilesMixin._post_process.<locals>.path_level   s    tzz"&&)**r   T)keyreverseseekr   Fzutf-8)sortedrR   r[   hash_keyr_   hasattrr   rP   readdecoder.   itemsr	   r   subrQ   deleter   encodekeep_intermediate_files_save)r   r   r   r/   r   r"   r   storager!   original_filecleaned_namer   r_   hashed_file_existsr   old_hashed_namerE   r:   r0   r;   r<   r   exccontent_file
saved_names                            r   r   zHashedFilesMixin._post_process   ss    	+ 5j$? A	BD M "$KMGTd# <B}#t4==6 </"&"2"24"GK".x"8K =&1!&&q)%)[[%="!	 ++&1O+00299'BG/3~~/C/C/E A+	8+D9,?5= A 1,0,>,>t\S[,\	!A.5kk)W.MGAA *K0#.w~~/?#@L33

;="&"2"24"FK{{;/K0!%K!FJ"&//*"=K&+5(- $I  .$(	%)ZZ]%K
&*ooj&A *5X&KMAAy<B <BA	BB (2 !A*.c5*@$@$@!A9<B <BsN   1I CH36H3H$C$H3I 	H0H+%H3+H00H33H=	8I c                 &    |j                  dd      S )N\rc   )rz   r   r"   s     r   r[   zHashedFilesMixin.clean_nameC  s    ||D#&&r   c                     |S r    r   s     r   r   zHashedFilesMixin.hash_keyF  s    r   c                     t        j                  |      }| j                  |      }| j                  |      }|j	                  |      }| | j                  | j                  |            }|S r   )r{   normpathr[   r   getr_   )r   r"   r/   r   r   
cache_names         r   r}   zHashedFilesMixin._stored_nameI  se     !!$'t,==.!%%h/
)9)9$)?@Jr   c                 `   | j                  |      }| j                  |      }| j                  j                  |      }|r|S |}t	        | j
                  dz         D ]?  }| j                  | j                  |d |            }||k(  r|| j                  |<   |c S |}A t        d|d| d      )N   )rE   rY   z
The name 'z' could not be hashed with rI   )r[   r   r/   r   r   r   r_   rQ   )r   r"   r   r   r   intermediate_namer   s          r   rp   zHashedFilesMixin.stored_nameU  s    t,==.&&**84
 t33a78 
	/A  t>O PJ !J..8!!(+!! %/!
	/ tTUUr   r   r#   )FN)F)r$   r%   r&   r4   r   r0   r   r   rG   r_   rn   rg   r   r   r   r[   r   r}   rp   r(   r)   s   @r   r+   r+   ,   sb    &H #V	$)B">84l./`FBP'
Vr   r+   c                   P     e Zd ZdZdZdZdZ fdZd Zd Z	 fdZ
d	 Zd
 Z xZS )ManifestFilesMixin1.0zstaticfiles.jsonTFc                 N    t        |   |i | | j                         | _        y r   )r   r   load_manifestr/   r   r   r   r   s      r   r   zManifestFilesMixin.__init__s  s&    $)&) ..0r   c                     	 | j                  | j                        5 }|j                         j                         cd d d        S # 1 sw Y   y xY w# t        $ r Y y w xY wr   )rR   manifest_namer   r   FileNotFoundError)r   manifests     r   read_manifestz ManifestFilesMixin.read_manifestw  sS    	4--. 0(}}--/0 0 0  		s-   A A	A A
A A 	AAc                 $   | j                         }|i S 	 t        j                  |      }|j                  d      }|dk(  r|j                  di       S t        d| j                  d| j                  d      # t        j                  $ r Y ;w xY w)Nversionr   r   zCouldn't load manifest 'z' (version ))r   jsonloadsr   JSONDecodeErrorrQ   r   manifest_version)r   rE   storedr   s       r   r   z ManifestFilesMixin.load_manifest~  s    $$&?I	/ZZ(F jj+G%zz'2..,,d.C.CE F 	F ## 		s   A9 9BBc              /      K   i | _         t        |   |i |E d {    |j                  d      s| j	                          y y 7 'w)Nr   )r/   r   r   r   save_manifestr   s      r   r   zManifestFilesMixin.post_process  sI     7'8888zz)$  % 	9s   AA(Ac                 2   | j                   | j                  d}| j                  | j                        r| j	                  | j                         t        j                  |      j                         }| j                  | j                  t        |             y )N)r   r   )
r/   r   rP   r   r   r   dumpsr   r   r   )r   payloadcontentss      r   r   z ManifestFilesMixin.save_manifest  sl     --$:O:OP;;t))*KK**+::g&--/

4%%{8'<=r   c                    t        t        |            }|j                  j                         }| j	                  |      }| j
                  j                  |      }|:| j                  rt        d|z        | j                  | j                  |            }t        |      }||d<   d|v r|d   s|dxx   dz  cc<   t        |      S )Nz+Missing staticfiles manifest entry for '%s'rK   rL   rM   rN   )r   r   r!   rO   r   r/   r   manifest_strictrQ   r[   r_   r3   r   )r   r"   rZ   r[   r   r   r`   s          r   rp   zManifestFilesMixin.stored_name  s    wt}- %%++-
==,&&**84
## !NQ[![\\)9)9$)?@J[)%a 4<a 0!#-((r   )r$   r%   r&   r   r   r   r   r   r   r   r   r   rp   r(   r)   s   @r   r   r   m  s8    &MO#1F!>)r   r   c                       e Zd ZdZy)ManifestStaticFilesStoragezh
    A static file system storage backend which also saves
    hashed copies of the files it saves.
    N)r$   r%   r&   r'   r   r   r   r   r     s     	r   r   c                       e Zd Zd Zy)ConfiguredStoragec                 J     t        t        j                               | _        y r   )r   r   STATICFILES_STORAGE_wrapped)r   s    r   _setupzConfiguredStorage._setup  s    G)(*F*FGIr   N)r$   r%   r&   r   r   r   r   r   r     s    Jr   r   )r@   r   rU   r{   r5   urllib.parser   r   r   r   django.confr    django.contrib.staticfiles.utilsr   r	   django.core.exceptionsr
   django.core.files.baser   django.core.files.storager   r   django.utils.functionalr   r   r+   r   r   r   staticfiles_storager   r   r   <module>r      s      	  	 A A   M 7 . J ."* "8~V ~VB
<)) <)~	!35G 	J
 J
 () r   