
    Ih                       d Z ddlm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(                  j0                  ej(                  j2                  ej(                  j4                  ej(                  j6                  ej(                  j8                  ej(                  j:                  f	Zej(                  j>                  ej(                  j@                  ej(                  jB                  ej(                  j.                  ej(                  j0                  ej(                  j2                  ej(                  jD                  ej(                  jF                  ej(                  j4                  ej(                  jH                  ej(                  jJ                  ej(                  jL                  ej(                  j:                  ej(                  jN                  ejP                  fZ)dZ+dZ, G d dejZ                        Z- G d dej\                        Z.y# e*$ r	 dZdxZZ)Y <w xY w)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
=================

    )annotationsN)Empty)bytes_to_strensure_bytes)dumpsloads   )virtual)KazooClient)Queue i  z!Mahendra M <mahendra.m@gmail.com>c                  v     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        |   |fi | | j                  j                  j                  }dj                  |j                  d            | _        y )Nz/{}/)super__init__
connectionclientvirtual_hostformatstrip_vhost)selfr   kwargsvhost	__class__s       R/var/www/html/planif/env/lib/python3.12/site-packages/kombu/transport/zookeeper.pyr   zChannel.__init__i   sC    .v.&&33ll5;;s#34    c                V    t         j                  j                  | j                  |      S N)ospathjoinr   )r   
queue_names     r   	_get_pathzChannel._get_pathn   s    ww||DKK44r   c                    | j                   j                  |d       }|?t        | j                  | j	                  |            }|| j                   |<   t        |       |S r!   )_queuesgetr   r   r&   len)r   r%   queues      r   
_get_queuezChannel._get_queueq   sR      T2=$++t~~j'ABE',DLL$ Jr   c                    | j                  |      j                  t        t        |            | j	                  |d            S )NT)reverse)priority)r,   putr   r   _get_message_priority)r   r+   messager   s       r   _putzChannel._put}   sB    u%))w(///F * 
 	
r   c                    | j                  |      }|j                         }|
t               t        t	        |            S r!   )r,   r)   r   r   r   )r   r+   msgs      r   _getzChannel._get   s7    &iik;'M\#&''r   c                `    d}| j                  |      }	 |j                         }|	 |S |dz  })Nr   r	   )r,   r)   )r   r+   countr5   s       r   _purgezChannel._purge   sB    &))+C{  QJE	 r   c                    | j                  |      r<| j                  |       | j                  j                  | j	                  |             y y r!   )
_has_queuer9   r   deleter&   )r   r+   argsr   s       r   _deletezChannel._delete   s:    ??5!KKKKt~~e45 "r   c                :    | j                  |      }t        |      S r!   )r,   r*   r   r+   s     r   _sizezChannel._size   s    &5zr   c                J    | j                  |      s| j                  |      }y y r!   )r;   r,   )r   r+   r   s      r   
_new_queuezChannel._new_queue   s!    u%OOE*E &r   c                Z    | j                   j                  | j                  |            d uS r!   )r   existsr&   r@   s     r   r;   zChannel._has_queue   s%    {{!!$.."78DDr   c           	        | j                   j                  }g }|j                  rg|j                  D ]X  }|j                  d      r|t	        d      d  }|s%	 |j                  dd      \  }}|t        |      f}|j                  |       Z |j                  |j                  xs t        f}||vr|j                  d|       dj                  |D cg c]  \  }}| d|  c}}      }t        |      }	|	j                          |	S # t        $ r1 ||j                  k(  r||j                  xs t        f}n|t        f}Y w xY wc c}}w )Nzzookeeper://:r	   r   ,)r   r   alt
startswithr*   splitint
ValueErrorhostnameportDEFAULT_PORTappendinsertr$   r   start)
r   conninfohosts	host_porthostrO   hpconn_strconns
             r   _openzChannel._open   s<   ??))<<%\\ (	''7 )#n*=*> ?I >!*a!8JD$!%s4y 1I Y'( &&(EF	E!LLI&88E:DAqs!A3Z:;8$

 " > H$5$55%.0M$N	%.$=		> ;s   "DE
7EEc                \    | j                   | j                         | _         | j                   S r!   )_clientr\   r   s    r   r   zChannel.client   s#    <<::<DL||r   )__name__
__module____qualname____doc__r^   r(   r   r&   r,   r3   r6   r9   r>   rA   rC   r;   r\   propertyr   __classcell__r   s   @r   r   r   c   s\    GG5
5

(
6
+E4  r   r   c                       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        |   |i | y )Nz"The kazoo library is not installed)rj   ImportErrorr   r   )r   r=   r   r   s      r   r   zTransport.__init__   s&    =BCC$)&)r   c                "    t         j                  S r!   )rj   __version__r_   s    r   driver_versionzTransport.driver_version   s       r   )r`   ra   rb   rc   r   polling_intervalrP   default_portr
   rh   connection_errorsKZ_CONNECTION_ERRORSchannel_errorsKZ_CHANNEL_ERRORSdriver_typedriver_namer   ro   re   rf   s   @r   rh   rh      sb    GL++.BB  	((+<<  KK*!r   rh   )/rc   
__future__r   r"   socketr+   r   kombu.utils.encodingr   r   kombu.utils.jsonr   r    r
   rj   kazoo.clientr   kazoo.recipe.queuer   
exceptionsSystemErrorExceptionConnectionLossExceptionMarshallingErrorExceptionUnimplementedExceptionOperationTimeoutExceptionNoAuthExceptionInvalidACLExceptionAuthFailedExceptionSessionExpiredExceptionrs   RuntimeInconsistencyExceptionDataInconsistencyExceptionBadArgumentsExceptionApiErrorExceptionNoNodeExceptionNodeExistsException NoChildrenForEphemeralsExceptionNotEmptyExceptionInvalidCallbackExceptionerrorru   rl   rP   
__author__r   rh   r   r   r   <module>r      s  'R # 	   ; ) $2(( 	--0022//22((,,,,00
 	6633..22//22**((((,,99**0011* 0
cgoo cL!!! !_  2E/11,2s   HI I-,I-