
    ?wg                       d dl mZ d dlZd dlZ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 d d	lmZ d d
lmZ d dlmZ d dlmZ eeeeeef   eedef   f      Z G d de      Z G d de      Z G d de      Zy)    )annotationsN)	Generator)Iterator)ThreadPoolExecutor)as_completed)Any)Union)settings)ManifestStaticFilesStorage)StaticFilesStorage
Compressorc                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)CompressedStaticFilesStoragezC
    StaticFilesStorage subclass that compresses output files.
    c              +  $   K   |ry t        t        dd       } j                  |d       _        d fdt	               5  fd|D        }t        |      D ]  }|j                         E d {     	 d d d        y 7 # 1 sw Y   y xY ww)N#WHITENOISE_SKIP_COMPRESS_EXTENSIONST
extensionsquietc                    g }j                  |       }t        |      t        |       z
  }j                  j                  |      D ]  }||d  }|j	                  | |df        |S NTpathlen
compressorcompressappendr   
compressed	full_path
prefix_lencompressed_pathcompressed_nameselfs         I/var/www/horilla/myenv/lib/python3.12/site-packages/whitenoise/storage.py_compress_pathzACompressedStaticFilesStorage.post_process.<locals>._compress_path%   sp    68J		$IY#d)3J#'??#;#;I#F A"1*+">!!4$"?@A     c              3  x   K   | ]1  }j                   j                  |      rj                  |       3 y wNr   should_compresssubmit.0r   r&   executorr$   s     r%   	<genexpr>z<CompressedStaticFilesStorage.post_process.<locals>.<genexpr>/   6      ??2248 5   7:)r   strreturnz Generator[tuple[str, str, bool]]getattrr
   create_compressorr   r   r   result)	r$   pathsdry_runoptionsr   futuresfuturer&   r/   s	   `      @@r%   post_processz)CompressedStaticFilesStorage.post_process   s      X'LdS
00Jd0S	  ! 	+X!G
 'w/ +!==?**+	+ 	+ +	+ 	+s/   =B/B1B2B9	BBB	Bc                    t        di |S N r   r$   kwargss     r%   r7   z.CompressedStaticFilesStorage.create_compressor7       #F##r'   N)F)r9   zdict[str, Any]r:   boolr;   r   r4   _PostProcessT)rC   r   r4   r   )__name__
__module____qualname____doc__r>   r7   rA   r'   r%   r   r      s6    
 6;+#+.2+GJ+	+6$r'   r   c                      e Zd Zy)MissingFileErrorN)rG   rH   rI   rA   r'   r%   rL   rL   ;   s    r'   rL   c                       e Zd ZdZdZ fdZ fdZd Z fdZd Z	d Z
ed	        Zd
 Zd Zd Zd Z ej$                  d      Z ej*                  d      Z xZS )$CompressedManifestStaticFilesStoragez
    Extends ManifestStaticFilesStorage instance to create compressed versions
    of its output files and, optionally, to delete the non-hashed files (i.e.
    those without the hash in their name)
    Nc                X    t        t        dd       }||| _        t        |   |i | y )NWHITENOISE_MANIFEST_STRICT)r6   r
   manifest_strictsuper__init__)r$   argsrC   rQ   	__class__s       r%   rS   z-CompressedManifestStaticFilesStorage.__init__H   s2    !(,H$O&#2D $)&)r'   c              /     K   t        |   |i |}|j                  d      s| j                  |      }|D ]/  \  }}}t	        |t
              r| j                  ||      }|||f 1 y w)Nr:   )rR   r>   getpost_process_with_compression
isinstance	Exceptionmake_helpful_exception)r$   rT   rC   filesnamehashed_name	processedrU   s          r%   r>   z1CompressedManifestStaticFilesStorage.post_processN   sx     $d5f5zz)$66u=E -2 	/(D+y)Y/ 77	4H	Y..	/s   A'A*c              #    K   i }t               }| j                  |       |D ]3  \  }}}|r$t        |t              s||| j	                  |      <   |||f 5 | j                          t        |j                               }t        |j                               }| j                  r||z  |z
  }	|}
nt               }	||z  }
| j                  |	       | j                  |
      D ]  \  }}||df  y wr   )setstart_tracking_new_filesrY   rZ   
clean_namestop_tracking_new_fileskeysvalueskeep_only_hashed_filesdelete_filescompress_files)r$   r\   hashed_names	new_filesr]   r^   r_   original_fileshashed_filesfiles_to_deletefiles_to_compressr#   s               r%   rX   zBCompressedManifestStaticFilesStorage.post_process_with_compressionZ   s     E	%%i0,1 	/(D+y:i#C6AT__T23Y..	/ 	$$&\..01<..01&&-	9\IO ,!eO . =/*%)%8%89J%K 	.!D/--	.s   C0C2c                    t        |   |i |}| j                  *| j                  j                  | j	                  |             |S r)   )rR   r^   
_new_filesaddrc   )r$   rT   rC   r]   rU   s       r%   r^   z0CompressedManifestStaticFilesStorage.hashed_namet   sA    w"D3F3??&OO 56r'   c                    || _         y r)   rq   )r$   rk   s     r%   rb   z=CompressedManifestStaticFilesStorage.start_tracking_new_filesz   s	    #r'   c                    d | _         y r)   rt   r$   s    r%   rd   z<CompressedManifestStaticFilesStorage.stop_tracking_new_files}   s	    r'   c                $    t        t        dd      S )N!WHITENOISE_KEEP_ONLY_HASHED_FILESF)r6   r
   rv   s    r%   rg   z;CompressedManifestStaticFilesStorage.keep_only_hashed_files   s    x!DeLLr'   c                    |D ]'  }	 t        j                  | j                  |             ) y # t        $ r(}|j                  t        j
                  k7  r Y d }~Wd }~ww xY wr)   )osunlinkr   OSErrorerrnoENOENT)r$   rn   r]   es       r%   rh   z1CompressedManifestStaticFilesStorage.delete_files   sT    # 	D		$))D/*	  77ell* +s   $.	AAAc                    t        di |S r@   r   rB   s     r%   r7   z6CompressedManifestStaticFilesStorage.create_compressor   rD   r'   c              #     K   t        t        dd       } j                  |d       _        d fdt	               5  fd|D        }t        |      D ]  }|j                         E d {     	 d d d        y 7 # 1 sw Y   y xY ww)Nr   Tr   c                    g }j                  |       }t        |      t        |       z
  }j                  j                  |      D ]  }||d  }|j	                  | |f        |S r)   r   r   s         r%   r&   zKCompressedManifestStaticFilesStorage.compress_files.<locals>._compress_path   sl    02J		$IY#d)3J#'??#;#;I#F ;"1*+">!!4"9:; r'   c              3  x   K   | ]1  }j                   j                  |      rj                  |       3 y wr)   r*   r-   s     r%   r0   zFCompressedManifestStaticFilesStorage.compress_files.<locals>.<genexpr>   r1   r2   )r   r3   r4   zlist[tuple[str, str]]r5   )r$   r9   r   r<   r=   r&   r/   s   `    @@r%   ri   z3CompressedManifestStaticFilesStorage.compress_files   s     X'LdS
00Jd0S	  ! 	+X!G
 'w/ +!==?**+	+ 	+ +	+ 	+s.   :B/B.A?/B6	B?BB
Bc                   t        |t              rt        |j                        r|j                  d   nd}| j                  j                  |      }|rxt        j                  j                  |      d   j                  d      j                         }| j                  j                  |||j                  d      |      }t        |      }|S )au  
        If a CSS file contains references to images, fonts etc that can't be found
        then Django's `post_process` blows up with a not particularly helpful
        ValueError that leads people to think WhiteNoise is broken.

        Here we attempt to intercept such errors and reformat them to be more
        helpful in revealing the source of the problem.
        r       .)orig_messagefilenamemissingext)rY   
ValueErrorr   rT   _error_msg_researchrz   r   splitextlstripupper
_error_msgformatgrouprL   )r$   	exceptionr]   messagematch	extensions         r%   r[   z;CompressedManifestStaticFilesStorage.make_helpful_exception   s     i,+.y~~+>innQ'BG&&--g6EGG,,T215<<SAGGI	//00!(!!KKN!	 1  -W5	r'   z#^The file '(.+)' could not be founda          {orig_message}

        The {ext} file '{filename}' references a file which could not be found:
          {missing}

        Please check the URL references in this {ext} file, particularly any
        relative paths which might be pointing to the wrong location.
        )rG   rH   rI   rJ   rq   rS   r>   rX   r^   rb   rd   propertyrg   rh   r7   ri   r[   recompiler   textwrapdedentr   __classcell__)rU   s   @r%   rN   rN   ?   s     J*
/.4$ M M$+,0 BJJEFM 	
Jr'   rN   )
__future__r   r}   rz   r   r   collections.abcr   r   concurrent.futuresr   r   typingr   r	   django.confr
   "django.contrib.staticfiles.storager   r   whitenoise.compressr   tupler3   rE   RuntimeErrorrF   r   r   rL   rN   rA   r'   r%   <module>r      s    "  	 	  % $ 1 +     I A *uS#t^4eC|<S6TTUV!$#5 !$H	z 	J+E Jr'   