
     h$                     
   d 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Z	d	Z
 G d
 dej                  Z G d dej        ej                  Z G d dej                  Z G d dej                  Z G d de          ZdS )a  pyamqp transport module for Kombu.

Pure-Python amqp transport using py-amqp library.

Features
========
* Type: Native
* Supports Direct: Yes
* Supports Topic: Yes
* Supports Fanout: Yes
* Supports Priority: Yes
* Supports TTL: Yes

Connection String
=================
Connection string can have the following formats:

.. code-block::

    amqp://[USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]
    [USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]
    amqp://

For TLS encryption use:

.. code-block::

    amqps://[USER:PASSWORD@]BROKER_ADDRESS[:PORT][/VIRTUALHOST]

Transport Options
=================
Transport Options are passed to constructor of underlying py-amqp
:class:`~kombu.connection.Connection` class.

Using TLS
=========
Transport over TLS can be enabled by ``ssl`` parameter of
:class:`~kombu.Connection` class. By setting ``ssl=True``, TLS transport is
used::

    conn = Connect('amqp://', ssl=True)

This is equivalent to ``amqps://`` transport URI::

    conn = Connect('amqps://')

For adding additional parameters to underlying TLS, ``ssl`` parameter should
be set with dict instead of True::

    conn = Connect('amqp://broker.example.com', ssl={
            'keyfile': '/path/to/keyfile'
            'certfile': '/path/to/certfile',
            'ca_certs': '/path/to/ca_certfile'
        }
    )

All parameters are passed to ``ssl`` parameter of
:class:`amqp.connection.Connection` class.

SSL option ``server_hostname`` can be set to ``None`` which is causing using
hostname from broker URL. This is usefull when failover is used to fill
``server_hostname`` with currently used broker::

    conn = Connect('amqp://broker1.example.com;broker2.example.com', ssl={
            'server_hostname': None
        }
    )
    N)get_manager)version_string_as_tuple   )baseto_rabbitmq_queue_argumentsi(  i'  c                   $     e Zd ZdZd fd	Z xZS )MessagezAMQP Message.Nc                     |j         } t                      j        d|j        ||j        |                    d          |                    d          |j        |j         |                    d          pi d| d S )Ncontent_typecontent_encodingapplication_headers)bodychanneldelivery_tagr   r   delivery_info
propertiesheaders )r   super__init__r   r   getr   )selfmsgr   kwargsprops	__class__s        R/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/kombu/transport/pyamqp.pyr   zMessage.__init__V   s     		)>22"YY'9::+~II344:		 		 		 		 		 		 		    N__name__
__module____qualname____doc__r   __classcell__r   s   @r   r
   r
   S   sC                 r   r
   c                   @    e Zd ZdZeZdddddej        fdZd Zd ZdS )ChannelzAMQP Channel.Nc                 "     ||f||||d|pi S )z<Prepare message so that it can be sent using this transport.)priorityr   r   r   r   )r   r   r+   r   r   r   r   _Messages           r   prepare_messagezChannel.prepare_messagei   s@     x
%- '
 
 B
 
 	
r   c                     t          |fi |S r    r   )r   	argumentsr   s      r   prepare_queue_argumentszChannel.prepare_queue_argumentsv   s    *9?????r   c                 0    |                      ||           S )z4Convert encoded message body back to a Python value.r   )r
   )r   raw_messages     r   message_to_pythonzChannel.message_to_pythony   s    ||K|666r   )	r"   r#   r$   r%   r
   amqpr-   r0   r4   r   r   r   r)   r)   d   se        G-1%)D $
 
 
 
@ @ @7 7 7 7 7r   r)   c                       e Zd ZdZeZdS )
ConnectionzAMQP Connection.N)r"   r#   r$   r%   r)   r   r   r   r7   r7   ~   s        GGGr   r7   c                   2   e Zd ZdZeZeZeZe	j        j
        Z
e	j        j        Ze	j        j        Ze	j        j        ZdZdZej        j                            dd          Z	 ddZd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZddZd Ze d             Z!d Z"dS )	TransportzAMQP Transport.zpy-amqpr5   T)asynchronous
heartbeatsNc                 L    || _         |p| j        | _        |p| j        | _        d S r    )clientdefault_portdefault_ssl_port)r   r=   r>   r?   r   s        r   r   zTransport.__init__   s/    (=D,= 0 ID4Ir   c                     t           j        S r    )r5   __version__r   s    r   driver_versionzTransport.driver_version   s    r   c                 *    |                                 S r    r2   r   
connections     r   create_channelzTransport.create_channel   s    !!###r   c                      |j         di |S )Nr   )drain_events)r   rF   r   s      r   rI   zTransport.drain_events   s    &z&00000r   c                 6    ||                                  d S d S r    )collectrE   s     r   _collectzTransport._collect   s(    !      "!r   c                 (   | j         }| j                                        D ]'\  }}t          ||d          st	          |||           (|j        dk    rd|_        t          |j        t                    r%d|j        v r|j        d         |j        |j        d<   t          |j	        |j
        |j        |j        |j        |j        |j        |j        |j        d	fi |j        pi } | j        di |}| j         |_         |                                 |S )z(Establish connection to the AMQP broker.N	localhostz	127.0.0.1server_hostname)	hostuseridpasswordlogin_methodvirtual_hostinsistsslconnect_timeout	heartbeatr   )r=   default_connection_paramsitemsgetattrsetattrhostname
isinstancerV   dictrP   rQ   rR   rS   rT   rU   rW   rX   transport_optionsr7   connect)r   conninfonamedefault_valueoptsconns         r   establish_connectionzTransport.establish_connection   s?   ;#'#A#G#G#I#I 	7 	7D-8T400 7$666++ +HhlD)) 	@!X\11./7.6.?HL*+Mo )$1$1o<'7!+

 

 
/ 
/ '-2
/ 
/ t&&&&kr   c                     |j         S r    )	connectedrE   s     r   verify_connectionzTransport.verify_connection       ##r   c                 <    d|_         |                                 dS )z!Close the AMQP broker connection.N)r=   closerE   s     r   close_connectionzTransport.close_connection   s"     
r   c                     |j         S r    )rX   rE   s     r   get_heartbeat_intervalz Transport.get_heartbeat_interval   rk   r   c                 b    d|j         _        |                    |j        | j        ||           d S NT)	transportraise_on_initial_eintr
add_readersockon_readable)r   rF   loops      r   register_with_event_loopz"Transport.register_with_event_loop   s0    6:
3
)9:tLLLLLr      c                 .    |                     |          S )N)rate)heartbeat_tick)r   rF   r|   s      r   heartbeat_checkzTransport.heartbeat_check   s    ((d(333r   c                 x    |j         }|                    d          dk    rt          |d                   dk     S dS )NproductRabbitMQversion)   r   T)server_propertiesr   r   )r   rF   r   s      r   qos_semantics_matches_specz$Transport.qos_semantics_matches_spec   s>    ,99Y:--*5+;<<vEEtr   c                 B    dd| j         j        r| j        n| j        dddS )NguestrN   PLAIN)rQ   rR   portr]   rS   )r=   rV   r?   r>   rB   s    r   rY   z#Transport.default_connection_params   s9     .2ko ,T**+##
 
 	
r   c                 ,    t          | j        g|R i |S r    )r   r=   )r   argsr   s      r   r   zTransport.get_manager   s"    4;8888888r   )NN)rz   )#r"   r#   r$   r%   r7   DEFAULT_PORTr>   DEFAULT_SSL_PORTr?   r5   connection_errorschannel_errorsrecoverable_connection_errorsrecoverable_channel_errorsdriver_namedriver_typer   r9   
implementsextendr   rC   rG   rI   rL   rg   rj   rn   rp   ry   r~   r   propertyrY   r   r   r   r   r9   r9      s|       JL' 9_3N5 "!%!KKK*11 2  J 6:J J J J     $ $ $1 1 1! ! !  :$ $ $  
$ $ $M M M4 4 4 4   
 
 X
9 9 9 9 9r   r9   c                   "     e Zd ZdZ fdZ xZS )SSLTransportzAMQP SSL Transport.c                 n     t                      j        |i | | j        j        sd| j        _        d S d S rr   )r   r   r=   rV   )r   r   r   r   s      r   r   zSSLTransport.__init__   sD    $)&))) { 	#"DKOOO	# 	#r   r!   r'   s   @r   r   r      s>        # # # # # # # # #r   r   )r%   r5   kombu.utils.amq_managerr   kombu.utils.textr    r   r   r   r   r
   r)   
StdChannelr7   r9   r   r   r   r   <module>r      sa  C CL  / / / / / / 4 4 4 4 4 4       - - - - - -     dl   "7 7 7 7 7dlDO 7 7 74       l9 l9 l9 l9 l9 l9 l9 l9^# # # # #9 # # # # #r   