HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/local/lib/python3.9/site-packages/kombu/__pycache__/messaging.cpython-39.pyc
a

X>h)b�@s�dZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZdd	lmZmZmZdd
lmZddlmZmZddlmZmZer�dd
lmZdZGdd�d�ZGdd�d�ZdS)zSending and receiving messages.�)�annotations)�count)�
TYPE_CHECKING�)�
maybe_declare)�compress)�PooledConnection�
is_connection�
maybe_channel)�Exchange�Queue�maybe_delivery_mode)�ContentDisallowed)�dumps�prepare_accept_content)�ChannelPromise�
maybe_list)�
TracebackType)rr�Producer�Consumerc@s�eZdZdZdZdZdZdZdZdZ	dZ
d.dd�Zdd�Zd	d
�Z
dd�Zd
d�Zd/dd�Zdeefdd�Zd0dd�Zd1dd�Zdd�Zdd�Zeee�Zdd�Zdd �Zd!d"d#d$d%�d&d'�Zd(d)�ZeZd2d*d+�Zed,d-��Z dS)3ra�Message Producer.

    Arguments:
    ---------
        channel (kombu.Connection, ChannelT): Connection or channel.
        exchange (kombu.entity.Exchange, str): Optional default exchange.
        routing_key (str): Optional default routing key.
        serializer (str): Default serializer. Default is `"json"`.
        compression (str): Default compression method.
            Default is no compression.
        auto_declare (bool): Automatically declare the default exchange
            at instantiation. Default is :const:`True`.
        on_return (Callable): Callback to call for undeliverable messages,
            when the `mandatory` or `immediate` arguments to
            :meth:`publish` is used. This callback needs the following
            signature: `(exception, exchange, routing_key, message)`.
            Note that the producer needs to drain events to use this feature.
    N�TcCsz||_||_|p|j|_|p |j|_|p,|j|_|p8|j|_d|_|jdurVtd�|_|durd||_|jrv|�	|j�dS)Nr)
�_channel�exchange�routing_key�
serializer�compression�	on_returnZ_channel_promiser�auto_declare�revive)�self�channelrrrrrr�r!�9/usr/local/lib/python3.9/site-packages/kombu/messaging.py�__init__As

zProducer.__init__cCsd|j�d�S)Nz<Producer: �>�r�rr!r!r"�__repr__SszProducer.__repr__cCs|j|��fS�N)�	__class__�__reduce_args__r&r!r!r"�
__reduce__VszProducer.__reduce__cCsd|j|j|j|j|jfSr()rrrrrr&r!r!r"r*Ys�zProducer.__reduce_args__cCs|jjr|j��dS)z�Declare the exchange.

        Note:
        ----
            This happens automatically at instantiation when
            the :attr:`auto_declare` flag is enabled.
        N)r�name�declarer&r!r!r"r-]szProducer.declareFcKs|rt||j|fi|��SdS)z=Declare exchange if not already declared during this session.N)rr )r�entity�retry�retry_policyr!r!r"rhszProducer.maybe_declarecCs2t||�r|j||p|j�fS|||p,|jj�fSr()�
isinstancer,�
delivery_moder)rrr2r
rr!r!r"�_delivery_detailsms
�
�zProducer._delivery_detailsrcKs|j}|durgn|}|
dur"in|
}
|dur2in|}|durD|jn|}|durV|jn|}|�|pf|j|�\}|d<|dur�tt|d��|d<|�||	||||
�\}}}|jr�|jj	r�|j|vr�|�
|j�|
r�|jj�
|�|jj||fi|��}||||||
|||||||||
|�S)a�Publish message to the specified exchange.

        Arguments:
        ---------
            body (Any): Message body.
            routing_key (str): Message routing key.
            delivery_mode (enum): See :attr:`delivery_mode`.
            mandatory (bool): Currently not supported.
            immediate (bool): Currently not supported.
            priority (int): Message priority. A number between 0 and 9.
            content_type (str): Content type. Default is auto-detect.
            content_encoding (str): Content encoding. Default is auto-detect.
            serializer (str): Serializer to use. Default is auto-detect.
            compression (str): Compression method to use.  Default is none.
            headers (Dict): Mapping of arbitrary headers to pass along
                with the message body.
            exchange (kombu.entity.Exchange, str): Override the exchange.
                Note that this exchange must have been declared.
            declare (Sequence[EntityT]): Optional list of required entities
                that must have been declared before publishing the message.
                The entities will be declared using
                :func:`~kombu.common.maybe_declare`.
            retry (bool): Retry publishing, or declaring entities if the
                connection is lost.
            retry_policy (Dict): Retry configuration, this is the keywords
                supported by :meth:`~kombu.Connection.ensure`.
            expiration (float): A TTL in seconds can be specified per message.
                Default is no expiration.
            timeout (float): Set timeout to wait maximum timeout second
                for message to publish.
            confirm_timeout (float): Set confirm timeout to wait maximum timeout second
                for message to confirm publishing if the channel is set to confirm publish mode.
            **properties (Any): Additional message properties, see AMQP spec.
        Nr2i��
expiration)�_publishrrr3r�str�int�_preparerr,�append�
connectionZtransport_options�updateZensure)r�bodyrr2�	mandatory�	immediate�priority�content_type�content_encodingr�headersrrr/r0r-r4�timeout�confirm_timeout�
propertiesr5Z
exchange_namer!r!r"�publishzs4)
��


�zProducer.publishc	Cs�|durin|}|j}|�||||||�}|rR|j}|D]}||fd|i|��q8|�d�}t|t�rp|j|d<|j||
|||	||
d�S)Nr/�reply_to)rrr=r>rCrD)r Zprepare_messager�getr1rr,Z
basic_publish)rr<r?r@rArBrErr=r>rr-rCrDr/r0r �messagerr.rGr!r!r"r5�s&�


�zProducer._publishcCsD|j}t|t�r@|�}|_|j�|�|jr@|jd�|j�|S)N�basic_return)rr1rrrr�events�add�rr r!r!r"�_get_channel�s
zProducer._get_channelcCs
||_dSr(r%rMr!r!r"�_set_channel�szProducer._set_channelcspt|�r"|��|_t�fdd��}t|t�r@||_|�|�|_n,||_|jr`|jjd�|j�|�|�|_dS)z*Revive the producer after connection loss.cs�jSr()Zdefault_channelr!�r:r!r"�<lambda>��z!Producer.revive.<locals>.<lambda>rJN)	r	�__connection__rr1rrrrKrLrMr!rPr"r�s
zProducer.revivecCs|Sr(r!r&r!r!r"�	__enter__�szProducer.__enter__�type[BaseException] | None�BaseException | None�TracebackType | None�None��exc_type�exc_val�exc_tb�returncCs:|jdur.|dur.t|jt�r.|jj�|j�|��dSr()rSr1r�_pool�replace�release)rrZr[r\r!r!r"�__exit__�szProducer.__exit__cCsdSr(r!r&r!r!r"r`szProducer.releasecCsh|s"|p|j}t||d�\}}}n&t|t�r@|s4d}|�|�}n|sHd}|r^t||�\}|d<|||fS)N)rzutf-8�binaryr)rrr1r6�encoder)rr<rr@rArrBr!r!r"r8s

��
zProducer._preparecCs*z|jp|jjjWSty$Yn0dSr()rSr r:�client�AttributeErrorr&r!r!r"r:+szProducer.connection)NNNNNN)F)NNFFrNNNNNNFNNNNN)NNFN)NNNNN)!�__name__�
__module__�__qualname__�__doc__rrrrrrrSr#r'r+r*r-rr
rr3rFr5rNrO�propertyr rrTrar`�closer8r:r!r!r!r"rsV�

�

�
L�
	
�
rc	@s,eZdZdZeZdZdZdZdZdZ	dZ
dZdZdZ
dZed�Zd9dd�Zedd��Zejd	d��Zd
d�Zdd
�Zdd�Zdd�Zddddd�dd�Zdd�Zd:dd�Zdd�ZeZdd �Zd!d"�Zd#d$�Zd%d&�Z d;d)d*�Z!d<d+d,�Z"d-d.�Z#dedfd/d0�Z$d=d1d2�Z%d3d4�Z&d5d6�Z'ed7d8��Z(dS)>raMessage consumer.

    Arguments:
    ---------
        channel (kombu.Connection, ChannelT): see :attr:`channel`.
        queues (Sequence[kombu.Queue]): see :attr:`queues`.
        no_ack (bool): see :attr:`no_ack`.
        auto_declare (bool): see :attr:`auto_declare`
        callbacks (Sequence[Callable]): see :attr:`callbacks`.
        on_message (Callable): See :attr:`on_message`
        on_decode_error (Callable): see :attr:`on_decode_error`.
        prefetch_count (int): see :attr:`prefetch_count`.
    NTrcCs�||_t|pg�|_|dur"|jn||_|dur:|jp<gn||_||_|
|_i|_|dur`||_|durn||_	t
|�|_|	|_|jr�|�
|j�dSr()r r�queues�no_ack�	callbacks�
on_message�
tag_prefix�_active_tagsr�on_decode_errorr�accept�prefetch_countr)rr rlrmrrnrrrorsrtrpr!r!r"r#�s"�
zConsumer.__init__cCst|j���Sr()�list�_queues�valuesr&r!r!r"rl�szConsumer.queuescCsdd�|D�|_dS)NcSsi|]}|j|�qSr!)r,)�.0�qr!r!r"�
<dictcomp>�rRz#Consumer.queues.<locals>.<dictcomp>)rv)rrlr!r!r"rl�scCs�|j��t|�}|_t|j���D]6\}}|j�|d�||j�}|j|j<|�	|�q&|j
rl|��|jdur�|j
|jd�dS)z&Revive consumer after connection loss.N)rt)rq�clearr
r rurv�items�popr,rrr-rt�qos)rr �qname�queuer!r!r"r�s

zConsumer.revivecCs|j��D]}|��q
dS)z�Declare queues, exchanges and bindings.

        Note:
        ----
            This is done automatically at instantiation
            when :attr:`auto_declare` is set.
        N)rvrwr-�rr�r!r!r"r-�szConsumer.declarecCs|j�|�dS)a%Register a new callback to be called when a message is received.

        Note:
        ----
            The signature of the callback needs to accept two arguments:
            `(body, message)`, which is the decoded message body
            and the :class:`~kombu.Message` instance.
        N)rnr9)r�callbackr!r!r"�register_callback�s	zConsumer.register_callbackcCs|��|Sr()�consumer&r!r!r"rT�szConsumer.__enter__rUrVrWrXrYcCsH|jrD|jjrD|jjjj}t||�sDz|��WntyBYn0dSr()r r:rdZconnection_errorsr1�cancel�	Exception)rrZr[r\Zconn_errorsr!r!r"ra�s
zConsumer.__exit__cCs(||j�}|jr|��||j|j<|S)z�Add a queue to the list of queues to consume from.

        Note:
        ----
            This will not start consuming from the queue,
            for that you will have to call :meth:`consume` after.
        )r rr-rvr,r�r!r!r"�	add_queue�s

zConsumer.add_queuecCsht|j���}|rd|dur |jn|}|dd�|d}}|D]}|j||dd�q>|j||dd�dS)aVStart consuming messages.

        Can be called multiple times, but note that while it
        will consume from new queues added since the last call,
        it will not cancel consuming from removed queues (
        use :meth:`cancel_by_queue`).

        Arguments:
        ---------
            no_ack (bool): See :attr:`no_ack`.
        N���T�rm�nowaitF)rurvrwrm�_basic_consume)rrmrl�H�Tr�r!r!r"r��szConsumer.consumecCs.|jj}|j��D]}||�q|j��dS)z�End all active queue consumers.

        Note:
        ----
            This does not affect already delivered messages, but it does
            mean the server will not send any more messages for this consumer.
        N)r �basic_cancelrqrwr{)rr��tagr!r!r"r�s
zConsumer.cancelc
Cslt|t�r|jn|}zBz|j�|�}Wnty8Yn0|j�|�W|j�|d�n|j�|d�0dS)zCancel consumer by queue name.N)	r1rr,rqr}�KeyErrorr r�rv)rr�rr�r!r!r"�cancel_by_queueszConsumer.cancel_by_queuecCs|}t|t�r|j}||jvS)z8Return :const:`True` if currently consuming from queue'.)r1rr,rq)rr�r,r!r!r"�consuming_froms
zConsumer.consuming_fromcCstdd�|j��D��S)z�Purge messages from all queues.

        Warning:
        -------
            This will *delete all ready messages*, there is no undo operation.
        css|]}|��VqdSr()�purge)rxr�r!r!r"�	<genexpr>-rRz!Consumer.purge.<locals>.<genexpr>)�sumrvrwr&r!r!r"r�&szConsumer.purgecCs|j�|�dS)a�Enable/disable flow from peer.

        This is a simple flow-control mechanism that a peer can use
        to avoid overflowing its queues or otherwise finding itself
        receiving more messages than it can process.

        The peer that receives a request to stop sending content
        will finish sending the current content (if any), and then wait
        until flow is reactivated.
        N)r �flow)r�activer!r!r"r�/sz
Consumer.flowrFcCs|j�|||�S)aSpecify quality of service.

        The client can request that messages should be sent in
        advance so that when the client finishes processing a message,
        the following message is already held locally, rather than needing
        to be sent down the channel. Prefetching gives a performance
        improvement.

        The prefetch window is Ignored if the :attr:`no_ack` option is set.

        Arguments:
        ---------
            prefetch_size (int): Specify the prefetch window in octets.
                The server will send a message in advance if it is equal to
                or smaller in size than the available prefetch size (and
                also falls within other prefetch limits). May be set to zero,
                meaning "no specific limit", although other prefetch limits
                may still apply.

            prefetch_count (int): Specify the prefetch window in terms of
                whole messages.

            apply_global (bool): Apply new settings globally on all channels.
        )r Z	basic_qos)rZ
prefetch_sizertZapply_globalr!r!r"r~<s�zConsumer.qoscCs|jj|d�S)a�Redeliver unacknowledged messages.

        Asks the broker to redeliver all unacknowledged messages
        on the specified channel.

        Arguments:
        ---------
            requeue (bool): By default the messages will be redelivered
                to the original recipient. With `requeue` set to true, the
                server will attempt to requeue the message, potentially then
                delivering it to an alternative subscriber.
        )�requeue)r Z
basic_recover)rr�r!r!r"�recoverYs
zConsumer.recovercs*|j}|std����fdd�|D�dS)a�Method called when a message is received.

        This dispatches to the registered :attr:`callbacks`.

        Arguments:
        ---------
            body (Any): The decoded message body.
            message (~kombu.Message): The message instance.

        Raises
        ------
            NotImplementedError: If no consumer callbacks have been
                registered.
        z$Consumer does not have any callbackscsg|]}|����qSr!r!)rxr��r<rIr!r"�
<listcomp>zrRz$Consumer.receive.<locals>.<listcomp>N)rn�NotImplementedError)rr<rIrnr!r�r"�receivehszConsumer.receivecCs:|j�|j�}|dur6|�||�}|j||j||d�|S)Nr�)rqrHr,�_add_tagr��_receive_callback)rr��consumer_tagrmr�r�r!r!r"r�|s
�zConsumer._basic_consumecCs(|pd�|jt|j��}||j|j<|S)Nz{}{})�formatrp�next�_tagsrqr,)rr�r�r�r!r!r"r��s
�zConsumer._add_tagc
Cs�|j}|j|jd}}}zNt|dd�}|r4||�}|durB||_|jrV|�|j�WS|r^dn|��}Wn8ty�}z |js��|�||�WYd}~n"d}~00|r�||�S|�	||�SdS)NZmessage_to_python)
rsror �getattr�errorsZ_reraise_errorrr�decoder�r�)rrIrsZon_mr �decodedZm2p�excr!r!r"r��s "zConsumer._receive_callbackcCsdt|�j�d|j�d�S)N�<z: r$)�typerfrlr&r!r!r"r'�szConsumer.__repr__cCs$z|jjjWStyYn0dSr()r r:rdrer&r!r!r"r:�szConsumer.connection)	NNNNNNNNN)N)rrF)F)N))rfrgrhrirr rlrmrrnrorrrsrtrvrr�r#rj�setterrr-r�rTrar�r�r�rkr�r�r�r�r~r�r�r�r�r�r'r:r!r!r!r"r3sZ	�




	

�
	
rN) ri�
__future__r�	itertoolsr�typingr�commonrrrr:rr	r
r.rrr
�
exceptionsrZ
serializationrrZutils.functionalrr�typesr�__all__rrr!r!r!r"�<module>s"