o
    wvXj»  ã                   @   s¦   d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ze W n ey=   eZeZY nw e d¡Zd	Zd
ZdZG dd„ deƒZdS )z!File-system result store backend.é    )Úabsolute_importÚunicode_literalsN)Úensure_bytes)ÚuuidÚstates)Ú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                       sz   e Zd ZdZdeejejef‡ fdd„	Z	di f‡ 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‡  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           	         sd   t t| ƒj|i |¤Ž || _|  |¡}| |¡| _| |¡| _|| _|| _	|  
dtƒ  |¡ ¡ d S )Ns   .fs-backend-)Úsuperr	   Ú__init__ÚurlÚ
_find_pathÚencodeÚpathÚsepÚopenÚunlinkÚ_do_directory_testr   )	Úselfr   r   r   r   ÚencodingÚargsÚkwargsr   ©Ú	__class__© úW/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/backends/filesystem.pyr   -   s   
zFilesystemBackend.__init__r   c                    s$   |  t| jd�¡ tt| ƒ ||¡S )N)r   )ÚupdateÚdictr   r
   r	   Ú
__reduce__)r   r   r   r   r   r   r   =   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_SETÚ
startswithÚE_PATH_NON_CONFORMING_SCHEME)r   r   r   r   r   r   B   s   

zFilesystemBackend._find_pathc                 C   sJ   z|   |dtj¡ |  |¡dksJ ‚|  |¡ W d S  ty$   ttƒ‚w )Ns
   test value)Úsetr   ÚSUCCESSÚgetÚdeleteÚIOErrorr   ÚE_PATH_INVALID©r   Úkeyr   r   r   r   K   s   ÿz$FilesystemBackend._do_directory_testc                 C   s   | j  | j|f¡S ©N)r   Újoinr   r*   r   r   r   Ú	_filenameS   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&   V   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ÚstateÚoutfiler   r   r   r$   ]   s   "ÿzFilesystemBackend.setc                 c   s   � |D ]}|   |¡V  qd S r,   )r&   )r   Úkeysr+   r   r   r   Úmgeta   s   €ÿzFilesystemBackend.mgetc                 C   s   |   |  |¡¡ d S r,   )r   r.   r*   r   r   r   r'   e   s   zFilesystemBackend.delete)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úosr   r   Údefault_encodingr   r   r   r   r.   r&   r$   r9   r'   Ú__classcell__r   r   r   r   r	   "   s    
ÿ	r	   )r=   Ú
__future__r   r   Úlocaler>   Úkombu.utils.encodingr   Úceleryr   r   Úcelery.backends.baser   Úcelery.exceptionsr   r1   Ú	NameErrorr(   ÚIsADirectoryErrorÚgetpreferredencodingr?   r!   r#   r)   r	   r   r   r   r   Ú<module>   s(   þ
ÿ