
    hk                        S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SSKJr  SS	KJr  SS
KJrJrJrJrJrJrJrJrJr  SSKJrJr  SSKJ r    SSK!J"r"  Sr%SRM                  5       r'Sr(\RR                  " S5      r*\RR                  " S5      r+S\S.r,SSSS.r- " S S\5      r.g! \# a     " S S\$5      r" Nbf = f)zAMQP 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                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       7D:\TimeStamps\venv\Lib\site-packages\amqp/connection.pyr   r      s    r"   r   zThe .{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_tickzpy-amqp)productproduct_versionT)consumer_cancel_notifyzconnection.blockedauthentication_failure_closec                     ^ \ rS rSrSr\r\r\r	Sr
SrSrSrSrSrSrSrSr\R(                  " \R*                  R,                  S5      \R(                  " \R*                  R.                  5      \R(                  " \R*                  R0                  S5      \R(                  " \R*                  R2                  S5      \R(                  " \R*                  R4                  S5      \R(                  " \R*                  R6                  5      \R(                  " \R*                  R8                  5      \R(                  " \R*                  R:                  5      1r\ V Vs0 s H  oR>                  U_M     snn r\R*                  R4                  \R*                  R:                  4r \!\"RF                  \$\%4r&\'4r(\)\*\"RF                  \$\%4r+\,4r-S	S
S
SSSSSSSSSSSSSSSSSSS\.\/4U4S jjr0S r1S r2S r3S7S jr4S r5S7S jr6S r7\8S 5       r9\9Rt                  S 5       r9\8S 5       r;\;Rt                  S 5       r;\8S 5       r/\/Rt                  S 5       r/ S8S jr<S r=S9S jr>S:S  jr?S! r@  S;S" jrA\8S# 5       rBS$ rCS% rDS& rES<S' jrFS( rGS7S) jrHS7S* jrIS+ rJ  S=S, jrKS- rLS. rMS/ rNS0 rOS1 rPS2 rQS>S3 jrR\8S4 5       rS\8S5 5       rTS6rUU=rV$ s  snn f )?r$   ?   aJ  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BsBBzlocalhost:5672guestr   /en_USFc                 @  > [         R                  " 5       R                  U l        U=(       d    SnU=(       d    SnU(       a*  [	        U[
        R                  5      (       a  U4nX`l        GO Ub  US:X  a  [
        R                  " U5      nOUS:X  a  [
        R                  " 5       nOUS:X  a(  Ub  Uc  [        S5      e[
        R                  " X#5      nOTUS:X  a(  Ub  Uc  [        S5      e[
        R                  " X#5      nO&Ub  [
        R                  " XE5      nO[        SU5      eU4U l        OY[
        R                  " US	S
9[
        R                  " 5       [
        R                  " X#5      [
        R                  " X#5      4U l        [        U R                  40 U	=(       d    0 D6U l        Xl        Xl        Xpl        [)        U5      U l        UU l        UU l        SU l        0 U l        [4        TU ]m  U S5        S U l        S U l        S U l        Xl        Xl         Xl!        UU l"        Xl#        UU l$        UU l%        UU l&        UU l'        UU l(        [)        U5      U l)        [U        S5      U l+        SU l,        SU l-        0 U l.        / U l/        / U l0        Xl1        g )Ni  i   GSSAPIEXTERNALAMQPLAINz-Must supply authentication or userid/passwordPLAINzInvalid login methodT)	fail_softFr   H)2uuiduuid4hex_connection_id
isinstancer   SASLauthenticationr4   r5   
ValueErrorr6   r7   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)selfrG   useridpasswordlogin_methodlogin_responser@   rH   rF   rE   rW   rd   rS   rT   	heartbeatr]   r[   r\   rV   rI   rX   rY   rZ   r   r   kwargsauth	__class__s                              r#   rO   Connection.__init__   s_    #jjl..!*U'	.$))44"0!2"0%x'{{6*+}}+>X%5$GI I}}V6(>X%5$GI Izz&3+xx= !7FF#''D#';;v#F#'==?#'==#B#'::f#?#AD
 "&##"
'8'>B"
 	((4!. ,#( q!!!% '" ).(*. %(%g.!&s !#.r"   c           
          U R                   (       a7  SU R                   SU R                   SU R                    S[        U 5      S S3	$ SU R                   SU R                   S[        U 5      S S3$ )Nz<AMQP Connection: r1   z using z at z#x>z (disconnected) at )rR   rG   rH   idre   s    r#   __repr__Connection.__repr__  s    ??'		{!D4E4E3F G OO,DD"Q@ @ (		{!D4E4E3F G((*4}A7 7r"   c                 &    U R                  5         U $ N)connectrr   s    r#   	__enter__Connection.__enter__"  s    r"   c                 $    U R                  5         g rv   )close)re   eargss     r#   __exit__Connection.__exit__&  s    

r"   c                 8    U R                   R                  X5      $ rv   )r]   then)re   
on_successon_errors      r#   r   Connection.then)  s    ||  66r"   c                 z   U R                   R                  [        R                  R                  U R
                  [        R                  R                  U R                  [        R                  R                  U R                  [        R                  R                  U R                  [        R                  R                  U R                  [        R                  R                  U R                  [        R                  R                   U R"                  [        R                  R$                  U R&                  05        g rv   )
_callbacksupdater	   r$   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_okrr   s    r#   _setup_listenersConnection._setup_listeners,  s    OO!!4>>OO""D$4$4OO""DOOOO  $--OO!!4>>OO##T%5%5OO%%t'9'9OO##T%6%6	 
 		r"   c           	      l   U R                   (       a  U(       a  U" 5       $ S $  U R                  U R                  U R                  U R                  U R
                  U R                  U R                  S9U l        U R                  R                  5         U R                  X R                  5      U l        U R                  X R                  5      U l        U R                  (       d-  U R!                  U R                  S9  U R                  (       d  M,  g g ! ["        [$        4 a    U R'                  5         e f = f)N)rZ   )timeout)	connectedr   rG   rd   rW   rX   rY   rZ   	transportrw   rJ   on_inbound_methodon_inbound_framerK   r   rL   drain_eventsOSErrorr   collect)re   callbacks     r#   rw   Connection.connect8  s     >>!)8:3t3	!^^		4//!!4#5#5 $ 4 4 , DN
 NN""$$($:$:,,%.D! $ 5 5dNN KD..!!$*>*>!? ... " 	LLN	s   C*D "D3c                 d    [         R                  " [        [        R	                  US95      5        g )N)attr)warningswarnr   W_FORCE_CONNECTformat)re   r   s     r#   _warn_force_connectConnection._warn_force_connectP  s'    ,"""-/ 	0r"   c                 v    U R                   c!  U R                  S5        U R                  5         U R                   $ )Nr   )rR   r   rw   rr   s    r#   r   Connection.transportT  s-    ??"$$[1LLNr"   c                     Xl         g rv   )rR   )re   r   s     r#   r   r   [  s    #r"   c                 v    U R                   c!  U R                  S5        U R                  5         U R                   $ )Nr   )rQ   r   rw   rr   s    r#   r   Connection.on_inbound_frame_  s2    !!)$$%78LLN%%%r"   c                     Xl         g rv   )rQ   )re   r   s     r#   r   r   f  s    !1r"   c                 v    U R                   c!  U R                  S5        U R                  5         U R                   $ )Nr   )rP   r   rw   rr   s    r#   r   Connection.frame_writerj  s1    %$$^4LLN!!!r"   c                     Xl         g rv   )rP   )re   r   s     r#   r   r   q  s    )r"   c           	         U R                   nXl        X l        X0l        [	        U[
        5      (       a  UR                  S5      nUR                  S5      U l        UR                  S5      U l	        [        R                  [        U R                  U R                  U R                  U R                  U R                  5        UR                  S5      =(       d    0 nUR                  S0 5      n	U	R                  U R                   R#                  5        V
Vs0 s H  u  pUR                  U
5      (       d  M  X_M!     snn
5        U	(       d  UR%                  SS 5        U R&                   H;  nUR(                  U R                  ;   d  M  UR+                  U 5      nU[,        Ld  M;    Or   [/        SR1                  SR3                  S U R&                   5       5      R5                  5       SR3                  U R                  5      R5                  5       5      5      eU R7                  [8        R:                  R<                  UX|R(                  XR>                  45        g s  snn
f )Nzutf-8     capabilitieszGCouldn't find appropriate auth mechanism (can offer: {}; available: {})s   , c              3   `   #    U  H$  nUR                   (       d  M  UR                   v   M&     g 7frv   )	mechanism).0ms     r#   	<genexpr>'Connection._on_start.<locals>.<genexpr>  s$      /(;1"#++  +q{{(;s   ..) rE   r_   r`   ra   r>   strencodesplitrb   rc   AMQP_LOGGERdebugSTART_DEBUG_FMTget
setdefaultr   negotiate_capabilitiesitemspopr@   r   startNotImplementedr   r   joindecodesend_methodr	   r$   StartOkrF   )re   r_   r`   ra   rb   rc   argsigrE   scapcap
wanted_cap
enable_capr@   ri   s                 r#   r   Connection._on_startu  s    22**!2j#&&#**73J$**40}}S) 2 2""DOOT\\	
 !$$^4:**>2>

*.*E*E*K*K*M
*M&
xx
# #J"*M
 	
  !!.$7"11N''4??:!/!5!5d!;!7	 2 "117JJ /(,(;(;/ //5vxJJt/668	2:; ; 	OO##V 8 8[[*	
1
s   I
5I
c                     g rv   r   )re   	challenges     r#   r   Connection._on_secure  s    r"   c                 *   U R                   =(       d    SnU=(       d    U R                  U l        U=(       d    U R                  U l        U=(       d    SU l        U R                  S:X  d  US:X  a  [	        U R                  U5      U l        O[        U R                  U5      U l        U R                   (       d  SU l        U R                  [        R                  R                  UU R                  U R                  U R
                  4U R                  S9  g )Nr   r   )rU   rS   rT   server_heartbeatmaxrj   minr   r	   r$   TuneOk_on_tune_sent)re   rS   rT   r   r   rU   s         r#   r   Connection._on_tune  s    005A&:$*:*:"4dnn 0 5A   A%)9Q)> !6!68HIDN !6!68HIDN $$DNOO""Ft~~t~~>'' 	 	
r"   c                 r    U R                  [        R                  R                  XR                  SS45        g )N F)r   r	   r$   OpenrH   )re   r   s     r#   r   Connection._on_tune_sent  s,    OO  &+<+<b%*H	
r"   c                 4    SU l         U R                  U 5        g )NT)rL   r]   rr   s    r#   r   Connection._on_open_ok  s    #' Tr"   c           	      "    [        U4X#XEUS.UD6$ )N)rd   rW   rX   rY   rZ   r   )re   rG   rd   rW   rX   rY   rZ   rk   s           r#   r   Connection.Transport  s,     7"1%+7 067 	7r"   c                 T    U R                   =(       a    U R                   R                  $ rv   )rR   r   rr   s    r#   r   Connection.connected  s    <4??#<#<<r"   c                 B   U R                   (       a  U R                   R                  5         U R                  (       aI  U R                  R                  5        Vs/ s H  nXLd  M	  UPM     nnU H  nUR	                  5         M     S =U l         =U l        U l        g s  snf rv   )rR   r{   rM   valuesr   
connection)re   chrM   s      r#   r   Connection.collect  s    ??OO!!#== "]]1133r> 3  
 

 <@@@$/DMs   B%Bc                 V   [        U R                  5      n[        SU R                  S-   5       H'  nX!;  d  M
  U R                  R	                  U5        Us  $    [        SR                  [        U R                  5      U R                  5      [        R                  R                  5      e)Nr   z/No free channel ids, current={}, channel_max={})setr^   rangerS   appendr   r   lenrM   r	   r   r   )re   used_channel_ids
channel_ids      r#   _get_free_channel_idConnection._get_free_channel_id  s    t5564#3#3a#78J1&&--j9!! 9
 =DDDMM"D$4$467;||7H7HJ 	Jr"   c                 z    XR                   ;   a  [        SU< S35      eU R                   R                  U5        U$ )NzChannel z already open)r^   r   r   )re   r   s     r#   _claim_channel_idConnection._claim_channel_id  s<    ///!HZN-"HII""))*5r"   c                     U R                   c  [        S5      e U R                   U   $ ! [         a%    U R                  XUS9nUR	                  5         Us $ f = f)zCreate new channel.

Fetch a Channel object identified by the numeric channel_id, or
create that object if it doesn't already exist.
zConnection already closed.)r]   )rM   r   KeyErrorr   open)re   r   r   channels       r#   r   Connection.channel  s]     == ,-IJJ	==,, 	ll4XlFGLLNN	s   ) ,AAc                     [        S5      e)NzUse AMQP heartbeats)NotImplementedErrorrr   s    r#   is_aliveConnection.is_alive	  s    !"788r"   c                 d    U R                  U5      (       d   U R                  U5      (       d  M  g g rv   )blocking_read)re   r   s     r#   r   Connection.drain_events  s)    $$W-- $$W--r"   c                     U R                   R                  U5         U R                   R                  5       nS S S 5        U R                  W5      $ ! , (       d  f       N= frv   )r   having_timeout
read_framer   )re   r   frames      r#   r  Connection.blocking_read  sE    ^^**73NN--/E 4$$U++ 43s   A
Ac                 p    U R                   c  [        S5      eU R                   U   R                  X#U5      $ )NzConnection already closed)rM   r   dispatch_method)re   r   
method_sigpayloadcontents        r#   r   Connection.on_inbound_method  s9    == ,-HII}}Z(88
 	
r"   c           	      4   U R                   c  g SU l        U R                  [        R                  R
                  UXUS   US   4[        R                  R                  S9SU l        $ ! [        [        4 a    U R                  5         e f = f! SU l        f = f)x  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.
NTr   r   )waitF)
rR   
is_closingr   r	   r$   r   r   r   r   r   )re   
reply_code
reply_textr  r   s        r#   r{   Connection.close  s    l ??"	$"DO##%%vA
1F__,, $  $DO " 	LLN	
 $DOs   AA) )"BB 	Bc                 F    U R                  5         [        XX44[        5      e)r  )_x_close_okr   r   )re   r  r  class_id	method_ids        r#   r   Connection._on_closef  s*    j 	Z&2OE 	Er"   c                 h    U R                  [        R                  R                  U R                  S9  g)a0  Confirm 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   r	   r$   r   r   rr   s    r#   r  Connection._x_close_ok  s'     	004;L;LMr"   c                 $    U R                  5         g)a1  Confirm 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   rr   s    r#   r   Connection._on_close_ok  s     	r"   c                 L    SnU R                   (       a  U R                  U5      $ g)zTCallback called when connection blocked.

Notes:
    This is an RabbitMQ Extension.
z#connection blocked, see broker logsN)r[   )re   reasons     r#   r   Connection._on_blocked  s$     7????6** r"   c                 F    U R                   (       a  U R                  5       $ g rv   )r\   rr   s    r#   r   Connection._on_unblocked  s    $$&& r"   c                 .    U R                  SSS S S 5        g )N   r   )r   rr   s    r#   send_heartbeatConnection.send_heartbeat  s    !QdD1r"   c                 ~   [         R                  SU R                  5        U R                  (       d  gUS::  a  SnU R                  nU R
                  nU R                  b  U R                  U:w  a  [        5       U l        U R                  b  U R                  U:w  a  [        5       U l
        [        5       n[         R                  SU R                  U R                  X#UU R                  U R                  U R                  5	        X#sU l        U l	        X@R                  U R                  U-  -   :  a?  [         R                  SU R                  5        U R                  5         [        5       U l        SU R                  -  nU R                  U-   nU[        5       :  nU R                  (       a  U(       a  [        S5      egg)aI  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 %sNr      zheartbeat_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 %szToo many heartbeats missed)AMQP_HEARTBEAT_LOGGERr   r=   rj   
bytes_sent
bytes_recv	prev_sentr   last_heartbeat_sent	prev_recvlast_heartbeat_receivedr*  r   )re   ratesent_nowrecv_nownowtwo_heartbeatstwo_heartbeats_intervalheartbeats_misseds           r#   heartbeat_tickConnection.heartbeat_tick  s{    	##$H$($7$7	9~~ 19D ????>>!T^^x%?'0{D$>>!T^^x%?+4;D(k##  NNDNN$$NN
	
 *2& ))DNNT,AAA!''E##% !'0{D$ T^^+"&">">"O3ikA'',="#?@@ ->'r"   c                 .    U R                   R                  $ rv   )r   sockrr   s    r#   r?  Connection.sock
  s    ~~"""r"   c                 J    U R                   R                  S5      =(       d    0 $ )Nr   )ra   r   rr   s    r#   server_capabilitiesConnection.server_capabilities  s    %%)).9?R?r"   )+r=   rP   rL   rQ   rR   r^   r@   rS   rM   rU   rE   rV   rd   r   rJ   rT   r   rK   rj   rG   r  r4  r2  rF   rc   rb   r[   r   r]   rI   r\   r3  r1  rX   r   ra   rZ   rW   r   r_   r`   rH   rY   rv   )FsSs)r.   )ssb)FNNN)NN)r   r   )r   r   r/   )r-  )Wr   r   r   r    __doc__r   NEGOTIATE_CAPABILITIESr   LIBRARY_PROPERTIESrD   rj   rU   r   r2  r4  r/  r0  r1  r3  r	   methodr$   r   r   r   r   r   r   r   r   _METHODSr  _ALLOWED_METHODS_WHEN_CLOSINGr   socketerrorIOErrorr   connection_errorsr   channel_errorsr   r   recoverable_connection_errorsr   recoverable_channel_errorsr   r   rO   rs   rx   r}   r   r   rw   r   propertyr   setterr   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r{   r   r  r   r   r   r*  r<  r?  rB  r!   __classcell__)r   r   rm   s   00@r#   r$   r$   ?   sq   ,\ G 4 , I      J J I I 	DOO))73DOO**+DOO**C0DOO((%0DOO))62DOO++,DOO--.DOO++,	H *22Aa2H 	t66%!
 		 #_N"%! 	 " -Ww"4 "!'TDd1dt"E t4!%]*Y/v77
00   $ $ & & 2 2 " " * * /5/
b
.


 ?C"&7 = =A J 9
,

 =CF$P7ErN+'2=A~ # # @ @Q 3s   K r$   )/rF  loggingrL  r:   r   r   timer   viner   r   r   r   r	   abstract_channelr
   r   r   
exceptionsr   r   r   r   r   r   r   r   r   method_framingr   r   r   r   rW   r   ImportError	Exceptionr   stripr   __all__	getLoggerr   r.  rH  rG  r$   r   r"   r#   <module>ra     s            % % - ) ) ) 8  
	EG  '))/  "  #$( Q@ Q@M  9 s    B5 5C	C	