a
    Šxdî  ã                   @   sn   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
 e d¡ZdZd	Zd
ZG dd„ deƒZdS )z!File-system result store backend.é    N)Ú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                       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           	         s€   t ƒ j|i |¤Ž || _|  |¡}tjdkrB| d¡rB|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__© úR/var/www/html/Ranjet/env/lib/python3.9/site-packages/celery/backends/filesystem.pyr   #   s    
zFilesystemBackend.__init__r   c                    s    |  t| jd¡ tƒ  ||¡S )N)r   )ÚupdateÚdictr   r
   Ú
__reduce__)r   r   r   r   r   r   r!   7   s    
ÿzFilesystemBackend.__reduce__c                 C   sD   |st tƒ‚| d¡r"|dd … S | d¡r8|dd … S t tƒ‚d S )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   sL   z,|   |d¡ |  |¡dks J ‚|  |¡ W n tyF   ttƒ‚Y n0 d S )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 s40    Y  W n tyR   Y n0 d S )NÚrb)r   r/   ÚreadÚFileNotFoundError)r   r,   Úinfiler   r   r   r'   P   s
    ,zFilesystemBackend.getc                 C   sD   |   |  |¡d¡}| t|ƒ¡ W d   ƒ n1 s60    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.delete)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Údefault_encodingr   r!   r   r   r/   r'   r&   r9   r(   Ú__classcell__r   r   r   r   r      s   
ÿ	r   )r=   Úlocaler   Zkombu.utils.encodingr   Zceleryr   Zcelery.backends.baser   Zcelery.exceptionsr   Úgetpreferredencodingr>   r$   r%   r*   r   r   r   r   r   Ú<module>   s   
ÿ