o
    wvXj\  ã                   @   sP  d Z ddlmZmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZ dZd eeeƒ¡ZejdkrtddlZddlZddlZej Z!dZ"ej#Z$e %¡ Z&dd„ Z'dd„ Z(n ejdkr�ddl)Z)ddl)m!Z!m"Z"m$Z$ dd„ Z'dd„ Z(ne*dƒ‚G dd„ de	j+ƒZ+G dd„ de	j,ƒZ,dS )zNFile-system Transport.

Transport using the file-system as the message store.
é    )Úabsolute_importÚunicode_literalsNé   )Úvirtual)ÚChannelError)ÚEmptyÚ	monotonic)Úbytes_to_strÚstr_to_bytes)ÚloadsÚdumps)Úcached_property)r   r   r   Ú.Úntc                 C   s$   t  |  ¡ ¡}t  ||ddt¡ dS )úCreate file lock.r   ì     þ N)Ú	win32fileÚ_get_osfhandleÚfilenoÚ
LockFileExÚ__overlapped)ÚfileÚflagsÚhfile© r   úW/var/www/html/myproject/venv/lib/python3.10/site-packages/kombu/transport/filesystem.pyÚlock$   s   r   c                 C   s"   t  |  ¡ ¡}t  |ddt¡ dS )úRemove file lock.r   r   N)r   r   r   ÚUnlockFileExr   )r   r   r   r   r   Úunlock)   s   r   Úposix)ÚLOCK_EXÚLOCK_SHÚLOCK_NBc                 C   s   t  |  ¡ |¡ dS )r   N)ÚfcntlÚflockr   )r   r   r   r   r   r   3   s   c                 C   s   t  |  ¡ t j¡ dS )r   N)r$   r%   r   ÚLOCK_UN)r   r   r   r   r   7   s   z9Filesystem plugin only defined for NT and POSIX platformsc                   @   sl   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zed
d„ ƒZ	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdS )ÚChannelzFilesystem Channel.c              	   K   s¦   dt ttƒ d ƒƒt ¡ |f }tj | j|¡}z1zt	|dƒ}t
|tƒ | tt|ƒƒ¡ W n ttfy>   td |¡ƒ‚w W t|ƒ | ¡  dS t|ƒ | ¡  w )zPut `message` onto `queue`.z%s_%s.%s.msgiè  Úwbz"Cannot add file {0!r} to directoryN)ÚintÚroundr   ÚuuidÚuuid4ÚosÚpathÚjoinÚdata_folder_outÚopenr   r!   Úwriter
   r   ÚIOErrorÚOSErrorr   Úformatr   Úclose)ÚselfÚqueueÚpayloadÚkwargsÚfilenameÚfr   r   r   Ú_putB   s$   ÿ

ÿÿÿÿ
zChannel._putc              	   C   sü   d| d }t  | j¡}t|ƒ}t|ƒdkr{| d¡}| |¡dk r#q| jr*| j}nt	 
¡ }zt t j | j|¡|¡ W n	 tyE   Y nw t j ||¡}zt|dƒ}| ¡ }| ¡  | jsct  |¡ W n ttfyt   td |¡ƒ‚w tt|ƒƒS tƒ ‚)zGet next message from `queue`.r   ú.msgr   Úrbz"Cannot read file {0!r} from queue.)r-   ÚlistdirÚdata_folder_inÚsortedÚlenÚpopÚfindÚstore_processedÚprocessed_folderÚtempfileÚ
gettempdirÚshutilÚmover.   r/   r3   r1   Úreadr6   Úremover4   r   r5   r   r	   r   )r7   r8   Ú
queue_findÚfolderr;   rG   r<   r9   r   r   r   Ú_getS   s@   
ÿÿ

€ÿÿzChannel._getc                 C   sŒ   d}d| d }t  | j¡}t|ƒdkrD| ¡ }z| |¡dk r"W qt j | j|¡}t  |¡ |d7 }W n	 t	y=   Y nw t|ƒdks|S )z!Remove all messages from `queue`.r   r   r>   r   )
r-   r@   rA   rC   rD   rE   r.   r/   rM   r4   ©r7   r8   ÚcountrN   rO   r;   r   r   r   Ú_purgez   s    
ýôzChannel._purgec                 C   sV   d}d  |¡}t | j¡}t|ƒdkr)| ¡ }| |¡dk rq|d7 }t|ƒdks|S )z<Return the number of messages in `queue` as an :class:`int`.r   z.{0}.msgr   )r5   r-   r@   rA   rC   rD   rE   rQ   r   r   r   Ú_size“   s   
ù	zChannel._sizec                 C   s
   | j jjS )N)Ú
connectionÚclientÚtransport_options©r7   r   r   r   rW   ¤   s   
zChannel.transport_optionsc                 C   ó   | j  dd¡S )NrA   Údata_in©rW   ÚgetrX   r   r   r   rA   ¨   ó   zChannel.data_folder_inc                 C   rY   )Nr0   Údata_outr[   rX   r   r   r   r0   ¬   r]   zChannel.data_folder_outc                 C   rY   )NrF   Fr[   rX   r   r   r   rF   °   r]   zChannel.store_processedc                 C   rY   )NrG   Ú	processedr[   rX   r   r   r   rG   ´   r]   zChannel.processed_folderN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=   rP   rS   rT   ÚpropertyrW   r   rA   r0   rF   rG   r   r   r   r   r'   ?   s     '



r'   c                   @   s(   e Zd ZdZeZdZdZdZdd„ ZdS )Ú	TransportzFilesystem Transport.r   Ú
filesystemc                 C   s   dS )NzN/Ar   rX   r   r   r   Údriver_versionÂ   s   zTransport.driver_versionN)	r`   ra   rb   rc   r'   Údefault_portÚdriver_typeÚdriver_namerg   r   r   r   r   re   ¹   s    re   )-rc   Ú
__future__r   r   r-   rJ   r+   rH   Ú r   Úkombu.exceptionsr   Ú
kombu.fiver   r   Úkombu.utils.encodingr	   r
   Úkombu.utils.jsonr   r   Úkombu.utils.objectsr   ÚVERSIONr/   ÚmapÚstrÚ__version__ÚnameÚwin32conr   Ú
pywintypesÚLOCKFILE_EXCLUSIVE_LOCKr!   r"   ÚLOCKFILE_FAIL_IMMEDIATELYr#   Ú
OVERLAPPEDr   r   r   r$   ÚRuntimeErrorr'   re   r   r   r   r   Ú<module>   sD    



ÿz