
     h                        d Z ddlZddl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 	 ddlZddlmZ dd	lmZ ej        j        ej        j        ej        j        ej        j        ej        j        ej        j        ej        j        ej        j        ej        j        f	Zej        j        ej        j        ej        j        ej        j        ej        j        ej        j        ej        j         ej        j!        ej        j        ej        j"        ej        j#        ej        j$        ej        j        ej        j%        ej&        fZ'n# e($ r	 dZd
xZZ'Y nw xY wdZ)dZ* G d dej+                  Z+ G d dej,                  Z,dS )a  Zookeeper transport module for kombu.

Zookeeper based transport. This transport uses the built-in kazoo Zookeeper
based queue implementation.

**References**

- https://zookeeper.apache.org/doc/current/recipes.html#sc_recipes_Queues
- https://kazoo.readthedocs.io/en/latest/api/recipe/queue.html

**Limitations**
This queue does not offer reliable consumption.  An entry is removed from
the queue prior to being processed.  So if an error occurs, the consumer
has to re-queue the item or it will be lost.

Features
========
* Type: Virtual
* Supports Direct: Yes
* Supports Topic: Yes
* Supports Fanout: No
* Supports Priority: Yes
* Supports TTL: No

Connection String
=================
Connects to a zookeeper node as:

.. code-block::

    zookeeper://SERVER:PORT/VHOST

The <vhost> becomes the base for all the other znodes.  So we can use
it like a vhost.


Transport Options
=================

    N)Empty)bytes_to_strensure_bytes)dumpsloads   )virtual)KazooClient)Queue i  z!Mahendra M <mahendra.m@gmail.com>c                   |     e Zd ZdZdZi Z fdZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zed             Z xZS )ChannelzZookeeper Channel.Nc                      t                      j        |fi | | j        j        j        }d                    |                    d                    | _        d S )Nz/{}/)super__init__
connectionclientvirtual_hostformatstrip_vhost)selfr   kwargsvhost	__class__s       U/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/kombu/transport/zookeeper.pyr   zChannel.__init__g   sR    ..v...&3ll5;;s#3#344    c                 L    t           j                            | j        |          S N)ospathjoinr   )r   
queue_names     r   	_get_pathzChannel._get_pathl   s    w||DK444r   c                     | j                             |d           }|At          | j        |                     |                    }|| j         |<   t          |           |S r    )_queuesgetr   r   r%   len)r   r$   queues      r   
_get_queuezChannel._get_queueo   sY      T22=$+t~~j'A'ABBE',DL$ JJJr   c                     |                      |                              t          t          |                    |                     |d                    S )NT)reverse)priority)r+   putr   r   _get_message_priority)r   r*   messager   s       r   _putzChannel._put{   sR    u%%))w((///FF * 
 
 	
r   c                     |                      |          }|                                }|t                      t          t	          |                    S r    )r+   r(   r   r   r   )r   r*   msgs      r   _getzChannel._get   sD    &&iikk;''M\#&&'''r   c                 p    d}|                      |          }	 |                                }|n|dz  }|S )Nr   Tr   )r+   r(   )r   r*   countr4   s       r   _purgezChannel._purge   sG    &&	))++C{QJE		 r   c                     |                      |          rD|                     |           | j                            |                     |                     d S d S r    )
_has_queuer8   r   deleter%   )r   r*   argsr   s       r   _deletezChannel._delete   sZ    ??5!! 	6KKKt~~e4455555	6 	6r   c                 J    |                      |          }t          |          S r    )r+   r)   r   r*   s     r   _sizezChannel._size   s    &&5zzr   c                 ^    |                      |          s|                     |          }d S d S r    )r:   r+   )r   r*   r   s      r   
_new_queuezChannel._new_queue   s5    u%% 	+OOE**EEE	+ 	+r   c                 `    | j                             |                     |                    d uS r    )r   existsr%   r?   s     r   r:   zChannel._has_queue   s)    {!!$.."7"788DDr   c                 p   | j         j        }g }|j        r|j        D ]}|                    d          r|t	          d          d          }|s1	 |                    dd          \  }}|t          |          f}n5# t          $ r( ||j        k    r||j	        pt          f}n	|t          f}Y nw xY w|                    |           |j        |j	        pt          f}||vr|                    d|           d                    d |D                       }t          |          }|                                 |S )Nzzookeeper://:r   r   ,c                 "    g | ]\  }}| d | S )rF   r   ).0hps      r   
<listcomp>z!Channel._open.<locals>.<listcomp>   s&    :::DAqZZAZZ:::r   )r   r   alt
startswithr)   splitint
ValueErrorhostnameportDEFAULT_PORTappendinsertr#   r
   start)r   conninfohosts	host_porthostrS   conn_strconns           r   _openzChannel._open   se   ?)< 	(%\ ( (	''77 @ )#n*=*=*>*> ?I  >!*a!8!8JD$!%s4yy 1II! > > > H$555%.0M$N		%.$=		>
 Y''''&(EF	E!!LLI&&&88::E:::;;8$$

s   *A::/B,+B,c                 P    | j         |                                 | _         | j         S r    )_clientr^   r   s    r   r   zChannel.client   s!    <::<<DL|r   )__name__
__module____qualname____doc__r`   r'   r   r%   r+   r2   r5   r8   r=   r@   rB   r:   r^   propertyr   __classcell__r   s   @r   r   r   a   s        GG5 5 5 5 5
5 5 5
 
 

 
 
( ( (
 
 
6 6 6
  + + +E E E  4   X    r   r   c                   x     e Zd ZdZeZdZeZej	        j
        ez   Z
ej	        j        ez   ZdZdZ fdZd Z xZS )	TransportzZookeeper Transport.r   	zookeeperkazooc                 f    t           t          d           t                      j        |i | d S )Nz"The kazoo library is not installed)rl   ImportErrorr   r   )r   r<   r   r   s      r   r   zTransport.__init__   s9    =BCCC$)&)))))r   c                     t           j        S r    )rl   __version__ra   s    r   driver_versionzTransport.driver_version   s      r   )rb   rc   rd   re   r   polling_intervalrT   default_portr	   rj   connection_errorsKZ_CONNECTION_ERRORSchannel_errorsKZ_CHANNEL_ERRORSdriver_typedriver_namer   rq   rg   rh   s   @r   rj   rj      s        GL+.BB  	(+<<  KK* * * * *! ! ! ! ! ! !r   rj   )-re   r!   socketr*   r   kombu.utils.encodingr   r   kombu.utils.jsonr   r    r	   rl   kazoo.clientr
   kazoo.recipe.queuer   
exceptionsSystemErrorExceptionConnectionLossExceptionMarshallingErrorExceptionUnimplementedExceptionOperationTimeoutExceptionNoAuthExceptionInvalidACLExceptionAuthFailedExceptionSessionExpiredExceptionru   RuntimeInconsistencyExceptionDataInconsistencyExceptionBadArgumentsExceptionApiErrorExceptionNoNodeExceptionNodeExistsException NoChildrenForEphemeralsExceptionNotEmptyExceptionInvalidCallbackExceptionerrorrw   rn   rT   
__author__r   rj   r   r   r   <module>r      sA  ' 'R 
			        ; ; ; ; ; ; ; ; ) ) ) ) ) ) ) )      $2LLL(((((((((((( 	-02/2(,,0
 	63.2/2*((,9*01"  2 2 2E/11,,,2 0
c c c c cgo c c cL! ! ! ! !! ! ! ! ! !s   DE   EE