
    i                         d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZ  ej        e          Z	 ej         n# e$ r  ed          w xY w G d de          Z G d de          ZdS )	    )
ConnectionConnectionShutdownN)LockThread	get_identzgCannot use asyncioreactor without access to asyncio.run_coroutine_threadsafe (added in 3.4.6 and 3.5.1)c                   V    e Zd ZdZed             Zd Zed             Zd Z	d Z
d ZdS )	AsyncioTimera  
    An ``asyncioreactor``-specific Timer. Similar to :class:`.connection.Timer,
    but with a slightly different API due to limitations in the underlying
    ``call_later`` interface. Not meant to be used with a
    :class:`.connection.TimerManager`.
    c                      t          d          )NzD{} is not compatible with TimerManager and does not implement .end()NotImplementedErrorselfs    m/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/cassandra/io/asyncioreactor.pyendzAsyncioTimer.end%   s    ! #> ? ? 	?    c                 j    |                      ||          }t          j        ||          | _        d S )Ntimeoutcallbackloop)_call_delayed_coroasynciorun_coroutine_threadsafe_handle)r   r   r   r   delayeds        r   __init__zAsyncioTimer.__init__*   s<    ))'3; * = =7dKKKr   c                 N   K   t          j        |            d {V   |            S N)r   sleepr   s     r   r   zAsyncioTimer._call_delayed_coro/   s4      mG$$$$$$$$$xzzr   c                 N    	 | j         |j         k     S # t          $ r t          w xY wr   )r   AttributeErrorNotImplemented)r   others     r   __lt__zAsyncioTimer.__lt__4   s7    	!<%-// 	! 	! 	!  	!s    $c                 8    | j                                          d S r   )r   cancelr   s    r   r'   zAsyncioTimer.cancel:   s    r   c                      t          d          )NzG{} is not compatible with TimerManager and does not implement .finish()r   r   s    r   finishzAsyncioTimer.finish=   s     " #A B B 	Br   N)__name__
__module____qualname____doc__propertyr   r   staticmethodr   r%   r'   r)    r   r   r	   r	      s          ? ? X?L L L
   \! ! !  B B B B Br   r	   c                       e Zd ZdZdZ ej                    Z e            Z	dZ
dZdZd Zed             Zed             Zd Zd Zd Zd	 Zd
 Zd ZdS )AsyncioConnectiona  
    An experimental implementation of :class:`.Connection` that uses the
    ``asyncio`` module in the Python standard library for its event loop.

    Note that it requires ``asyncio`` features that were only introduced in the
    3.4 line in 3.4.6, and in the 3.5 line in 3.5.1.
    Nc                    t          j        | g|R i | |                                  | j                            d           t          j                    | _        t          j                    | _	        t          j
        |                                 | j                  | _        t          j
        |                                 | j                  | _        |                                  d S Nr   r   )r   r   _connect_socket_socketsetblockingr   Queue_write_queuer   _write_queue_lockr   handle_read_loop_read_watcherhandle_write_write_watcher_send_options_message)r   argskwargss      r   r   zAsyncioConnection.__init__V   s    D242226222  ####MOO!( %=TZ
 
 
 &>dj
 
 
 	""$$$$$r   c                 ~   | j         5  | j        t          j                    k    rd | _        | j        1t          j                    | _        t          j        | j                   | j        s:t          | j        j
        dd          | _        | j                                         d d d            d S # 1 swxY w Y   d S )NTasyncio_thread)targetdaemonname)_lock_pidosgetpidr<   r   new_event_loopset_event_loop_loop_threadr   run_foreverstart)clss    r   initialize_reactorz$AsyncioConnection.initialize_reactori   s    Y 	) 	)x29;;&& 	y #244	&sy111# ) $*1F15<L$N $N $N  &&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   BB22B69B6c                 0    t          ||| j                  S )Nr   )r	   r<   )rQ   r   r   s      r   create_timerzAsyncioConnection.create_timery   s    GXCI>>>>r   c                     | j         5  | j        r	 d d d            d S d| _        d d d            n# 1 swxY w Y   t          j        |                                 | j                   d S )NTr   )lock	is_closedr   r   _closer<   r   s    r   closezAsyncioConnection.close}   s    Y 	" 	"~ 	" 	" 	" 	" 	" 	" 	" 	" "DN	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	(KKMM
	
 	
 	
 	
 	
 	
s   	1155c                   K   t                               dt          |           d| j                   | j        r| j                                         | j        r| j                                         | j        r{| j        	                    | j        
                                           | j                            | j        
                                           | j                                         t                               d| j                   | j        sE|                     t          d| j        z                       | j                                         d S d S )NzClosing connection (z) to zClosed socket to zConnection to %s was closed)logdebugidendpointr?   r'   r=   r6   r<   remove_writerfilenoremove_readerrY   
is_defuncterror_all_requestsr   connected_eventsetr   s    r   rX   zAsyncioConnection._close   sM     			RXXXXt}}MNNN 	)&&((( 	(%%'''< 	!J$$T\%8%8%:%:;;;J$$T\%8%8%:%:;;;L   			4==:;;; 	'##"#@4=#PQQS S S  $$&&&&&		' 	'r   c                    | j         }t          |          |k    rDg }t          dt          |          |          D ]"}|                    ||||z                       #n|g}| j        j        t                      k    r0t          j        | 	                    |          | j
                   d S | j
                            | 	                    |                     d S r4   )out_buffer_sizelenrangeappendrN   identr   r   r   	_push_msgr<   create_task)r   data	buff_sizechunksis        r   pushzAsyncioConnection.push   s    (	t99y  F1c$ii33 5 5d1Q]?344445 VF"ikk11,v&&Z      J""4>>&#9#9:::::r   c                    K   | j         4 d {V  |D ]}| j                            |           	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   )r:   r9   
put_nowait)r   rp   chunks      r   rl   zAsyncioConnection._push_msg   s      ) 	4 	4 	4 	4 	4 	4 	4 	4 4 4!,,U33334	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s    A
AAc                 Z  K   	 	 | j                                          d {V }|r&| j                            | j        |           d {V  n_# t
          j        $ r<}t                              d| |           | 	                    |           Y d }~d S d }~wt          j        $ r Y d S w xY w)NTzException in send for %s: %s)r9   getr<   sock_sendallr6   socketerrorr[   r\   defunctr   CancelledError)r   next_msgerrs      r   r>   zAsyncioConnection.handle_write   s      
		!%!2!6!6!8!8888888 J*11$,IIIIIIIII<   		8$DDDS!!!)   
	s   AA B)1BB)(B)c                   K   	 	 | j                             | j        | j                   d {V }| j                            |           n# t          j        t          j        f$ r t          j
        d           d {V  Y t          j        $ r<}t                              d| |           |                     |           Y d }~d S d }~wt          j        $ r Y d S w xY w|r.| j                                        r|                                  n1t                              d|            |                                  d S ?)NTr   z'Exception during socket recv for %s: %szConnection %s closed by server)r<   	sock_recvr6   in_buffer_size_iobufwritesslSSLWantWriteErrorSSLWantReadErrorr   r    ry   rz   r[   r\   r{   r|   tellprocess_io_bufferrY   )r   bufr~   s      r   r;   zAsyncioConnection.handle_read   sy     	 J00t?RSSSSSSSS!!#&&&&
 )3+?@    mA&&&&&&&&&<   		C% % %S!!!)     t{'')) &&((((		:DAAA

5	s$   AA 5CC1CCC)r*   r+   r,   r-   r<   rJ   rK   rI   r   rH   rN   r9   r:   r   classmethodrR   rT   rY   rX   rr   rl   r>   r;   r0   r   r   r2   r2   D   s          E29;;DDFFELL% % %& ) ) [) ? ? [?

 

 

' ' '&; ; ;$4 4 4      r   r2   )cassandra.connectionr   r   r   loggingrJ   ry   r   	threadingr   r   r   	getLoggerr*   r[   r   r"   ImportErrorobjectr	   r2   r0   r   r   <module>r      s3   ? ? ? ? ? ? ? ?   				  



 - - - - - - - - - - g!!$$$   
+	F  $B $B $B $B $B6 $B $B $BNY Y Y Y Y
 Y Y Y Y Ys   A   A