o
    ~¨Êh2  ã                   @   s<  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 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mZ d d	lmZ dad2d
d„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdadd„ Z dd„ Z!dd„ Z"d d!„ Z#d"d#„ Z$d3d%d&„Z%d3d'd(„Z&d)d*„ Z'd+d,„ Z(d4d.d/„Z)ed0d1„ ƒZ*dS )5é    N)Úimport_module)Úcaches)ÚContentFile)Ú
force_textÚsmart_bytes)ÚSimpleLazyObject)Úsettings)Údefault_storage)Úget_mod_funcc                 C   s&   t  t| ƒ¡ ¡ }|r|d |… S |S ©N)ÚhashlibÚsha256r   Ú	hexdigest)Ú	plaintextÚlengthÚdigest© r   úB/var/www/html/env/lib/python3.10/site-packages/compressor/cache.pyÚget_hexdigest   s   r   c                 C   s   dt | ƒ S )Nzdjango_compressor.%s)r   ©Úkeyr   r   r   Úsimple_cachekey   s   r   c                 C   s   dt  ¡ t| ƒf S )Nzdjango_compressor.%s.%s)ÚsocketÚgethostnamer   r   r   r   r   Úsocket_cachekey   s   r   c               
   O   sh   t d u r-zttjƒ\}}tt|ƒ|ƒa W n tttfy, } z	tdtj|f ƒ‚d }~ww t | i |¤ŽS )Nz)Couldn't import cache key function %s: %s)	Ú_cachekey_funcr
   r   ÚCOMPRESS_CACHE_KEY_FUNCTIONÚgetattrr   ÚAttributeErrorÚImportErrorÚ	TypeError)ÚargsÚkwargsÚmod_nameÚ	func_nameÚer   r   r   Úget_cachekey#   s   ÿÿ€ÿr&   c                 C   ó   t dt| ƒ ƒS )Nzmtime.%s)r&   r   )Úfilenamer   r   r   Úget_mtime_cachekey0   ó   r)   c                 C   s   t |  tjd¡ƒS )NÚ )r   Úreplacer   Ú
STATIC_URL)Úrender_template_stringr   r   r   Úget_offline_hexdigest4   s   þr/   c                 C   r'   )Nz
offline.%s)r&   r/   )Úsourcer   r   r   Úget_offline_cachekey;   r*   r1   c                  C   s   t j d¡} tj | t j¡S )Nú/)r   ÚCOMPRESS_OUTPUT_DIRÚstripÚosÚpathÚjoinÚCOMPRESS_OFFLINE_MANIFEST)Ú
output_dirr   r   r   Úget_offline_manifest_filename?   s   r:   c                  C   sd   t d u r0tƒ } t | ¡r.t | ¡�}t | ¡  d¡¡a W d   ƒ t S 1 s'w   Y  t S i a t S )NÚutf8)	Ú_offline_manifestr:   r	   ÚexistsÚopenÚjsonÚloadsÚreadÚdecode)r(   Úfpr   r   r   Úget_offline_manifestG   s   

ÿüÿrD   c                   C   s   d a d S r   )r<   r   r   r   r   Úflush_offline_manifestS   s   rE   c                 C   s4   t ƒ }tj| dd� d¡}t |t|ƒ¡ tƒ  d S )Né   )Úindentr;   )r:   r?   ÚdumpsÚencoder	   Úsaver   rE   )Úmanifestr(   Úcontentr   r   r   Úwrite_offline_manifestX   s   
rM   c                 C   s   t d| j||f ƒS )Nztemplatetag.%s.%s.%s)r&   Úcachekey)Ú
compressorÚmodeÚkindr   r   r   Úget_templatetag_cachekey_   s   ÿrR   c                 C   sL   t jr t| ƒ}t |¡}|d u rtj | ¡}t ||t j¡ |S tj | ¡S r   )	r   ÚCOMPRESS_MTIME_DELAYr)   ÚcacheÚgetr5   r6   ÚgetmtimeÚset)r(   r   Úmtimer   r   r   Ú	get_mtimed   s   
rY   é   c                 C   s@   zt j | ¡} ttt| ƒƒƒ}W n
 ty   Y d S w t||ƒS r   )r5   r6   ÚrealpathÚstrÚintrY   ÚOSErrorr   )r(   r   rX   r   r   r   Úget_hashed_mtimeo   s   ÿ
r_   c                 C   sb   zt j | ¡} W n
 ty   Y d S w t| dƒ�}t| ¡ |ƒW  d   ƒ S 1 s*w   Y  d S )NÚrb)r5   r6   r[   r^   r>   r   rA   )r(   r   Úfiler   r   r   Úget_hashed_contentx   s   ÿ$ÿrb   c                 C   s   t  td| |f ƒ¡ ¡ S )Nzprecompiler.%s.%s)r   Úsha1r   r   )ÚcommandÚcontentsr   r   r   Úget_precompiler_cachekeyƒ   s   rf   c                 C   sJ   t  | ¡}|d u rd S |\}}}t ¡ |kr#|s#t| |dtjd� d S |S )NT)Ú	refreshedÚtimeout)rT   rU   ÚtimeÚ	cache_setr   ÚCOMPRESS_MINT_DELAY)r   Ú
packed_valÚvalÚrefresh_timerg   r   r   r   Ú	cache_get‡   s   

ÿro   Fc                 C   s<   |d u rt j}|t ¡  }|t j }|||f}t | ||¡S r   )r   ÚCOMPRESS_REBUILD_TIMEOUTri   rk   rT   rW   )r   rm   rg   rh   rn   Úreal_timeoutrl   r   r   r   rj   •   s   

rj   c                   C   s
   t tj S r   )r   r   ÚCOMPRESS_CACHE_BACKENDr   r   r   r   Ú<lambda>ž   s   
 rs   r   )rZ   )FN)+r?   r   r5   r   ri   Ú	importlibr   Údjango.core.cacher   Údjango.core.files.baser   Údjango.utils.encodingr   r   Údjango.utils.functionalr   Úcompressor.confr   Úcompressor.storager	   Úcompressor.utilsr
   r   r   r   r   r&   r)   r/   r1   r:   r<   rD   rE   rM   rR   rY   r_   rb   rf   ro   rj   rT   r   r   r   r   Ú<module>   sD    


	
	