HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/amqp/__pycache__/connection.cpython-310.pyc
o

%we�k�@s>dZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZdd	lmZdd
lmZmZmZmZmZmZmZmZmZddlmZmZddlm Z zdd
l!m"Z"Wne#ywGdd�de$�Z"YnwdZ%d�&�Z'dZ(e�)d�Z*e�)d�Z+ded�Z,dddd�Z-Gdd�de�Z.dS)zAMQP Connections.�N)�array)�	monotonic)�ensure_promise�)�__version__�sasl�spec)�AbstractChannel)�Channel)	�AMQPDeprecationWarning�ChannelError�ConnectionError�ConnectionForced�
MessageNacked�RecoverableChannelError�RecoverableConnectionError�
ResourceError�error_for_code)�
frame_handler�frame_writer��	Transport)�SSLErrorc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�H/home/arjun/projects/env/lib/python3.10/site-packages/amqp/connection.pyrsrz�The .{attr} attribute on the connection was accessed before
the connection was established.  This is supported for now, but will
be deprecated in amqp 2.2.0.

Since amqp 2.0 you have to explicitly call Connection.connect()
before using the connection.
zP
Start from server, version: %d.%d, properties: %s, mechanisms: %s, locales: %s
)�
Connection�amqpz)amqp.connection.Connection.heartbeat_tickzpy-amqp)�product�product_versionT)�consumer_cancel_notifyzconnection.blocked�authentication_failure_closecs�eZdZdZeZeZeZdZ	dZ
dZdZdZ
dZdZdZdZe�ejjd�e�ejj�e�ejjd�e�ejjd�e�ejjd�e�ejj�e�ejj�e�ejj�hZdd	�eD�ZejjejjfZee j!e"e#fZ$e%fZ&e'e(e j!e"e#fZ)e*fZ+d
dddddd
ddddddddddddddde,e-f�fdd�	Z.dd�Z/dd�Z0dd�Z1d`dd�Z2dd�Z3d`dd�Z4dd�Z5e6d d!��Z7e7j8d"d!��Z7e6d#d$��Z9e9j8d%d$��Z9e6d&d'��Z-e-j8d(d'��Z-	)dad*d+�Z:d,d-�Z;dbd.d/�Z<dcd1d2�Z=d3d4�Z>		ddd5d6�Z?e6d7d8��Z@d9d:�ZAd;d<�ZBd=d>�ZCded?d@�ZDdAdB�ZEd`dCdD�ZFd`dEdF�ZGdGdH�ZH	J	dfdKdL�ZIdMdN�ZJdOdP�ZKdQdR�ZLdSdT�ZMdUdV�ZNdWdX�ZOdgdZd[�ZPe6d\d]��ZQe6d^d_��ZR�ZSS)hra�AMQP Connection.

    The connection class provides methods for a client to establish a
    network connection to a server, and for both peers to operate the
    connection thereafter.

    GRAMMAR::

        connection          = open-connection *use-connection close-connection
        open-connection     = C:protocol-header
                              S:START C:START-OK
                              *challenge
                              S:TUNE C:TUNE-OK
                              C:OPEN S:OPEN-OK
        challenge           = S:SECURE C:SECURE-OK
        use-connection      = *channel
        close-connection    = C:CLOSE S:CLOSE-OK
                            / S:CLOSE C:CLOSE-OK
    Create a connection to the specified host, which should be
    a 'host[:port]', such as 'localhost', or '1.2.3.4:5672'
    (defaults to 'localhost', if a port is not specified then
    5672 is used)

    Authentication can be controlled by passing one or more
    `amqp.sasl.SASL` instances as the `authentication` parameter, or
    setting the `login_method` string to one of the supported methods:
    'GSSAPI', 'EXTERNAL', 'AMQPLAIN', or 'PLAIN'.
    Otherwise authentication will be performed using any supported method
    preferred by the server. Userid and passwords apply to AMQPLAIN and
    PLAIN authentication, whereas on GSSAPI only userid will be used as the
    client name. For EXTERNAL authentication both userid and password are
    ignored.

    The 'ssl' parameter may be simply True/False, or
    a dictionary of options to pass to :class:`ssl.SSLContext` such as
    requiring certain certificates. For details, refer ``ssl`` parameter of
    :class:`~amqp.transport.SSLTransport`.

    The "socket_settings" parameter is a dictionary defining tcp
    settings which will be applied as socket options.

    When "confirm_publish" is set to True, the channel is put to
    confirm mode. In this mode, each published message is
    confirmed using Publisher confirms RabbitMQ extension.
    Nr�ooFSS�s�BlB�BsBBcCsi|]}|j|�qSr)�
method_sig��.0�mrrr�
<dictcomp>�szConnection.<dictcomp>zlocalhost:5672�guestr�/�en_USFcs�t��j|_|p	d}|
p
d}
|rt|tj�r|f}||_np|durw|dkr+t�|�}nG|dkr4t�	�}n>|dkrK|dus@|durDt
d��t�||�}n'|dkrb|dusW|dur[t
d��t�||�}n|durmt�
||�}nt
d|��|f|_ntj|d	d
�t�	�t�||�t�||�f|_t|jfi|	p�i��|_||_||_||_t|�|_||_||_d|_i|_t��|d�d|_d|_d|_||_|
|_ ||_!||_"|
|_#||_$||_%||_&||_'||_(t|�|_)t*d
�|_+d|_,d|_-i|_.g|_/g|_0||_1dS)Ni��i�GSSAPI�EXTERNAL�AMQPLAINz-Must supply authentication or userid/password�PLAINzInvalid login methodT)�	fail_softFr�H)2�uuid�uuid4�hex�_connection_id�
isinstancer�SASL�authenticationr0r1�
ValueErrorr2r3�RAW�dict�library_properties�client_properties�locale�host�virtual_hostr�
on_tune_ok�frame_handler_cls�frame_writer_cls�_handshake_complete�channels�super�__init__�
_frame_writer�_on_inbound_frame�
_transport�channel_max�	frame_max�client_heartbeat�confirm_publish�ssl�read_timeout�
write_timeout�socket_settings�
on_blocked�on_unblocked�on_openr�_used_channel_ids�
version_major�
version_minor�server_properties�
mechanisms�locales�connect_timeout)�selfrC�userid�password�login_method�login_responser<rDrBrArSr`rOrP�	heartbeatrYrWrXrRrErTrUrVrr�kwargs�auth��	__class__rrrK�s�

��



���



zConnection.__init__c	CsR|jrd|j�d|j�d|j�dt|�d�d�	Sd|j�d|j�dt|�d�d�S)Nz<AMQP Connection: r.z using z at z#x�>z (disconnected) at )rNrCrD�id�rarrr�__repr__s���zConnection.__repr__cCs|��|S�N)�connectrmrrr�	__enter__"szConnection.__enter__cGs|��dSro)�close)ra�eargsrrr�__exit__&szConnection.__exit__cCs|j�||�Sro)rY�then)ra�
on_success�on_errorrrrru)szConnection.thencCs`|j�tjj|jtjj|jtjj|j	tjj
|jtjj|j
tjj|jtjj|jtjj|ji�dSro)�
_callbacks�updaterr�Start�	_on_start�OpenOk�_on_open_ok�Secure�
_on_secure�Tune�_on_tune�Close�	_on_close�Blocked�_on_blocked�	Unblocked�
_on_unblocked�CloseOk�_on_close_okrmrrr�_setup_listeners,s








�zConnection._setup_listenersc	Cs�|jr
|r|�SdSz:|j|j|j|j|j|j|jd�|_|j�	�|�
||j�|_|�
||j�|_|jsB|j|jd�|jr5WdSWdSttfyR|���w)N)rV)�timeout)�	connectedrrCr`rSrTrUrV�	transportrprF�on_inbound_method�on_inbound_framerGrrH�drain_events�OSErrorr�collect)ra�callbackrrrrp8s(�
���zConnection.connectcCst�ttj|d���dS)N)�attr)�warnings�warnr�W_FORCE_CONNECT�format)rar�rrr�_warn_force_connectPs

�zConnection._warn_force_connectcC�"|jdur|�d�|��|jS)Nr�)rNr�rprmrrrr�T�

zConnection.transportcC�
||_dSro)rN)rar�rrrr�[�
cCr�)Nr�)rMr�rprmrrrr�_r�zConnection.on_inbound_framecCr�ro)rM)rar�rrrr�fr�cCr�)Nr)rLr�rprmrrrrjr�zConnection.frame_writercCr�ro)rL)rarrrrrqr��FsSscs,|j}||_||_||_t|t�r|�d�}|�d�|_|�d�|_	t
�t|j|j|j|j|j	�|�
d�p7i�|�di�}|��fdd�|j��D��|sU|�dd�|jD]}	|	j|jvrk|	�|�}
|
turknqXtd�d�d	d
�|jD����d�|j������|�tjj|||	j|
|jf�dS)Nzutf-8� � �capabilitiescs i|]\}}��|�r||�qSr)�get)r*�
wanted_cap�
enable_cap��scaprrr,�s��z(Connection._on_start.<locals>.<dictcomp>zGCouldn't find appropriate auth mechanism (can offer: {}; available: {})s, css�|]	}|jr|jVqdSro)�	mechanismr)rrr�	<genexpr>�s
��z'Connection._on_start.<locals>.<genexpr>) rAr[r\r]r:�str�encode�splitr^r_�AMQP_LOGGER�debug�START_DEBUG_FMTr��
setdefaultry�negotiate_capabilities�items�popr<r��start�NotImplementedr
r��join�decode�send_methodrr�StartOkrB)rar[r\r]r^r_�argsigrA�capr<rerr�rr{usT

��

�
�����zConnection._on_startcCsdSror)ra�	challengerrrr�szConnection._on_securecCs�|jpd}|p	|j|_|p|j|_|pd|_|jdks|dkr't|j|�|_nt|j|�|_|js4d|_|jtj	j
||j|j|jf|jd�dS)Nr�r�)rQrOrP�server_heartbeat�maxrf�minr�rr�TuneOk�
_on_tune_sent)rarOrPr�r�rQrrrr��s


�zConnection._on_tune�ssbcCs|�tjj||jddf�dS)N�F)r�rr�OpenrD)rar�rrrr��s�zConnection._on_tune_sentcCsd|_|�|�dS)NT)rHrYrmrrrr}�szConnection._on_open_okcKst|f|||||d�|��S)N)r`rSrTrUrVr)rarCr`rSrTrUrVrgrrrr�s���zConnection.TransportcCs|jo|jjSro)rNr�rmrrrr��szConnection.connectedcsV�jr�j���jr �fdd��j��D�}|D]}|��qd�_�_�_dS)Ncsg|]}|�ur|�qSrr)r*�chrmrr�
<listcomp>�s
�z&Connection.collect.<locals>.<listcomp>)rNrrrI�valuesr��
connection)rarIr�rrmrr��s

�
zConnection.collectcCsZt|j�}td|jd�D]}||vr|j�|�|Sq
td�t|j�|j�t	j
j��)Nrz/No free channel ids, current={}, channel_max={})�setrZ�rangerO�appendrr��lenrIrr
r�)ra�used_channel_ids�
channel_idrrr�_get_free_channel_id�s
���zConnection._get_free_channel_idcCs*||jvr
td|�d���|j�|�|S)NzChannel z
 already open)rZr
r�)rar�rrr�_claim_channel_id�s
zConnection._claim_channel_idcCsN|jdur	td��z|j|WSty&|j|||d�}|��|YSw)z�Create new channel.

        Fetch a Channel object identified by the numeric channel_id, or
        create that object if it doesn't already exist.
        NzConnection already closed.)rY)rIr�KeyErrorr
�open)rar�r��channelrrrr��s
�zConnection.channelcCstd��)NzUse AMQP heartbeats)�NotImplementedErrorrmrrr�is_alive	szConnection.is_alivecCs|�|�s
	|�|�rdSdSro)�
blocking_read)rar�rrrr�s
�zConnection.drain_eventscCs@|j�|��
|j��}Wd�n1swY|�|�Sro)r��having_timeout�
read_framer�)rar��framerrrr�s�
zConnection.blocking_readcCs&|jdur	td��|j|�|||�S)NzConnection already closed)rIr�dispatch_method)rar�r(�payload�contentrrrr�s


�zConnection.on_inbound_methodr��rrc	Csp|jdurdSz,zd|_|jtjj||||d|dftjjd�WWd|_Sttfy3|�	��wd|_w)�Request a connection close.

        This method indicates that the sender wants to close the
        connection. This may be due to internal conditions (e.g. a
        forced shut-down) or due to an error handling a specific
        method, i.e. an exception.  When a close is due to an
        exception, the sender provides the class and method id of the
        method which caused the exception.

        RULE:

            After sending this method any received method except the
            Close-OK method MUST be discarded.

        RULE:

            The peer sending this method MAY use a counter or timeout
            to detect failure of the other peer to respond correctly
            with the Close-OK method.

        RULE:

            When a server receives the Close method from a client it
            MUST delete all server-side resources associated with the
            client's context.  A client CANNOT reconnect to a context
            after sending or receiving a Close method.

        PARAMETERS:
            reply_code: short

                The reply code. The AMQ reply codes are defined in AMQ
                RFC 011.

            reply_text: shortstr

                The localised reply text.  This text can be logged as an
                aid to resolving issues.

            class_id: short

                failing method class

                When the close is provoked by a method exception, this
                is the class of the method.

            method_id: short

                failing method ID

                When the close is provoked by a method exception, this
                is the ID of the method.
        NTrr)�waitF)
rN�
is_closingr�rrr�r�r�rr�)ra�
reply_code�
reply_textr(r�rrrrrs
6�
��zConnection.closecCs|��t||||ft��)r�)�_x_close_okrr
)rar�r��class_id�	method_idrrrr�fs5�zConnection._on_closecCs|jtjj|jd�dS)ahConfirm a connection close.

        This method confirms a Connection.Close method and tells the
        recipient that it is safe to release resources for the
        connection and close the socket.

        RULE:
            A peer that detects a socket closure without having
            received a Close-Ok handshake method SHOULD log the error.
        r�N)r�rrr�r�rmrrrr��szConnection._x_close_okcCs|��dS)aiConfirm a connection close.

        This method confirms a Connection.Close method and tells the
        recipient that it is safe to release resources for the
        connection and close the socket.

        RULE:

            A peer that detects a socket closure without having
            received a Close-Ok handshake method SHOULD log the error.
        N)r�rmrrrr��szConnection._on_close_okcCsd}|jr
|�|�SdS)zlCallback called when connection blocked.

        Notes:
            This is an RabbitMQ Extension.
        z#connection blocked, see broker logsN)rW)ra�reasonrrrr��s
�zConnection._on_blockedcCs|jr|��SdSro)rXrmrrrr��s�zConnection._on_unblockedcCs|�ddddd�dS)N�r)rrmrrr�send_heartbeat�szConnection.send_heartbeat�cCs
t�d|j�|jsdS|dkrd}|j}|j}|jdus"|j|kr&t�|_|j	dus0|j	|kr4t�|_
t�}t�d|j|j	||||j|j|j�	|||_|_	||j|j|krit�d|j�|��t�|_d|j}|j
|}|t�k}|j
r�|r�td��dSdS)a�Send heartbeat packets if necessary.

        Raises:
            ~amqp.exceptions.ConnectionForvced: if none have been
                received recently.

        Note:
            This should be called frequently, on the order of
            once per second.

        Keyword Arguments:
            rate (int): Number of heartbeat frames to send during the heartbeat
                        timeout
        z"heartbeat_tick : for connection %sNrr�z�heartbeat_tick : Prev sent/recv: %s/%s, now - %s/%s, monotonic - %s, last_heartbeat_sent - %s, heartbeat int. - %s for connection %sz3heartbeat_tick: sending heartbeat for connection %szToo many heartbeats missed)
�AMQP_HEARTBEAT_LOGGERr�r9rf�
bytes_sent�
bytes_recv�	prev_sentr�last_heartbeat_sent�	prev_recv�last_heartbeat_receivedr�r)ra�rate�sent_now�recv_now�now�two_heartbeats�two_heartbeats_interval�heartbeats_missedrrr�heartbeat_tick�sH���



�zConnection.heartbeat_tickcCs|jjSro)r��sockrmrrrr�
szConnection.sockcCs|j�d�piS)Nr�)r]r�rmrrr�server_capabilitiesszConnection.server_capabilitiesro)r�)r&)r�)FNNN)NN)rr�r�r')r�)Trrr�__doc__r
�NEGOTIATE_CAPABILITIESr��LIBRARY_PROPERTIESr@rfrQr�r�r�r�r�r�r�r�methodrrzr|r~r�r�r�r�r��_METHODS�_ALLOWED_METHODS_WHEN_CLOSINGr
�socket�error�IOErrorr��connection_errorsr�channel_errorsrr�recoverable_connection_errorsr�recoverable_channel_errorsrrrKrnrqrtrur�rpr��propertyr��setterr�r{rr�r�r}rr�r�r�r�r�r�r�r�r�rrr�r�r�r�r�r�r�r�r��
__classcell__rrrirr?s�.�
�����[








�1


�




�H9


?
r)/r��loggingrr6r�r�timer�vinerr�rrr�abstract_channelr	r�r
�
exceptionsrrr
rrrrrr�method_framingrrr�rrSr�ImportError�	Exceptionr��stripr��__all__�	getLoggerr�r�r�r�rrrrr�<module>sH,�	�
���