
    h                         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y)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                 p   t        	|   |i | || _        | j                  |      }t        j
                  dk(  r|j                  d      r|dd  }|j                  |      | _        |j                  |      | _	        || _
        || _        | j                  dt               j                  |      z          y )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
            V/var/www/Befach/backend/env/lib/python3.12/site-packages/celery/backends/filesystem.pyr   zFilesystemBackend.__init__$   s    $)&)s# 77d?ts38D KK)	::h'	 	$&--2I IJ    c                 P    |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w!$(C6(C5$(((CDDr!   c                     |st        t              |j                  d      r|dd  S |j                  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<   sK    &}55>>-.rs8O>>)$qr7N"#?@@r!   c                     	 | j                  |d       | j                  |      dk(  sJ | j                  |       y # 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   sQ    	7HHS-(88C=M111KK 	7&~66	7s	   9< Ac                 P    | j                   j                  | j                  |f      S N)r   joinr   r/   s     r    	_filenamezFilesystemBackend._filenameM   s    xx}}dii-..r!   c                     	 | j                  | j                  |      d      5 }|j                         cd d d        S # 1 sw Y   y xY w# t        $ r Y y w xY w)Nrb)r   r4   readFileNotFoundError)r   r0   infiles      r    r+   zFilesystemBackend.getP   sO    	4>>#.5 %{{}% % %  		s+   !A	 =	A	 AA	 A	 		AAc                     | j                  | j                  |      d      5 }|j                  t        |             d d d        y # 1 sw Y   y xY w)Nwb)r   r4   writer   )r   r0   valueoutfiles       r    r*   zFilesystemBackend.setW   sA    YYt~~c*D1 	/WMM,u-.	/ 	/ 	/s   AAc              #   @   K   |D ]  }| j                  |        y wr2   )r+   )r   keysr0   s      r    mgetzFilesystemBackend.mget[   s     C((3- s   c                 D    | j                  | j                  |             y r2   )r   r4   r/   s     r    r,   zFilesystemBackend.delete_   s    DNN3'(r!   c                 P   | j                   syt        ddd| j                  j                        }| j                  j	                         |z
  j                         }|| j                   z
  }t        j                  | j                        D ]  }| j                  | j                  | j                  fD ]r  }|j                  |      st        j                  j                  | j                  |      }t        j                  |      j                  |k  r| j!                  |          y)zDelete expired meta-data.Ni  r   )tzinfo)expiresr   apptimezonenowtotal_secondsr   listdirr   task_keyprefixgroup_keyprefixchord_keyprefixr   r3   statst_mtimer   )r   epochnow_ts	cutoff_tsfilenameprefixr   s          r    cleanupzFilesystemBackend.cleanupb   s    ||q!DHH,=,=>((,,.5(779T\\)	

499-H..0D0D//1&&v.77<<		8<Dwwt}--	9D)1 .r!   ) N)__name__
__module____qualname____doc__r   r   r   r   default_encodingr   r#   r   r   r4   r+   r*   rA   r,   rU   __classcell__)r   s   @r    r	   r	      sS      d299"&&*K(EA7// )r!   r	   )rZ   localer   r   kombu.utils.encodingr   celeryr   celery.backends.baser   celery.exceptionsr   getpreferredencodingr[   r'   r(   r.   r	   rV   r!   r    <module>rc      sS    '  	  -  5 2.6..u5 JN W, Wr!   