o
    þâfÁ  ã                   @   sz   d 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 e d¡Zd	Zd
ZdZG dd„ de	ƒZdS )z!File-system result store backend.é    N)Údatetime)Úensure_bytes)Úuuid)ÚKeyValueStoreBackend)ÚImproperlyConfiguredFz8You need to configure a path for the file-system backendzHA path for the file-system backend should conform to the file URI schemez‰The configured path for the file-system backend does not
work correctly, please make sure that it exists and has
the correct permissions.c                       s~   e Zd ZdZdeejejef‡ fdd„	Z	d‡ fdd„	Z
dd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚFilesystemBackendas  File-system result backend.

    Arguments:
        url (str):  URL to the directory we should use
        open (Callable): open function to use when opening files
        unlink (Callable): unlink function to use when deleting files
        sep (str): directory separator (to join the directory with the key)
        encoding (str): encoding used on the file-system
    Nc           	         s€   t ƒ j|i |¤Ž || _|  |¡}tjdkr!| d¡r!|dd … }| |¡| _| |¡| _	|| _
|| _|  dtƒ  |¡ ¡ d S )NÚntú/é   s   .fs-backend-)ÚsuperÚ__init__ÚurlÚ
_find_pathÚosÚnameÚ
startswithÚencodeÚpathÚsepÚopenÚunlinkÚ_do_directory_testr   )	Úselfr   r   r   r   ÚencodingÚargsÚkwargsr   ©Ú	__class__© úM/var/www/html/venv/lib/python3.10/site-packages/celery/backends/filesystem.pyr   $   s   
zFilesystemBackend.__init__r   c                    s(   |si n|}t ƒ  |i |¥d| ji¥¡S )Nr   )r   Ú
__reduce__r   )r   r   r   r   r   r   r    8   s   zFilesystemBackend.__reduce__c                 C   s@   |st tƒ‚| d¡r|dd … S | d¡r|dd … S t tƒ‚)Nzfile://localhost/é   zfile://é   )r   ÚE_NO_PATH_SETr   ÚE_PATH_NON_CONFORMING_SCHEME)r   r   r   r   r   r   <   s   

zFilesystemBackend._find_pathc                 C   sF   z|   |d¡ |  |¡dksJ ‚|  |¡ W d S  ty"   ttƒ‚w )Ns
   test value)ÚsetÚgetÚdeleteÚOSErrorr   ÚE_PATH_INVALID©r   Úkeyr   r   r   r   E   s   ÿz$FilesystemBackend._do_directory_testc                 C   s   | j  | j|f¡S ©N)r   Újoinr   r*   r   r   r   Ú	_filenameM   s   zFilesystemBackend._filenamec                 C   sX   z!|   |  |¡d¡}| ¡ W  d   ƒ W S 1 sw   Y  W d S  ty+   Y d S w )NÚrb)r   r.   ÚreadÚFileNotFoundError)r   r+   Úinfiler   r   r   r&   P   s   (ÿÿzFilesystemBackend.getc                 C   sF   |   |  |¡d¡}| t|ƒ¡ W d   ƒ d S 1 sw   Y  d S )NÚwb)r   r.   Úwriter   )r   r+   ÚvalueÚoutfiler   r   r   r%   W   s   "ÿzFilesystemBackend.setc                 c   s    |D ]}|   |¡V  qd S r,   )r&   )r   Úkeysr+   r   r   r   Úmget[   s   €ÿzFilesystemBackend.mgetc                 C   s   |   |  |¡¡ d S r,   )r   r.   r*   r   r   r   r'   _   s   zFilesystemBackend.deletec                 C   sž   | j sdS tddd| jjd}| j ¡ |  ¡ }|| j  }t | j¡D ])}| j	| j
| jfD ]}| |¡rKtj | j|¡}t |¡j|k rI|  |¡  nq-q#dS )zDelete expired meta-data.Ni²  r
   )Útzinfo)Úexpiresr   ÚappÚtimezoneÚnowÚtotal_secondsr   Úlistdirr   Útask_keyprefixÚgroup_keyprefixÚchord_keyprefixr   r-   ÚstatÚst_mtimer   )r   ÚepochÚnow_tsÚ	cutoff_tsÚfilenameÚprefixr   r   r   r   Úcleanupb   s"   
ÿ

ü€ýzFilesystemBackend.cleanup)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Údefault_encodingr   r    r   r   r.   r&   r%   r8   r'   rJ   Ú__classcell__r   r   r   r   r      s    
ÿ	r   )rN   Úlocaler   r   Úkombu.utils.encodingr   Úceleryr   Úcelery.backends.baser   Úcelery.exceptionsr   ÚgetpreferredencodingrO   r#   r$   r)   r   r   r   r   r   Ú<module>   s    
ÿ