
    `f                         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j        d          Zd	Zd
ZdZ G 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 schemezThe configured path for the file-system backend does not
work correctly, please make sure that it exists and has
the correct permissions.c                   ~     e Zd ZdZdeej        ej        ef fd	Z	d fd	Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Z x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                     t                      j        |i | || _        |                     |          }t          j        dk    r|                    d          r
|dd          }|                    |          | _        |                    |          | _	        || _
        || _        |                     dt                                          |          z              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__s
            L/var/www/html/env/lib/python3.11/site-packages/celery/backends/filesystem.pyr   zFilesystemBackend.__init__$   s    $)&)))s## 7d??ts33?8D KK))	::h''	 	$&&--2I2I IJJJJJ     c                 j    |si n|}t                                          |i |d| j        i          S )Nr   )r   
__reduce__r   )r   r   r   r   s      r    r$   zFilesystemBackend.__reduce__8   s=    !-vww!!$(C6(C5$((C(CDDDr!   c                     |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   s     r    r   zFilesystemBackend._find_path<   sj     	6&}555>>-.. 	rss8O>>)$$ 	qrr7N"#?@@@r!   c                     	 |                      |d           |                     |          dk    sJ |                     |           d S # t          $ r t	          t
                    w xY w)Ns
   test value)setgetdeleteOSErrorr   E_PATH_INVALIDr   keys     r    r   z$FilesystemBackend._do_directory_testE   sw    	7HHS-(((88C==M1111KK 	7 	7 	7&~666	7s   AA
 
A)c                 D    | j                             | j        |f          S N)r   joinr   r0   s     r    	_filenamezFilesystemBackend._filenameM   s    x}}di-...r!   c                     	 |                      |                     |          d          5 }|                                cd d d            S # 1 swxY w Y   d S # t          $ r Y d S w xY w)Nrb)r   r5   readFileNotFoundError)r   r1   infiles      r    r,   zFilesystemBackend.getP   s    	4>>#..55 %{{}}% % % % % % % % % % % % % % % % % %  	 	 	DD	s3   )A AA AA AA 
A'&A'c                     |                      |                     |          d          5 }|                    t          |                     d d d            d S # 1 swxY w Y   d S )Nwb)r   r5   writer   )r   r1   valueoutfiles       r    r+   zFilesystemBackend.setW   s    YYt~~c**D11 	/WMM,u--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   #AA!Ac              #   B   K   |D ]}|                      |          V  d S r3   )r,   )r   keysr1   s      r    mgetzFilesystemBackend.mget[   s8       	  	 C((3--	  	 r!   c                 V    |                      |                     |                     d S r3   )r   r5   r0   s     r    r-   zFilesystemBackend.delete_   s&    DNN3''(((((r!   c                    | j         sdS t          ddd| j        j                  }| j                                        |z
                                  }|| j         z
  }t          j        | j                  D ]}| j	        | j
        | j        fD ]p}|                    |          rYt          j                            | j        |          }t          j        |          j        |k     r|                     |            nqdS )zDelete expired meta-data.Ni  r   )tzinfo)expiresr   apptimezonenowtotal_secondsr   listdirr   task_keyprefixgroup_keyprefixchord_keyprefixr   r4   statst_mtimer   )r   epochnow_ts	cutoff_tsfilenameprefixr   s          r    cleanupzFilesystemBackend.cleanupb   s    | 	Fq!DH,=>>>(,,..5(7799T\)	
49-- 	 	H.0D/1  &&v.. 7<<	8<<Dwt}}-	99D)))E		 	r!   )r"   N)__name__
__module____qualname____doc__r   r   r   r   default_encodingr   r$   r   r   r5   r,   r+   rB   r-   rV   __classcell__)r   s   @r    r	   r	      s           d29"&*K K K K K K(E E E E E EA A A7 7 7/ / /  / / /     ) ) )      r!   r	   )rZ   localer   r   kombu.utils.encodingr   celeryr   celery.backends.baser   celery.exceptionsr   getpreferredencodingr[   r(   r)   r/   r	   r"   r!   r    <module>rc      s    ' '  				       - - - - - -       5 5 5 5 5 5 2 2 2 2 2 2.6.u55 JN W W W W W, W W W W Wr!   