o
    wvXjð  ã                   @   s”   d Z ddlmZm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mZ d
ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )zSimple messaging interface.é    )Úabsolute_importÚunicode_literalsN)Údequeé   )Úentity)Ú	messaging)Úmaybe_channel)ÚEmptyÚ	monotonic)ÚSimpleQueueÚSimpleBufferc                   @   sŠ   e Zd ZeZdZdd„ Zdd„ Zddd„Zdd
d„Zdd„ Z					d dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZeZd	S )!Ú
SimpleBaseFc                 C   s   | S ©N© ©Úselfr   r   úI/var/www/html/myproject/venv/lib/python3.10/site-packages/kombu/simple.pyÚ	__enter__   ó   zSimpleBase.__enter__c                 G   s   |   ¡  d S r   )Úclose)r   Úexc_infor   r   r   Ú__exit__   s   zSimpleBase.__exit__c                 C   sD   t |ƒ| _|| _|| _|| _| jjd | _tƒ | _| j 	| j
¡ d S )Nr   )r   ÚchannelÚproducerÚconsumerÚno_ackÚqueuesÚqueuer   ÚbufferÚregister_callbackÚ_receive)r   r   r   r   r   r   r   r   Ú__init__   s   
zSimpleBase.__init__TNc                 C   s”   |s|   ¡ S |  ¡  tƒ }|}	 | jr| j ¡ S |d ur$|dkr$|  ¡ ‚z| jjjj	|d� W n t
jy;   |  ¡ ‚w |d urItƒ | }|| }q)NTg        )Útimeout)Ú
get_nowaitÚ_consumer
   r   Úpopleftr	   r   Ú
connectionÚclientÚdrain_eventsÚsocketr"   )r   Úblockr"   Ú
time_startÚ	remainingÚelapsedr   r   r   Úget#   s&   
ÿ
èzSimpleBase.getc                 C   s    | j j| jd�}|s|  ¡ ‚|S )N©r   )r   r.   r   r	   )r   Úmr   r   r   r#   E   s   zSimpleBase.get_nowaitc                 K   s"   | j j|f||||dœ|¤Ž d S )N)Ú
serializerÚrouting_keyÚheadersÚcompression)r   Úpublish)r   Úmessager1   r3   r4   r2   Úkwargsr   r   r   ÚputK   s   
ü
ûzSimpleBase.putc                 C   s
   | j  ¡ S r   )r   Úpurger   r   r   r   ÚclearT   s   
zSimpleBase.clearc                 C   s   | j jdd�\}}}|S )NT)Úpassive)r   Úqueue_declare)r   Ú_Úsizer   r   r   ÚqsizeW   s   zSimpleBase.qsizec                 C   s   | j  ¡  d S r   )r   Úcancelr   r   r   r   r   [   s   zSimpleBase.closec                 C   s   | j  |¡ d S r   )r   Úappend)r   Úmessage_datar6   r   r   r   r    ^   s   zSimpleBase._receivec                 C   s$   | j s| jj| jd� d| _ d S d S )Nr/   T)Ú
_consumingr   Úconsumer   r   r   r   r   r$   a   s   
þzSimpleBase._consumec                 C   s   |   ¡ S )z`len(self) -> self.qsize()`.)r?   r   r   r   r   Ú__len__f   s   zSimpleBase.__len__c                 C   s   dS )NTr   r   r   r   r   Ú__bool__j   r   zSimpleBase.__bool__)F)TN)NNNN)Ú__name__Ú
__module__Ú__qualname__r	   rC   r   r   r!   r.   r#   r8   r:   r?   r   r    r$   rE   rF   Ú__nonzero__r   r   r   r   r      s&    

	"
ÿ	r   c                       s<   e Zd ZdZdZi Zi ZddiZ			d‡ fdd„	Z‡  Z	S )	r   z!Simple API for persistent queues.FÚtypeÚdirectNc	                    sà   |}
t | jfi |p
i ¤Ž}t | jfi |pi ¤Ž}t | jfi |p i ¤Ž}|d u r*| j}t|
tjƒsItj|fi |¤Ž}tj|||fd|i|¤Ž}
|}n|
j	}|
j
}t ||
¡}tj|||||d�}tt| ƒj||||fi |	¤Ž d S )NÚqueue_arguments)r1   r2   r4   )ÚdictÚ
queue_optsÚ
queue_argsÚexchange_optsr   Ú
isinstancer   ÚQueueÚExchangeÚexchanger2   r   ÚConsumerÚProducerÚsuperr   r!   )r   r   Únamer   rO   rP   rQ   r1   r4   r7   r   rU   r2   r   r   ©Ú	__class__r   r   r!   w   s6   ÿþýÿ
ÿzSimpleQueue.__init__)NNNNNN)
rG   rH   rI   Ú__doc__r   rO   rP   rQ   r!   Ú__classcell__r   r   rZ   r   r   o   s    þr   c                   @   s*   e Zd ZdZdZdddœZddddœZdS )r   z Simple API for ephemeral queues.TF)ÚdurableÚauto_deleteÚ	transient)r^   Údelivery_moder_   N)rG   rH   rI   r\   r   rO   rQ   r   r   r   r   r   ’   s    ÿ
þr   )r\   Ú
__future__r   r   r)   Úcollectionsr   Ú r   r   r&   r   Úfiver	   r
   Ú__all__Úobjectr   r   r   r   r   r   r   Ú<module>   s    _#