HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/django/core/cache/backends/__pycache__/filebased.cpython-310.pyc
o

3�a7�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlmZGdd�de�ZdS)zFile-based cache backend�N)�DEFAULT_TIMEOUT�	BaseCache)�locks)�file_move_safecs�eZdZdZejZ�fdd�Zedfdd�Z	d!dd�Z
d	d
�Zedfdd�Zedfd
d�Z
d"dd�Zdd�Zd"dd�Zdd�Zdd�Zd"dd�Zdd�Zdd�Zdd �Z�ZS)#�FileBasedCachez.djcachecs&t��|�tj�|�|_|��dS�N)�super�__init__�os�path�abspath�_dir�
_createdir)�self�dir�params��	__class__��F/usr/lib/python3/dist-packages/django/core/cache/backends/filebased.pyr	szFileBasedCache.__init__NcCs$|�||�rdS|�||||�dS�NFT)�has_key�set)r�key�value�timeout�versionrrr�addszFileBasedCache.addcCs�|�||�}z1t|d��!}|�|�s$t�t�|����Wd�WSWd�W|S1s0wYW|StyAY|Sw)N�rb)	�_key_to_file�open�_is_expired�pickle�loads�zlib�
decompress�read�FileNotFoundError)rr�defaultr�fname�frrr�gets
�����zFileBasedCache.getcCs<|�|�}|�t�||j��|�t�t�||j���dSr)�get_backend_timeout�writer"�dumps�pickle_protocolr$�compress)r�filerr�expiryrrr�_write_content)s
zFileBasedCache._write_contentc
	Cs�|��|�||�}|��tj|jd�\}}d}z1t|d��}	|�|	||�Wd�n1s1wYt||dd�d}W|sIt	�
|�dSdS|sSt	�
|�ww)N)rF�wbT)�allow_overwrite)rr�_cull�tempfile�mkstempr
r r3rr
�remove)
rrrrrr)�fd�tmp_path�renamedr*rrrr.s ���zFileBasedCache.setc
Cs�z\t|�||�d��H}z@t�|tj�|�|�r'Wt�|�Wd�WdSt�t	�
|����}|�d�|�
|||�Wt�|�Wd�WdSt�|�w1sUwYWdStyfYdSw)Nzr+bFrT)r rr�lock�LOCK_EXr!�unlockr"r#r$r%r&�seekr3r')rrrrr*�previous_valuerrr�touch=s&

�

���zFileBasedCache.touchcCs|�|�||��Sr)�_deleter�rrrrrr�deleteNszFileBasedCache.deletecCsB|�|j�rtj�|�sdSzt�|�WdSty YdSwr)�
startswithr
r
r�existsr9r'�rr)rrrrCQs��zFileBasedCache._deletecCsR|�||�}tj�|�r't|d��}|�|�Wd�S1s"wYdS)NrF)rr
rrGr r!)rrrr)r*rrrr[s
 �zFileBasedCache.has_keycCs^|��}t|�}||jkrdS|jdkr|��St�|t||j��}|D]}|�|�q%dS)z�
        Remove random cache entries if max_entries is reached at a ratio
        of num_entries / cull_frequency. A value of 0 for CULL_FREQUENCY means
        that the entire cache will be purged.
        Nr)	�_list_cache_files�len�_max_entries�_cull_frequency�clear�random�sample�intrC)r�filelist�num_entriesr)rrrr6bs

��zFileBasedCache._cullc	Cs:t�d�}ztj|jddd�Wt�|�dSt�|�w)N�?i�T)�exist_ok)r
�umask�makedirsr
)r�	old_umaskrrrrts
zFileBasedCache._createdirc	CsB|j||d�}|�|�tj�|jd�t�|����	�|j
g��S)z�
        Convert a key into a cache file path. Basically this is the
        root cache path joined with the md5sum of the key and a suffix.
        )r�)�make_key�validate_keyr
r�joinr
�hashlib�md5�encode�	hexdigest�cache_suffixrDrrrr}s

�zFileBasedCache._key_to_filecCs|��D]}|�|�qdS)z-
        Remove all the cache files.
        N)rIrCrHrrrrM�s�zFileBasedCache.clearcCsVzt�|�}Wntyd}Ynw|dur)|t��kr)|��|�|j�dSdS)zL
        Take an open cache file `f` and delete it if it's expired.
        rNTF)r"�load�EOFError�time�closerC�name)rr*�exprrrr!�s�zFileBasedCache._is_expiredcs"�fdd�t��jd�j�D�S)z�
        Get a list of paths to all the cache files. These are all the files
        in the root cache dir that end on the cache_suffix.
        csg|]
}tj��j|��qSr)r
rr[r
)�.0r)�rrr�
<listcomp>�s��z4FileBasedCache._list_cache_files.<locals>.<listcomp>z*%s)�glob�glob1r
r`rhrrhrrI�s
�z FileBasedCache._list_cache_files)NNr)�__name__�
__module__�__qualname__r`r"�HIGHEST_PROTOCOLr/r	rrr+r3rrBrErCrr6rrrMr!rI�
__classcell__rrrrrs$





	
r)�__doc__rjr\r
r"rNr7rcr$�django.core.cache.backends.baserr�django.core.filesr�django.core.files.moverrrrrr�<module>s