
    |Oi                         d Z ddlZddlZddlmZ ddlZddlZ G d de          Z G d d          Z	 G d d	          Z
d
ej        dej        defdZdS )zB
The Pulsar Python client APIs that work with the asyncio module.
    N)Anyc                   H    e Zd ZdZdej        ddfdZdej        fdZd ZdS )PulsarExceptionz8
    The exception that wraps the Pulsar error code
    resultreturnNc                     || _         dS )z
        Create the Pulsar exception.

        Parameters
        ----------
        result: pulsar.Result
            The error code of the underlying Pulsar APIs.
        N_result)selfr   s     i/var/www/html/web/mlink/mlink_AI_Server/mlink-backend/venv/lib/python3.11/site-packages/pulsar/asyncio.py__init__zPulsarException.__init__$   s         c                     | j         S )z0
        Returns the Pulsar error code.
        r	   r   s    r   errorzPulsarException.error/   s     |r   c                 8    | j         j         d| j         j         S )z2
        Convert the exception to string.
         )r
   valuenamer   s    r   __str__zPulsarException.__str__5   s"     ,$::t|'8:::r   )	__name__
__module____qualname____doc__pulsarResultr   r   r    r   r   r   r      sn         	v} 	 	 	 	 	v}    ; ; ; ; ;r   r   c                   N    e Zd ZdZdej        ddfdZdedej	        fdZ
d	dZdS )
ProducerzK
    The Pulsar message producer, used to publish messages on a topic.
    producerr   Nc                     || _         dS )a-  
        Create the producer.
        Users should not call this constructor directly. Instead, create the
        producer via `Client.create_producer`.

        Parameters
        ----------
        producer: _pulsar.Producer
            The underlying Producer object from the C extension.
        N)	_producer)r   r    s     r   r   zProducer.__init__@   s     ,4r   contentc                   K   t          j                    }|                    |           t          j                                                    }| j                            |                                t          j
        t          |                     | d{V }t          j        |                                |                                |                                |                                          S )aQ  
        Send a message asynchronously.

        parameters
        ----------
        content: bytes
            The message payload

        Returns
        -------
        pulsar.MessageId
            The message id that represents the persisted position of the message.

        Raises
        ------
        PulsarException
        N)_pulsarMessageBuilderr#   asyncioget_running_loopcreate_futurer"   
send_asyncbuild	functoolspartial_set_futurer   	MessageId	partition	ledger_identry_idbatch_index)r   r#   builderfuturemsg_ids        r   sendzProducer.sendM   s      $ (**   )++99;;!!'--//93D[RX3Y3YZZZOO  	
 
 	
r   c                    K   t          j                                                    }| j                            t          j        t          |d                     | d{V  dS )z\
        Close the producer.

        Raises
        ------
        PulsarException
        Nr   )r'   r(   r)   r"   close_asyncr,   r-   r.   r   r5   s     r   closezProducer.closek   s`       )++99;;""9#4[&PT#U#U#UVVVr   r   N)r   r   r   r   r%   r   r   bytesr   r/   r7   r<   r   r   r   r   r   ;   s|         4!1 4d 4 4 4 4
% 
F,< 
 
 
 
<
 
 
 
 
 
r   r   c                   2    e Zd ZdZddZdedefdZddZdS )	Clientz6
    The asynchronous version of `pulsar.Client`.
    r   Nc                 >    t          j        |fi |j        | _        dS )z.
        See `pulsar.Client.__init__`
        N)r   r@   _client)r   service_urlkwargss      r   r   zClient.__init__|   s$     (.}['K'KF'K'K'Sr   topicc                   K   t          j                                                    }t          j                    }| j                            ||t          j        t          |                     t          | d{V           S )a  
        Create a new producer on a given topic

        Parameters
        ----------
        topic: str
            The topic name

        Returns
        -------
        Producer
            The producer created

        Raises
        ------
        PulsarException
        N)r'   r(   r)   r%   ProducerConfigurationrB   create_producer_asyncr,   r-   r.   r   )r   rE   r5   confs       r   create_producerzClient.create_producer   sr      $ )++99;;,..**5$	8I+W]8^8^___f%%%r   c                    K   t          j                                                    }| j                            t          j        t          |d                     | d{V  dS )z
        Close the client and all the associated producers and consumers

        Raises
        ------
        PulsarException
        Nr9   )r'   r(   r)   rB   r:   r,   r-   r.   r;   s     r   r<   zClient.close   s_       )++99;;  !2;d!S!S!STTTr   r=   )	r   r   r   r   r   strr   rJ   r<   r   r   r   r@   r@   w   sl         T T T T&3 &8 & & & &0
 
 
 
 
 
r   r@   r5   r   r   c                 h      fd}                                                      |           d S )Nc                      t           j        j        k    r                                d S                      t                               d S )N)r%   r   Ok
set_resultset_exceptionr   )r5   r   r   s   r   completez_set_future.<locals>.complete   sO    W^&&&e$$$$$  !8!899999r   )get_loopcall_soon_threadsafe)r5   r   r   rR   s   ``` r   r.   r.      sN    : : : : : : :
 OO**844444r   )r   r'   r,   typingr   r%   r   BaseExceptionr   r   r@   Futurer   r.   r   r   r   <module>rX      s   (              ; ; ; ; ;m ; ; ;8: : : : : : : :x- - - - - - - -^5 5 5s 5 5 5 5 5 5r   