
    )Jf                         d Z ddlZddl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 ddlmZmZmZ ddlmZ  ej        e          ZdZ G d de          Z G d	 d
e          ZdS )zThe Channel class provides a wrapper for interacting with RabbitMQ
implementing the methods and behaviors for an AMQP Channel.

    N)Enum)unicode_typedictkeys
is_integer)ExchangeTypei  c                      e Zd ZdZdZdZdZdZedededed	iZd
Z	d Z
d Zd ZdTdZd Zd Zd Zd ZdUdZdVdZ	 	 	 	 	 dWdZd ZdXdZdYdZ	 	 dZdZ	 	 	 	 d[dZd\dZd]d Zd^d"Zd_d#Zed$             Z	 	 	 d`d%Z e!j"        ddddddfd&Z#dad'Z$	 	 	 	 	 dbd(Z%d_d)Z&ed*             Z'ed+             Z(ed,             Z)ed-             Z*d. Z+	 	 	 dcd/Z,	 	 	 	 	 	 ddd0Z-	 	 	 ded1Z.d_d2Z/	 	 	 	 dfd3Z0d_d4Z1d_d5Z2d_d6Z3d7 Z4d8 Z5d9 Z6d: Z7d; Z8d< Z9d= Z:d> Z;d? Z<d@ Z=dA Z>dB Z?dC Z@dD ZAdE ZBdF ZCdG ZDdH ZEdI ZFdJ ZGdK ZHdL ZIdM ZJdgdNZKdO ZLd_dPZMdQ ZNdR ZOdS ZPdS )hChannela  A Channel is the primary communication method for interacting with
    RabbitMQ. It is recommended that you do not directly invoke the creation of
    a channel object in your application code but rather construct a channel by
    calling the active connection's channel() method.

    r            CLOSEDOPENINGOPENCLOSING_on_channel_cleanupc                    t          |t                    st          j        |          t	          j        |           || _        |j        | _        || _        d| _	        t                      | _        t          j        t                                | _        d| _        d| _        t%                      | _        t)                      | _        t%                      | _        d| _        d| _        || _        | j        | _        d| _        d| _        dS )as  Create a new instance of the Channel

        :param pika.connection.Connection connection: The connection
        :param int channel_number: The channel number for this instance
        :param callable on_open_callback: The callback to call on channel open.
            The callback will be invoked with the `Channel` instance as its only
            argument.

        TNF)
isinstanceint
exceptionsInvalidChannelNumber
validatorsrpc_completion_callbackchannel_number	callbacks
connectionflow_activeContentFrameAssembler_content_assemblercollectionsdequelist_blocked	_blocking_has_on_flow_callbackset
_cancelleddict
_consumers_consumers_with_noack_on_flowok_callback_on_getok_callback_on_openok_callbackr   _state_closing_reason_cookie)selfr   r   on_open_callbacks       O/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/pika/channel.py__init__zChannel.__init__2   s     .#.. 	B1.AAA*+;<<<,#-$  "7"9"9#)$&&11%*"%%&&%(UU"#' "&#3 k  $     c                     | j         S )zNReturn the channel object as its channel number

        :rtype: int

        )r   r0   s    r2   __int__zChannel.__int__`   s     ""r4   c           	      h    d| j         j        d| j        d| j        | j                 d| j        d	S )N<z number= z conn=>)	__class____name__r   _STATE_NAMESr-   r   r6   s    r2   __repr__zChannel.__repr__h   sB     N###T%8%8%8dk***DOOO= 	=r4   Tc                 T    |D ]$}| j                             | j        |||           %dS )a  Pass in a callback handler and a list replies from the
        RabbitMQ broker which you'd like the callback notified of. Callbacks
        should allow for the frame parameter to be passed in.

        :param callable callback: The callback to call
        :param list replies: The replies to get a callback for
        :param bool one_shot: Only handle the first type callback

        Nr   addr   )r0   callbackrepliesone_shotreplys        r2   add_callbackzChannel.add_callbackm   sC      	O 	OENt2E8XNNNN	O 	Or4   c                 h    | j                             | j        t          j        j        |d           dS )a  Pass a callback function that will be called when the basic_cancel
        is sent by the server. The callback function should receive a frame
        parameter.

        :param callable callback: The callback to call on Basic.Cancel from
            broker

        FN)r   rB   r   specBasicCancelr0   rC   s     r2   add_on_cancel_callbackzChannel.add_on_cancel_callbackz   s9     	4.
0A8 	" 	" 	" 	" 	"r4   c                 L    | j                             | j        d|d|            dS )a  Pass a callback function that will be called when the channel is
        closed. The callback function will receive the channel and an exception
        describing why the channel was closed.

        If the channel is closed by broker via Channel.Close, the callback will
        receive `ChannelClosedByBroker` as the reason.

        If graceful user-initiated channel closing completes successfully (
        either directly of indirectly by closing a connection containing the
        channel) and closing concludes gracefully without Channel.Close from the
        broker and without loss of connection, the callback will receive
        `ChannelClosedByClient` exception as reason.

        If channel was closed due to loss of connection, the callback will
        receive another exception type describing the failure.

        :param callable callback: The callback, having the signature:
            callback(Channel, Exception reason)

        _on_channel_closeFNrA   rL   s     r2   add_on_close_callbackzChannel.add_on_close_callback   s7    * 	4.0CX $	( 	( 	( 	( 	(r4   c                 v    d| _         | j                            | j        t          j        j        |d           dS )a  Pass a callback function that will be called when Channel.Flow is
        called by the remote server. Note that newer versions of RabbitMQ
        will not issue this but instead use TCP backpressure

        :param callable callback: The callback function

        TFN)r$   r   rB   r   rI   r	   FlowrL   s     r2   add_on_flow_callbackzChannel.add_on_flow_callback   sA     &*"4.0A8 	" 	" 	" 	" 	"r4   c                 J    | j                             | j        d|d           dS )aM  Pass a callback function that will be called when basic_publish is
        sent a message that has been rejected and returned by the server.

        :param callable callback: The function to call, having the signature
                                callback(channel, method, properties, body)
                                where
                                - channel: pika.channel.Channel
                                - method: pika.spec.Basic.Return
                                - properties: pika.spec.BasicProperties
                                - body: bytes

        
_on_returnFNrA   rL   s     r2   add_on_return_callbackzChannel.add_on_return_callback   s)     	4.hNNNNNr4   Fc                     |                                   |                     t          j                            ||                    S )a  Acknowledge one or more messages. When sent by the client, this
        method acknowledges one or more messages delivered via the Deliver or
        Get-Ok methods. When sent by server, this method acknowledges one or
        more messages published with the Publish method on a channel in
        confirm mode. The acknowledgement can be for a single message or a
        set of messages up to and including a specific message.

        :param integer delivery_tag: int/long The server-assigned delivery tag
        :param bool multiple: If set to True, the delivery tag is treated as
                              "up to and including", so that multiple messages
                              can be acknowledged with a single method. If set
                              to False, the delivery tag refers to a single
                              message. If the multiple field is 1, and the
                              delivery tag is zero, this indicates
                              acknowledgement of all outstanding messages.

        )_raise_if_not_open_send_methodrI   rJ   Ack)r0   delivery_tagmultiples      r2   	basic_ackzChannel.basic_ack   s:    $ 	!!!  h!G!GHHHr4    Nc                    t          j        |d           |                                  t          j        |          }|| j        v rt
                              d|           dS || j        vrt
                              d|           dS t
                              d||           |r| j        |= |0| j	        
                    | j        t          j        j        |           | j        
                    |           |                     t          j                            ||          |s| j        nd|st          j        j        d|ifgng            dS )a  This method cancels a consumer. This does not affect already
        delivered messages, but it does mean the server will not send any more
        messages for that consumer. The client may receive an arbitrary number
        of messages in between sending the cancel method and receiving the
        cancel-ok reply. It may also be sent from the server to the client in
        the event of the consumer being unexpectedly cancelled (i.e. cancelled
        for any reason other than the server receiving the corresponding
        basic.cancel from the client). This allows clients to be notified of
        the loss of consumers due to events such as queue deletion.

        :param str consumer_tag: Identifier for the consumer
        :param callable callback: callback(pika.frame.Method) for method
            Basic.CancelOk. If None, do not expect a Basic.CancelOk response,
            otherwise, callback must be callable

        :raises ValueError:

        consumer_tagz1basic_cancel - consumer is already cancelling: %sNz%basic_cancel - consumer not found: %sz#Cancelling consumer: %s (nowait=%s))r`   nowait)r   require_stringrX   r   r&   LOGGERwarningr(   debugr   rB   r   rI   rJ   CancelOk_rpcrK   _on_cancelok)r0   r`   rC   ra   s       r2   basic_cancelzChannel.basic_cancel   s   & 	!,???!!!3H==4?** NNN') ) )Ft..NNB') ) )F:L	 	 	  	.
 -Nt2DJ4G') ) ) 	L)))		$*##f#MM+1;$##t $,DJ'$l*   )+		- 	- 	- 	- 	-r4   c           
      8   t          j        |d           t          j        |           |                                  t          j        |           |s|                                 }|| j        v s	|| j        v rt          j	        |          |r| j
                            |           || j        |<   || j        n|}|                     t          j                            |||||pt#                                |t          j        j        d|ifg           |S )a  Sends the AMQP 0-9-1 command Basic.Consume to the broker and binds messages
        for the consumer_tag to the consumer callback. If you do not pass in
        a consumer_tag, one will be automatically generated for you. Returns
        the consumer tag.

        For more information on basic_consume, see:
        Tutorial 2 at http://www.rabbitmq.com/getstarted.html
        http://www.rabbitmq.com/confirms.html
        http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume

        :param str queue: The queue to consume from. Use the empty string to
            specify the most recent server-named queue for this channel
        :param callable on_message_callback: The function to call when
            consuming with the signature
            on_message_callback(channel, method, properties, body), where
            - channel: pika.channel.Channel
            - method: pika.spec.Basic.Deliver
            - properties: pika.spec.BasicProperties
            - body: bytes
        :param bool auto_ack: if set to True, automatic acknowledgement mode
            will be used (see http://www.rabbitmq.com/confirms.html).
            This corresponds with the 'no_ack' parameter in the basic.consume
            AMQP 0.9.1 method
        :param bool exclusive: Don't allow other consumers on the queue
        :param str consumer_tag: Specify your own consumer tag
        :param dict arguments: Custom key/value pair arguments for the consumer
        :param callable callback: callback(pika.frame.Method) for method
          Basic.ConsumeOk.
        :returns: Consumer tag which may be used to cancel the consumer.
        :rtype: str
        :raises ValueError:

        queueN)rk   r`   no_ack	exclusive	argumentsr`   )r   rb   require_callbackrX   r   _generate_consumer_tagr(   r&   r   DuplicateConsumerTagr)   rB   _on_eventokrg   rI   rJ   Consumer'   	ConsumeOk)	r0   rk   on_message_callbackauto_ackrm   r`   rn   rC   rpc_callbacks	            r2   basic_consumezChannel.basic_consume  sA   R 	!%111#$7888!!!*8444  	96688L4?**ldo.M.M1,??? 	9&**<888(;%+3+;t''		JU,8&.)2)2)<dff	  > > @Lj"%  	 	 	 r4   c                 F    d| j         t          j                    j        fz  S )zGenerate a consumer tag

        NOTE: this protected method may be called by derived classes

        :returns: consumer tag
        :rtype: str

        z	ctag%i.%s)r   uuiduuid4hexr6   s    r2   rp   zChannel._generate_consumer_tagP  s      d14:<<3CDDDr4   c                    t          j        |d           t          j        |           | j        t	          j                    || _        |                     t          j        	                    ||                     dS )a6  Get a single message from the AMQP broker. If you want to
        be notified of Basic.GetEmpty, use the Channel.add_callback method
        adding your Basic.GetEmpty callback which should expect only one
        parameter, frame. Due to implementation details, this cannot be called
        a second time until the callback is executed.  For more information on
        basic_get and its parameters, see:

        http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.get

        :param str queue: The queue from which to get a message. Use the empty
            string to specify the most recent server-named queue for this
            channel
        :param callable callback: The callback to call with a message that has
            the signature callback(channel, method, properties, body), where:
            - channel: pika.channel.Channel
            - method: pika.spec.Basic.GetOk
            - properties: pika.spec.BasicProperties
            - body: bytes
        :param bool auto_ack: Tell the broker to not expect a reply
        :raises ValueError:

        rk   N)rk   rl   )
r   rb   ro   r+   r   DuplicateGetOkCallbackrY   rI   rJ   Get)r0   rk   rC   rv   s       r2   	basic_getzChannel.basic_get[  sv    . 	!%111#H---".3555"* 	$*..uX.FFGGGGGr4   c                     |                                   |                     t          j                            |||                    S )aL  This method allows a client to reject one or more incoming messages.
        It can be used to interrupt and cancel large incoming messages, or
        return untreatable messages to their original queue.

        :param integer delivery_tag: int/long The server-assigned delivery tag
        :param bool multiple: If set to True, the delivery tag is treated as
                              "up to and including", so that multiple messages
                              can be acknowledged with a single method. If set
                              to False, the delivery tag refers to a single
                              message. If the multiple field is 1, and the
                              delivery tag is zero, this indicates
                              acknowledgement of all outstanding messages.
        :param bool requeue: If requeue is true, the server will attempt to
                             requeue the message. If requeue is false or the
                             requeue attempt fails the messages are discarded or
                             dead-lettered.

        )rX   rY   rI   rJ   Nack)r0   r[   r\   requeues       r2   
basic_nackzChannel.basic_nack~  sC    & 	!!!  JOOL(G<<> > 	>r4   c                    |                                   t          |t                    r|                    d          }|pt	          j                    }|                     t          j                            |||          ||f           dS )a  Publish to the channel with the given exchange, routing key and body.
        For more information on basic_publish and what the parameters do, see:

        http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.publish

        :param str exchange: The exchange to publish to
        :param str routing_key: The routing key to bind on
        :param bytes body: The message body
        :param pika.spec.BasicProperties properties: Basic.properties
        :param bool mandatory: The mandatory flag

        zutf-8)exchangerouting_key	mandatoryN)	rX   r   r   encoderI   BasicPropertiesrY   rJ   Publish)r0   r   r   body
propertiesr   s         r2   basic_publishzChannel.basic_publish  s    $ 	!!!dL)) 	(;;w''D94#7#9#9
J+6)2  4 46@$5G	I 	I 	I 	I 	Ir4   c                 2   |                                   t          j        |           t          j        d|           t          j        d|           |                     t
          j                            |||          |t
          j        j        g          S )a  Specify quality of service. This method requests a specific quality
        of service. The client can request that messages 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. The QoS can be applied separately to each new consumer on
        channel or shared across all consumers on the channel. Prefetching
        gives a performance improvement.

        :param int prefetch_size:  This field specifies the prefetch window
                                   size. 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 into other prefetch limits). May be set
                                   to zero, meaning "no specific limit",
                                   although other prefetch limits may still
                                   apply. The prefetch-size is ignored by
                                   consumers who have enabled the no-ack option.
        :param int prefetch_count: Specifies a prefetch window in terms of whole
                                   messages. This field may be used in
                                   combination with the prefetch-size field; a
                                   message will only be sent in advance if both
                                   prefetch windows (and those at the channel
                                   and connection level) allow it. The
                                   prefetch-count is ignored by consumers who
                                   have enabled the no-ack option.
        :param bool global_qos:    Should the QoS be shared across all
                                   consumers on the channel.
        :param callable callback: The callback to call for Basic.QosOk response
        :raises ValueError:

        prefetch_sizeprefetch_count)	rX   r   r   zero_or_greaterrg   rI   rJ   QosQosOk)r0   r   r   
global_qosrC   s        r2   	basic_qoszChannel.basic_qos  s    H 	!!!*8444"?MBBB"#3^DDDyyJNN=.*EExZ    	 r4   c                     |                                   t          |          st          d          |                     t          j                            ||                    S )a_  Reject an incoming message. This method allows a client to reject a
        message. It can be used to interrupt and cancel large incoming messages,
        or return untreatable messages to their original queue.

        :param integer delivery_tag: int/long The server-assigned delivery tag
        :param bool requeue: If requeue is true, the server will attempt to
                             requeue the message. If requeue is false or the
                             requeue attempt fails the messages are discarded or
                             dead-lettered.
        :raises: TypeError

        zdelivery_tag must be an integer)rX   r   	TypeErrorrY   rI   rJ   Reject)r0   r[   r   s      r2   basic_rejectzChannel.basic_reject  s[     	!!!,'' 	?=>>>  !2!2<!I!IJJJr4   c                     |                                   t          j        |           |                     t          j                            |          |t          j        j        g          S )a  This method asks the server to redeliver all unacknowledged messages
        on a specified channel. Zero or more messages may be redelivered. This
        method replaces the asynchronous Recover.

        :param bool requeue: If False, the message will be redelivered to the
                             original recipient. If True, the server will
                             attempt to requeue the message, potentially then
                             delivering it to an alternative subscriber.
        :param callable callback: Callback to call when receiving
            Basic.RecoverOk
        :param callable callback: callback(pika.frame.Method) for method
            Basic.RecoverOk
        :raises ValueError:

        )rX   r   r   rg   rI   rJ   Recover	RecoverOk)r0   r   rC   s      r2   basic_recoverzChannel.basic_recover  s\      	!!!*8444yy++G44h*./1 1 	1r4   Normal shutdownc                    | j         s| j        r|                                  t                              d|||            t          j        ||          | _        t          | j	                  D ]!}|| j
        vr|                     |           "|                     | j                   |                     t          j                            ||dd          | j        t          j        j        g           dS )a  Invoke a graceful shutdown of the channel with the AMQP Broker.

        If channel is OPENING, transition to CLOSING and suppress the incoming
        Channel.OpenOk, if any.

        :param int reply_code: The reason code to send to broker
        :param str reply_text: The reason text to send to broker

        :raises ChannelWrongStateError: if channel is closed or closing

        zClosing channel (%s): %r on %s)r`   r   N)	is_closed
is_closingrX   rc   infor   ChannelClosedByClientr.   r   r(   r&   ri   
_set_stater   rg   rI   r	   Close_on_closeokCloseOk)r0   
reply_code
reply_textr`   s       r2   closezChannel.close  s    > 	&T_ 	& ##%%% 	4j*	 	 	
  *?
 $  $ %T_55 	= 	=L4?22!!|!<<< 	%%%		$,$$ZQBB"T\%9$:	< 	< 	< 	< 	<r4   c                 >   t          |          st          d          |                                  t          j        |          }| j        j        r| j        j        st          j	        d          | j
                            | j        t          j        j        |d           | j
                            | j        t          j        j        |d           |                     t          j                            |          ||st          j        j        gng            dS )a  Turn on Confirm mode in the channel. Pass in a callback to be
        notified by the Broker when a message has been confirmed as received or
        rejected (Basic.Ack, Basic.Nack) from the broker to the publisher.

        For more information see:
            https://www.rabbitmq.com/confirms.html

        :param callable ack_nack_callback: Required callback for delivery
            confirmations that has the following signature:
            callback(pika.frame.Method), where method_frame contains
            either method `spec.Basic.Ack` or `spec.Basic.Nack`.
        :param callable callback: callback(pika.frame.Method) for method
            Confirm.SelectOk
        :raises ValueError:

        zSconfirm_delivery requires a callback to receieve Basic.Ack/Basic.Nack notificationsz&Confirm.Select not Supported by ServerFN)callable
ValueErrorrX   r   r   r   publisher_confirmsr   r   MethodNotImplementedr   rB   r   rI   rJ   rZ   r   rg   ConfirmSelectSelectOk)r0   ack_nack_callbackrC   ra   s       r2   confirm_deliveryzChannel.confirm_delivery+  s/   " )** 	O  N O O O 	!!!3H==2 	:*	:18: : : 	4.
,e	5 	5 	54.
,e	5 	5 	5 			$,%%f--x17?4<())R	A 	A 	A 	A 	Ar4   c                 *    t          | j                  S )zaProperty method that returns a list of currently active consumers

        :rtype: list

        )r   r(   r6   s    r2   consumer_tagszChannel.consumer_tagsS  s     (((r4   c                 \   |                                   t          j        |d           t          j        |d           t          j        |          }|                     t
          j                            d|||||pt                                ||st
          j        j	        gng           S )a  Bind an exchange to another exchange.

        :param str destination: The destination exchange to bind
        :param str source: The source exchange to bind to
        :param str routing_key: The routing key to bind on
        :param dict arguments: Custom key/value pair arguments for the binding
        :param callable callback: callback(pika.frame.Method) for method Exchange.BindOk
        :raises ValueError:

        destinationsourcer   )
rX   r   rb   r   rg   rI   ExchangeBindr'   BindOkr0   r   r   r   rn   rC   ra   s          r2   exchange_bindzChannel.exchange_bind\  s      	!!!!+}===!&(3333H==yyMq+v{F(2DFF4 45=*08T]!""b: : 	:r4   c	                 p   t          j        |d           |                                  t          j        |          }	t	          |t
                    r|j        }|                     t          j	        
                    d|||||||	|pt                      	  	        ||	st          j	        j        gng           S )a  This method creates an exchange if it does not already exist, and if
        the exchange exists, verifies that it is of the correct and expected
        class.

        If passive set, the server will reply with Declare-Ok if the exchange
        already exists with the same name, and raise an error if not and if the
        exchange does not already exist, the server MUST raise a channel
        exception with reply code 404 (not found).

        :param str exchange: The exchange name consists of a non-empty sequence
            of these characters: letters, digits, hyphen, underscore, period,
            or colon
        :param str exchange_type: The exchange type to use
        :param bool passive: Perform a declare or just check to see if it exists
        :param bool durable: Survive a reboot of RabbitMQ
        :param bool auto_delete: Remove when no more queues are bound to it
        :param bool internal: Can only be published to by other exchanges
        :param dict arguments: Custom key/value pair arguments for the exchange
        :param callable callback: callback(pika.frame.Method) for method Exchange.DeclareOk
        :raises ValueError:

        r   r   )r   rb   rX   r   r   r   valuerg   rI   r   Declarer'   	DeclareOk)
r0   r   exchange_typepassivedurableauto_deleteinternalrn   rC   ra   s
             r2   exchange_declarezChannel.exchange_declareu  s    > 	!(J777!!!3H==mT** 	0)/MyyM!!!X}gw"-x B)"&&&* *+3-3;T]$%%	= = 	=r4   c                     |                                   t          j        |          }|                     t          j                            d|||          ||st          j        j        gng           S )a
  Delete the exchange.

        :param str exchange: The exchange name
        :param bool if_unused: only delete if the exchange is unused
        :param callable callback: callback(pika.frame.Method) for method Exchange.DeleteOk
        :raises ValueError:

        r   )rX   r   r   rg   rI   r   DeleteDeleteOk)r0   r   	if_unusedrC   ra   s        r2   exchange_deletezChannel.exchange_delete  st     	!!!3H==yy--a9.46 67?9?G$-011RI I 	Ir4   c           
          |                                   t          j        |          }|                     t          j                            d|||||          ||st          j        j        gng           S )a  Unbind an exchange from another exchange.

        :param str destination: The destination exchange to unbind
        :param str source: The source exchange to unbind from
        :param str routing_key: The routing key to unbind
        :param dict arguments: Custom key/value pair arguments for the binding
        :param callable callback: callback(pika.frame.Method) for method Exchange.UnbindOk
        :raises ValueError:

        r   )rX   r   r   rg   rI   r   UnbindUnbindOkr   s          r2   exchange_unbindzChannel.exchange_unbind  sv      	!!!3H==yyM  Kf!*, ,-5,2:T]#$$< < 	<r4   c                     |                                   t          j        |           || _        |                     t
          j                            |          | j        t
          j        j	        g           dS )a  Turn Channel flow control off and on. Pass a callback to be notified
        of the response from the server. active is a bool. Callback should
        expect a bool in response indicating channel flow state. For more
        information, please reference:

        http://www.rabbitmq.com/amqp-0-9-1-reference.html#channel.flow

        :param bool active: Turn flow on or off
        :param callable callback: callback(bool) upon completion
        :raises ValueError:

        N)
rX   r   r   r*   rg   rI   r	   rR   
_on_flowokFlowOk)r0   activerC   s      r2   flowzChannel.flow  sp     	!!!*8444#+ 		$,##F++T_<&'	) 	) 	) 	) 	)r4   c                 "    | j         | j        k    S )zFReturns True if the channel is closed.

        :rtype: bool

        )r-   r   r6   s    r2   r   zChannel.is_closed  s     {dk))r4   c                 "    | j         | j        k    S )zoReturns True if client-initiated closing of the channel is in
        progress.

        :rtype: bool

        )r-   r   r6   s    r2   r   zChannel.is_closing  s     {dl**r4   c                 "    | j         | j        k    S )zDReturns True if the channel is open.

        :rtype: bool

        )r-   r   r6   s    r2   is_openzChannel.is_open  s     {di''r4   c                 "    | j         | j        k    S )zGReturns True if the channel is opening.

        :rtype: bool

        )r-   r   r6   s    r2   
is_openingzChannel.is_opening  s     {dl**r4   c                     |                      | j                   |                                  |                     t          j                                        | j        t          j        j        g           dS )zOpen the channelN)	r   r   _add_callbacksrg   rI   r	   Open
_on_openokOpenOkr6   s    r2   openzChannel.open  s\    %%%		$,##%%t9L8MNNNNNr4   c                 d   t          j        |d           t          j        |d           |                                  t          j        |          }||}|                     t
          j                            d|||||pt                                ||st
          j        j	        gng           S )a  Bind the queue to the specified exchange

        :param str queue: The queue to bind to the exchange
        :param str exchange: The source exchange to bind to
        :param str routing_key: The routing key to bind on
        :param dict arguments: Custom key/value pair arguments for the binding
        :param callable callback: callback(pika.frame.Method) for method Queue.BindOk
        :raises ValueError:

        rk   r   Nr   )
r   rb   rX   r   rg   rI   Queuer   r'   r   )r0   rk   r   r   rn   rC   ra   s          r2   
queue_bindzChannel.queue_bind  s      	!%111!(J777!!!3H==KyyJOOAuhV%/1 12:'-5TZ27 7 	7r4   c                 n   t          j        |d           |                                  t          j        |          }|rt          j        j        d|if}	nt          j        j        }	|s|	gng }
|                     t          j                            d|||||||pt                                ||
          S )a  Declare queue, create if needed. This method creates or checks a
        queue. When creating a new queue the client can specify various
        properties that control the durability of the queue and its contents,
        and the level of sharing for the queue.

        Use an empty string as the queue name for the broker to auto-generate
        one

        :param str queue: The queue name; if empty string, the broker will
            create a unique queue name
        :param bool passive: Only check to see if the queue exists
        :param bool durable: Survive reboots of the broker
        :param bool exclusive: Only allow access by the current connection
        :param bool auto_delete: Delete after consumer cancels or disconnects
        :param dict arguments: Custom key/value arguments for the queue
        :param callable callback: callback(pika.frame.Method) for method Queue.DeclareOk
        :raises ValueError:

        rk   r   )
r   rb   rX   r   rI   r   r   rg   r   r'   )r0   rk   r   r   rm   r   rn   rC   ra   	conditionrD   s              r2   queue_declarezChannel.queue_declare  s    6 	!%111!!!3H== 	--/?@II
,I%+39++yyJq%'9*FI4GI Ig  	r4   c           	         |                                   t          j        |d           t          j        |          }|st          j        j        gng }|                     t          j                            d||||          ||          S )aF  Delete a queue from the broker.

        :param str queue: The queue to delete
        :param bool if_unused: only delete if it's unused
        :param bool if_empty: only delete if the queue is empty
        :param callable callback: callback(pika.frame.Method) for method Queue.DeleteOk
        :raises ValueError:

        rk   r   )	rX   r   rb   r   rI   r   r   rg   r   )r0   rk   r   if_emptyrC   ra   rD   s          r2   queue_deletezChannel.queue_deleteH  s     	!!!!%1113H==/5=4:&''2yyJa	8VDDh  	r4   c                    |                                   t          j        |d           t          j        |          }|st          j        j        gng }|                     t          j                            d||          ||          S )zPurge all of the messages from the specified queue

        :param str queue: The queue to purge
        :param callable callback: callback(pika.frame.Method) for method Queue.PurgeOk
        :raises ValueError:

        rk   r   )	rX   r   rb   r   rI   r   PurgeOkrg   Purge)r0   rk   rC   ra   rD   s        r2   queue_purgezChannel.queue_purge^  sz     	!!!!%1113H==.4<4:%&&"yy))!UF;;XwOOOr4   c           
      0   |                                   t          j        |d           t          j        |           ||}|                     t
          j                            d||||pt                                |t
          j        j	        g          S )a  Unbind a queue from an exchange.

        :param str queue: The queue to unbind from the exchange
        :param str exchange: The source exchange to bind from
        :param str routing_key: The routing key to unbind
        :param dict arguments: Custom key/value pair arguments for the binding
        :param callable callback: callback(pika.frame.Method) for method Queue.UnbindOk
        :raises ValueError:

        rk   Nr   )
rX   r   rb   r   rg   rI   r   r   r'   r   )r0   rk   r   r   rn   rC   s         r2   queue_unbindzChannel.queue_unbindl  s      	!!!!%111*8444KyyJa+y @%"ff& &'/$*2E1FH H 	Hr4   c                     |                                   t          j        |           |                     t          j                                        |t          j        j        g          S )zCommit a transaction

        :param callable callback: The callback for delivery confirmations
        :raises ValueError:

        )rX   r   r   rg   rI   TxCommitCommitOkrL   s     r2   	tx_commitzChannel.tx_commit  sQ     	!!!*8444yy))8dg6F5GHHHr4   c                     |                                   t          j        |           |                     t          j                                        |t          j        j        g          S )zRollback a transaction.

        :param callable callback: The callback for delivery confirmations
        :raises ValueError:

        )rX   r   r   rg   rI   r   Rollback
RollbackOkrL   s     r2   tx_rollbackzChannel.tx_rollback  sS     	!!!*8444yy))++X8J7KLLLr4   c                     |                                   t          j        |           |                     t          j                                        |t          j        j        g          S )aE  Select standard transaction mode. This method sets the channel to use
        standard transactions. The client must use this method at least once on
        a channel before using the Commit or Rollback methods.

        :param callable callback: The callback for delivery confirmations
        :raises ValueError:

        )rX   r   r   rg   rI   r   r   r   rL   s     r2   	tx_selectzChannel.tx_select  sQ     	!!!*8444yy))8dg6F5GHHHr4   c                    | j                             | j        t          j        j        | j        d           | j                             | j        t          j        j        | j        d           | j                             | j        t          j	        j
        | j        d           | j                             | j        t          j	        j        | j        d           dS )zsCallbacks that add the required behavior for a channel when
        connecting and connected to a server.

        FTN)r   rB   r   rI   rJ   GetEmpty_on_getemptyrK   
_on_cancelr	   rR   _on_flowr   _on_close_from_brokerr6   s    r2   r   zChannel._add_callbacks  s     	4.
0C,e	5 	5 	5 	4.
0A?E	3 	3 	3 	4.0A=%	1 	1 	1 	4.0B5t	= 	= 	= 	= 	=r4   c                 X    | j                             | j        | j        |d|            dS )ar  For internal use only (e.g., Connection needs to remove closed
        channels from its channel container). Pass a callback function that will
        be called when the channel is being cleaned up after all channel-close
        callbacks callbacks.

        :param callable callback: The callback to call, having the
            signature: callback(channel)

        T)rE   only_callerN)r   rB   r   _ON_CHANNEL_CLEANUP_CB_KEYrL   s     r2   _add_on_cleanup_callbackz Channel._add_on_cleanup_callback  sA     	4.:#$('+	 	 	- 	- 	- 	- 	-r4   c                     | j                             | j        | j        | |            t	                      | _        | j                             t          | j                             d| _        dS )z7Remove all consumers and any callbacks for the channel.N)	r   processr   r  r'   r(   cleanupstrr/   r6   s    r2   _cleanupzChannel._cleanup  se    t2#>d	L 	L 	L&&s4#677888r4   c                     | j                             |           | j                            |d           | j                            |           dS )zRemove any references to the consumer tag in internal structures
        for consumer state.

        :param str consumer_tag: The consumer tag to cleanup

        N)r)   discardr(   popr&   )r0   r`   s     r2   _cleanup_consumer_refzChannel._cleanup_consumer_ref  sO     	"**<888L$///-----r4   c                     | j         S )zUsed by the wrapper implementation (e.g., `BlockingChannel`) to
        retrieve the cookie that it set via `_set_cookie`

        :returns: opaque cookie value that was set via `_set_cookie`
        :rtype: object

        r/   r6   s    r2   _get_cookiezChannel._get_cookie  s     |r4   c                    	 | j                             |          }n+# t          j        $ r |                     |           Y dS w xY w|rt          |d         j        t          j        j	                  r | j
        |  dS t          |d         j        t          j        j                  r | j        |  dS t          |d         j        t          j        j                  r | j        |  dS dS dS )a  This is invoked by the connection when frames that are not registered
        with the CallbackManager have been found. This should only be the case
        when the frames are related to content delivery.

        The _content_assembler will be invoked which will return the fully
        formed message in three parts when all of the body frames have been
        received.

        :param pika.amqp_object.Frame frame_value: The frame to deliver

        Nr   )r   r	  r   UnexpectedFrameError_on_unexpected_framer   methodrI   rJ   Deliver_on_deliverGetOk	_on_getokReturnrU   )r0   frame_valueresponses      r2   _handle_content_framezChannel._handle_content_frame  s   	.66{CCHH. 	 	 	%%k222FF	  	+(1+,dj.@AA +  (++++HQK.
0@AA +))))HQK.
0ABB +****	+ 	+
+ +s    $AAc                 n    |j         j        | j        v rdS |                     |j         j                   dS )zWhen the broker cancels a consumer, delete it from our internal
        dictionary.

        :param pika.frame.Method method_frame: The method frame received

        N)r  r`   r&   r  r0   method_frames     r2   r  zChannel._on_cancel  s<     +t>>F""<#6#CDDDDDr4   c                 D    |                      |j        j                   dS )zCalled in response to a frame from the Broker when the
         client sends Basic.Cancel

        :param pika.frame.Method method_frame: The method frame received

        N)r  r  r`   r!  s     r2   rh   zChannel._on_cancelok  s$     	""<#6#CDDDDDr4   c                 
   | j         rJ | j        J |                     | j                   	 | j                            | j        d| | | j                   |                                  dS # |                                  w xY w)a1  Common logic for transitioning the channel to the CLOSED state:

        Set state to CLOSED, dispatch callbacks registered via
        `Channel.add_on_close_callback()`, and mop up.

        Assumes that the channel is not in CLOSED state and that
        `self._closing_reason` has been set up

        NrO   )r   r.   r   r   r   r	  r   r  r6   s    r2   _transition_to_closedzChannel._transition_to_closed  s     >!!!#///$$$	N""4#68K#'t/CE E E MMOOOOODMMOOOOs   (A, ,Bc                    t                               d|j        j        |j        j        |            | j        rJ |                     t          j        	                                           t          j        |j        j        |j        j                  | _        | j        r|                                  dS |                                  dS )zHandle `Channel.Close` from broker.

        :param pika.frame.Method method_frame: Method frame with Channel.Close
            method

        z,Received remote Channel.Close (%s): %r on %sN)rc   rd   r  r   r   r   rY   rI   r	   r   r   ChannelClosedByBrokerr.   r   &_drain_blocked_methods_on_remote_closer%  r!  s     r2   r  zChannel._on_close_from_broker1  s     	E#*5#*5t	= 	= 	= >!!! 	$,..00111
  *?*L,?,J L  L ? 	) 7799999&&(((((r4   c                     t                               d| |           | j        s|| _        |                                  dS dS )a  Handle meta-close request from either a remote Channel.Close from
        the broker (when a pending Channel.Close method is queued for
        execution) or a Connection's cleanup logic after sudden connection
        loss. We use this opportunity to transition to CLOSED state, clean up
        the channel, and dispatch the on-channel-closed callbacks.

        :param Exception reason: Exception describing the reason for closing.

        zHandling meta-close on %s: %rN)rc   re   r   r.   r%  )r0   reasons     r2   _on_close_metazChannel._on_close_metaV  sO     	4dFCCC~ 	)#)D &&(((((	) 	)r4   c                 p    t                               d|j        |            |                                  dS )zInvoked when RabbitMQ replies to a Channel.Close method

        :param pika.frame.Method method_frame: Method frame with Channel.CloseOk
            method

        zReceived %s on %sN)rc   r   r  r%  r!  s     r2   r   zChannel._on_closeokf  s6     	')<dCCC""$$$$$r4   c                 $   |j         j        }|| j        v r1| j        r(|| j        vr|                     |j         j                   dS || j        vrt          	                    d|           dS  | j        |         | |j         |j
        |           dS )an  Cope with reentrancy. If a particular consumer is still active when
        another delivery appears for it, queue the deliveries up until it
        finally exits.

        :param pika.frame.Method method_frame: The method frame received
        :param pika.frame.Header header_frame: The header frame received
        :param bytes body: The body received

        NzUnexpected delivery: %r)r  r`   r&   r   r)   r   r[   r(   rc   errorr   )r0   r"  header_framer   r`   s        r2   r  zChannel._on_deliverq  s     $*74?**| DD4N N N!!,"5"BCCCFt..LL2LAAAF%%dL,?&2&=t	E 	E 	E 	E 	Er4   c                 <    t                               d|           dS )a  Generic events that returned ok that may have internal callbacks.
        We keep a list of what we've yet to implement so that we don't silently
        drain events that we don't support.

        :param pika.frame.Method method_frame: The method frame received

        zDiscarding frame %rNrc   re   r!  s     r2   rr   zChannel._on_eventok  s     	*L99999r4   c                 P    | j         du rt                              d           dS dS )zCalled if the server sends a Channel.Flow frame.

        :param pika.frame.Method method_frame_unused: The Channel.Flow frame

        Fz!Channel.Flow received from serverN)r$   rc   rd   r0   _method_frame_unuseds     r2   r  zChannel._on_flow  s3     %..NN>????? /.r4   c                     |j         j        | _        | j        r(|                     |j         j                   d| _        dS t                              d           dS )zCalled in response to us asking the server to toggle on Channel.Flow

        :param pika.frame.Method method_frame: The method frame received

        Nz0Channel.FlowOk received with no active callbacks)r  r   r   r*   rc   rd   r!  s     r2   r   zChannel._on_flowok  s_     (.5# 	O$$\%8%?@@@'+D$$$NNMNNNNNr4   c                 \    t                               d|           | j        	d| _        dS dS )zWhen we receive an empty reply do nothing but log it

        :param pika.frame.Method method_frame: The method frame received

        zReceived Basic.GetEmpty: %rN)rc   re   r+   r!  s     r2   r   zChannel._on_getempty  s8     	2LAAA".&*D### /.r4   c                     | j         (| j         }d| _          || |j        |j        |           dS t                              d           dS )a  Called in reply to a Basic.Get when there is a message.

        :param pika.frame.Method method_frame: The method frame received
        :param pika.frame.Header header_frame: The header frame received
        :param bytes body: The body received

        Nz,Basic.GetOk received with no active callback)r+   r  r   rc   r.  )r0   r"  r/  r   rC   s        r2   r  zChannel._on_getok  sX     "..H&*D#HT<.0GNNNNNLLGHHHHHr4   c                     | j         rt                              d|           dS |                     | j                   | j        |                     |            dS dS )a  Called by our callback handler when we receive a Channel.OpenOk and
        subsequently calls our _on_openok_callback which was passed into the
        Channel constructor. The reason we do this is because we want to make
        sure that the on_open_callback parameter passed into the Channel
        constructor is not the first callback we make.

        Suppress the state transition and callback if channel is already in
        CLOSING state.

        :param pika.frame.Method method_frame: Channel.OpenOk frame

        z&Suppressing while in closing state: %sN)r   rc   re   r   r   r,   r!  s     r2   r   zChannel._on_openok  sh     ? 	/LLA<PPPPPOODI&&&'3((..... 43r4   c           	          | j                             | j        d| | |j        |j        |          s(t
                              d|j        |j                   dS dS )zCalled if the server sends a Basic.Return frame.

        :param pika.frame.Method method_frame: The Basic.Return frame
        :param pika.frame.Header header_frame: The content header frame
        :param bytes body: The message body

        rU   z*Basic.Return received from server (%r, %r)N)r   r	  r   r  r   rc   re   )r0   r"  r/  r   s       r2   rU   zChannel._on_return  s{     ~%%d&9<&*L,?&2&=tE E 	H LLE&-|/FH H H H H	H 	Hr4   c                 <    t                               d|           dS )zCalled when the broker sends a Confirm.SelectOk frame

        :param pika.frame.Method method_frame: The method frame received

        zConfirm.SelectOk Received: %rNr1  r!  s     r2   _on_selectokzChannel._on_selectok  s     	4lCCCCCr4   c                     t                               dt          | j                             d| _        | j        r8| j        5 | j        | j                                          | j        r| j        /dS dS dS dS )a  This is called when a synchronous command is completed. It will undo
        the blocking state and send all the frames that stacked up while we
        were in the blocking state.

        :param pika.frame.Method method_frame_unused: The method frame received

        z%i blocked framesN)rc   re   lenr"   r#   rg   popleftr3  s     r2   _on_synchronous_completez Channel._on_synchronous_complete  s     	(#dm*<*<=== m 	0 6DIt},,..// m 	0 6 6 6 	0 	0 	0 	0 6 6r4   c                 h   t                               dt          | j                             | j        r}| j                                        d         }t          |t          j        j                  r| 	                    | j
                   nt                               d|           | j        {dS dS )a  This is called when the broker sends a Channel.Close while the
        client is in CLOSING state. This method checks the blocked method
        queue for a pending client-initiated Channel.Close method and
        ensures its callbacks are processed, but does not send the method
        to the broker.

        The broker may close the channel before responding to outstanding
        in-transit synchronous methods, or even before these methods have been
        sent to the broker. AMQP 0.9.1 obliges the server to drop all methods
        arriving on a closed channel other than Channel.CloseOk and
        Channel.Close. Since the response to a synchronous method that blocked
        the channel never arrives, the channel never becomes unblocked, and the
        Channel.Close, if any, in the blocked queue has no opportunity to be
        sent, and thus its completion callback would never be called.

        z@Draining %i blocked frames due to broker-requested Channel.Closer   z#Ignoring drained blocked method: %sN)rc   re   r=  r"   r>  r   rI   r	   r   r+  r.   )r0   r  s     r2   r(  z.Channel._drain_blocked_methods_on_remote_close  s    " 	N	  	  	  m 	L]**,,Q/F&$,"455 L##D$89999BFKKK m 	L 	L 	L 	L 	Lr4   c                 x   |j         sJ d|            t          |t          d          t          f          st	          d          |/t          |          st	          d          |st          d          | j        r|                                  | j	        r;t                              d||           | j                            |||g           dS |                     |           |r|j        | _	        t                              d||           |D ]}t          |t                     r|\  }}nd}t                              d           | j                            | j        || j        |	           |=t                              d
           | j                            | j        |||	           dS dS )a  Make a synchronous channel RPC call for a synchronous method frame. If
        the channel is already in the blocking state, then enqueue the request,
        but don't send it at this time; it will be eventually sent by
        `_on_synchronous_complete` after the prior blocking request receives a
        response. If the channel is not in the blocking state and
        `acceptable_replies` is not empty, transition the channel to the
        blocking state and register for `_on_synchronous_complete` before
        sending the request.

        NOTE: A callback must be accompanied by non-empty acceptable_replies.

        :param pika.amqp_object.Method method: The AMQP method to invoke
        :param callable callback: The callback for the RPC response
        :param list|None acceptable_replies: A (possibly empty) sequence of
            replies this RPC call expects or None

        z8Only synchronous-capable methods may be used with _rpc: Nz)acceptable_replies should be list or Nonez%callback should be None or a callablez8Unexpected callback for asynchronous (nowait) operation.zIAlready in blocking state, so enqueueing method %s; acceptable_replies=%rz:Entering blocking state on frame %s; acceptable_replies=%rz'Adding on_synchronous_complete callback)rn   z&Adding passed-in RPC response callback)synchronousr   typer!   r   r   r   r   rX   r#   rc   re   r"   appendrY   NAMEtupler   rB   r   r?  )r0   r  rC   acceptable_repliesrF   rn   s         r2   rg   zChannel._rpc  s:   $ ! 	 	 	V	 	 	
 ,tDzz4.@AA 	IGHHHH%% I GHHH & P NP P P > 	&##%%% > 	LL()/1CE E E M  &(4F!GHHHF 	&!!!  	<#[DNLLL*, , , , < <eU++ %',$E99 $IFGGG""4#6#(#'#@-6 # 8 8 8 'LL!IJJJN&&t':','/1: ' < < <'	< 	<< <r4   c                    | j         | j        k    rdS | j         | j        k    rt          j        d          | j         | j        k    rt          j        d          | j         | j        k    sJ t          j        d          )zIf channel is not in the OPEN state, raises ChannelWrongStateError
        with `reply_code` and `reply_text` corresponding to current state.

        :raises exceptions.ChannelWrongStateError: if channel is not in OPEN
            state.
        Nz*Channel is opening, but is not usable yet.zChannel is closing.zChannel is closed.)r-   r   r   r   ChannelWrongStateErrorr   r   r6   s    r2   rX   zChannel._raise_if_not_openi  s     ;$)##F;$,&&34`aaa;$,&&34IJJJ {dk))))/0DEEEr4   c                 H    | j                             | j        ||           dS )a%  Shortcut wrapper to send a method through our connection, passing in
        the channel number

        :param pika.amqp_object.Method method: The method to send
        :param tuple content: If set, is a content frame, is tuple of
                              properties and body.

        N)r   rY   r   )r0   r  contents      r2   rY   zChannel._send_method}  s'     	$$T%8&'JJJJJr4   c                     || _         dS )a  Used by wrapper layer (e.g., `BlockingConnection`) to link the
        channel implementation back to the proxy. See `_get_cookie`.

        :param cookie: an opaque value; typically a proxy channel implementation
            instance (e.g., `BlockingChannel` instance)
        Nr  )r0   cookies     r2   _set_cookiezChannel._set_cookie  s     r4   c                     || _         dS )zSet the channel connection state to the specified state value.

        :param int connection_state: The connection_state value

        N)r-   )r0   connection_states     r2   r   zChannel._set_state  s     'r4   c                 <    t                               d|           dS )zInvoked when a frame is received that is not setup to be processed.

        :param pika.frame.Frame frame_value: The frame received

        zUnexpected frame: %rN)rc   r.  r0   r  s     r2   r  zChannel._on_unexpected_frame  s     	+[99999r4   )T)r   F)r^   N)FFNNN)F)r   FT)NF)r   r   FN)r   T)FN)r   r   )N)r^   NN)NFN)NNr^   NN)NNN)FFFFNN)FFN)NNNN)NN)Qr=   
__module____qualname____doc__r   r   r   r   r>   r  r3   r7   r?   rG   rM   rP   rS   rV   r]   ri   rx   rp   r   r   r   r   r   r   r   r   propertyr   r   r   directr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rh   r%  r  r+  r   r  rr   r  r   r   r  r   rU   r;  r?  r(  rg   rX   rY   rN  r   r   r4   r2   r	   r	      s         FGDG 	f	L "7, , ,\# # #= = =
O O O O
" 
" 
"( ( (0
" 
" 
"O O OI I I I*8- 8- 8- 8-z  % %#' $#F F F FP	E 	E 	E!H !H !H !HF> > > >6 "& %I I I I8 !"!""	*  *  *  * XK K K K$1 1 1 1*&< &< &< &<P&A &A &A &AP ) ) X) #% $#: : : :6 (4':!&!&%*"'#'"&(= (= (= (=TI I I I  %)#$&"&!%< < < <.) ) ) )& * * X* + + X+ ( ( X( + + X+O O O  $! 7 7 7 7: $# %"' $#( ( ( (X  %#"	   ,P P P P  #!%#"H H H H2	I 	I 	I 	I	M 	M 	M 	MI I I I= = =*- - -   	. 	. 	.  + + +4E E EE E E  *#) #) #)J) ) ) 	% 	% 	%E E E0: : :@ @ @O O O+ + +I I I/ / /,H H HD D D0 0 0 L L L8M< M< M< M<^F F F(
K 
K 
K 
K  ' ' ': : : : :r4   r	   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )r   ztHandle content related frames, building a message and return the message
    back in three parts upon receipt.

    c                 V    d| _         d| _        d| _        t                      | _        dS )z>Create a new instance of the conent frame assembler.

        Nr   _method_frame_header_frame_seen_so_farr!   _body_fragmentsr6   s    r2   r3   zContentFrameAssembler.__init__  s.     "!#vvr4   c                    t          |t          j                  r't          j        |j        j                  r	|| _        dS t          |t          j                  r(|| _	        |j
        dk    r|                                 S dS t          |t          j                  r|                     |          S t          j        |          )a!  Invoked by the Channel object when passed frames that are not
        setup in the rpc process and that don't have explicit reply types
        defined. This includes Basic.Publish, Basic.GetOk and Basic.Return

        :param Method|Header|Body frame_value: The frame to process

        Nr   )r   frameMethodrI   has_contentr  INDEXr\  Headerr]  	body_size_finishBody_handle_body_framer   r  rR  s     r2   r	  zContentFrameAssembler.process  s     {EL11 	? !3!9::	?!,D4U\22 		?!,D$))||~~%tUZ00 	?**;7771+>>>r4   c                 |    | j         | j        d                    | j                  f}|                                  |S )z}Invoked when all of the message has been received

        :rtype: tuple(pika.frame.Method, pika.frame.Header, str)

        r4   )r\  r]  joinr_  _reset)r0   rK  s     r2   rg  zContentFrameAssembler._finish  s:     %t'988D0113r4   c                 L   | xj         t          |j                  z  c_         | j                            |j                   | j         | j        j        k    r|                                 S | j         | j        j        k    r$t          j	        | j         | j        j                  dS )a  Receive body frames and append them to the stack. When the body size
        matches, call the finish method.

        :param Body body_frame: The body frame
        :raises: pika.exceptions.BodyTooLongError
        :rtype: tuple(pika.frame.Method, pika.frame.Header, str)|None

        N)
r^  r=  fragmentr_  rD  r]  rf  rg  r   BodyTooLongError)r0   
body_frames     r2   ri  z(ContentFrameAssembler._handle_body_frame  s     	S!4555##J$7888 2 <<<<<>>!!3!===-d.?.2.@.JL L Ltr4   c                 V    d| _         d| _        d| _        t                      | _        dS )z&Reset the values for processing framesNr   r[  r6   s    r2   rl  zContentFrameAssembler._reset  s,    !!#vvr4   N)	r=   rS  rT  rU  r3   r	  rg  ri  rl  rX  r4   r2   r   r     si         
& & &? ? ?.	 	 	  $& & & & &r4   r   )rU  r   loggingrz   enumr   
pika.framera  pika.exceptionsr   	pika.specrI   pika.validatorsr   pika.compatr   r   r   pika.exchange_typer   	getLoggerr=   rc   MAX_CHANNELSobjectr	   r   rX  r4   r2   <module>r}     sA                      $ $ $ $ $ $       $ $ $ $ $ $ : : : : : : : : : : + + + + + +		8	$	$G: G: G: G: G:f G: G: G:T,H& H& H& H& H&F H& H& H& H& H&r4   