
    jKj
                         d dl Z d dlZd dlZd dlmZ ddlmZ ej                  ej                     Z	ej                  ej                     Z G d de j                        Zy)    N)partial   )abstractc                      e Zd ZdZdZdZddZd Zd Zd Z	d Z
d Zd	 Zd
 Z	 ddededededej                   e   f
dZ	 ddededededej                   e   f
dZdedej                   fdZdedej                   fdZy)AsyncioContextBasei   Nc                     |xs | j                   }|xs t        j                         | _        t        j                  |      | _         | j                  |fi || _        y N)MAX_REQUESTS_DEFAULTasyncioget_event_looploopBoundedSemaphore	semaphore_create_contextcontext)selfmax_requestsr   kwargss       b/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/caio/asyncio_base.py__init__zAsyncioContextBase.__init__   sR    #@t'@'@4G224	 11,?+t++LCFC    c                 *     | j                   dd|i|S )Nr    )CONTEXT_CLASS)r   r   r   s      r   r   z"AsyncioContextBase._create_context   s    !t!!F|FvFFr   c                      y r	   r   r   s    r   _destroy_contextz#AsyncioContextBase._destroy_context   s    r   c                    K   | S wr	   r   r   s    r   
__aenter__zAsyncioContextBase.__aenter__   s     s   c                 ,   K   | j                          y wr	   )close)r   exc_typeexc_valexc_tbs       r   	__aexit__zAsyncioContextBase.__aexit__!   s     

s   c                 $    | j                          y r	   )r   r   s    r   r!   zAsyncioContextBase.close$   s    r   c                 Z  K   t        || j                        st        d      | j                  j	                         }|j                  t        | j                  |             | j                  4 d {    | j                  j                  |      dk7  rt        d      	 | d {    |j                         cd d d       d {    S 7 Y7 '# t        j                  $ r- 	 | j                  j                  |        # t        $ r Y  w xY ww xY w7 L# 1 d {  7  sw Y   y xY ww)NzOperation object expectedr   zOperation was not submitted)
isinstanceOPERATION_CLASS
ValueErrorr   create_futureset_callbackr   _on_doner   r   submitIOErrorr   CancelledErrorcancel	get_value)r   opfutures      r   r.   zAsyncioContextBase.submit'   s     "d223899((*
v67>>>||""2&!+;<< <<> ">>
 )) LL''+  "  ">>>s   A1D+3C4D+7*D"C'C(C,D;D+DD+CD%D D	D
DDDDD+D(DD($D+c                 d    j                         ry| j                  j                  fd       y)z
        In general case impossible predict current thread and the thread
        of event loop. So have to use `call_soon_threadsave` the result setter.
        Nc                  J     j                         xs  j                  d      S )NT)done
set_result)r4   s   r   <lambda>z-AsyncioContextBase._on_done.<locals>.<lambda>F   s    FKKM<V%6%6t%<<r   )r7   r   call_soon_threadsafe)r   r4   results    ` r   r-   zAsyncioContextBase._on_done<   s&     ;;=		&&<	
r   nbytesfdoffsetpriorityreturnc                 \    | j                  | j                  j                  ||||            S r	   )r.   r)   read)r   r<   r=   r>   r?   s        r   rB   zAsyncioContextBase.readI   s/     {{  %%fb&(C
 	
r   payloadc                 \    | j                  | j                  j                  ||||            S r	   )r.   r)   write)r   rC   r=   r>   r?   s        r   rE   zAsyncioContextBase.writeQ   s/     {{  &&wFHE
 	
r   c                 V    | j                  | j                  j                  |            S r	   )r.   r)   fsyncr   r=   s     r   rG   zAsyncioContextBase.fsyncY   s"    {{4//55b9::r   c                 V    | j                  | j                  j                  |            S r	   )r.   r)   fdsyncrH   s     r   rJ   zAsyncioContextBase.fdsync\   s"    {{4//66r:;;r   )NN)r   )__name__
__module____qualname__r
   r   r)   r   r   r   r   r%   r!   r.   r-   inttyping	AwaitablebytesrB   rE   rG   rJ   r   r   r   r   r      s    MODG "*
 &'

"

"
 
		%	 
 &'

"%

"
 
		#	
; ; 0 0 ;< <!1!1 <r   r   )abcr   rO   	functoolsr    r   TypeAbstractContextContextTypeAbstractOperationOperationTypeABCr   r   r   r   <module>r[      sP    
     kk(223H667P< P<r   