
    f                         d Z ddlZddlZddlZddlmZ ej                  dd       Zej                  d	d       Z G d dej                        Z
y)
zImplementation of coroutines without using ``async def``/``await`` keywords.

``@asyncio.coroutine`` and ``yield from`` are  used here instead.
    N)EOFc              #     K   | j                         }||S | j                  j                  skt               j	                  |        t        j                         j                  fd| j                        E d {   \  }|f| j                  _        n:| j                  j                  \  }j	                  |        |j                          	 t        j                  j                  |      E d {   S 7 ~7 # t
        j                  $ r+}|j                          | j                  |      cY d }~S d }~ww xY ww)Nc                       S N )pws   S/var/www/cvtools/html/venv/lib/python3.12/site-packages/pexpect/_async_pre_await.py<lambda>zexpect_async.<locals>.<lambda>   s    B     )existing_dataspawnasync_pw_transportPatternWaiterset_expecterasyncioget_event_loopconnect_read_piperesume_readingwait_forfutTimeoutErrorpause_readingtimeout)expecterr   idx	transporter   s        @r	   expect_asyncr      s     
 
 
"C

>>,,_
!#*#9#9#;#M#M$
 
	2 -/	M) 99I
!  "#"++BFFG<<=
 = #!""#sU   A:E=C<>AE#D  7C>8D  ;E>D   D> D93D>4E9D>>Ec              #   P  K   g }| j                   j                  |d          |dd  D ]]  }| j                  |d      E d {    |j                  | j                   j                         | j                   j                  |       _ | j                  |d      E d {   }|dk(  rO| j                   j                  t        j                         | j                  dd      E d {    t        d      dj                  || j                   j                  gz         S 7 7 7 <w)Nr      T)r   async_z1Continuation prompt found - input was incomplete: )
childsendline_expect_promptappendbeforekillsignalSIGINT
ValueErrorjoin)replcmdlinesr   resline
prompt_idxs         r	   repl_run_command_asyncr2   %   s    
CJJ$ "&&wt&DDD

4::$$%

D!" !///MMJQ

&&&q&>>>LMM773$**++,,-- 	E
 N 	?s7   ?D&D AD&D"AD&'D$(9D&"D&$D&c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y)	r   Nc                 D    || _         t        j                         | _        y r   )r   r   Futurer   )selfr   s     r	   r   zPatternWaiter.set_expecter;   s     >>#r   c                     | j                   j                         s6| j                   j                  |       | j                  j	                          y y r   )r   done
set_resultr   r   )r6   results     r	   foundzPatternWaiter.found?   s6    xx}}HH'NN((* r   c                     | j                   j                         s6| j                   j                  |       | j                  j	                          y y r   )r   r8   set_exceptionr   r   r6   excs     r	   errorzPatternWaiter.errorD   s6    xx}}HH""3'NN((* r   c                     || _         y r   )r   )r6   r   s     r	   connection_madezPatternWaiter.connection_madeI   s	    "r   c                    | j                   j                  }|j                  j                  |      }|j	                  |d       | j
                  j                         r7|j                  j                  |       |j                  j                  |       y 	 | j                   j                  |      }|| j                  |       y y # t        $ r5}| j                   j                          | j                  |       Y d }~y d }~ww xY w)Nread)r   r   _decoderdecode_logr   r8   _beforewrite_buffernew_datar;   	Exceptionerroredr@   )r6   datar   sindexr   s         r	   data_receivedzPatternWaiter.data_receivedL   s    ##NN!!$'

1f88==?MM"MM"	MM**1-E 

5! !  	MM!!#JJqMM	s   .C 	D+C??Dc                     	 d| j                   j                  _        | j                   j                         }| j	                  |       y # t
        $ r}| j                  |       Y d }~y d }~ww xY w)NT)r   r   flag_eofeofr;   r   r@   )r6   rP   r   s      r	   eof_receivedzPatternWaiter.eof_received_   sX    	+/DMM(MM%%'E JJu  	JJqMM	s   5A	 		A-A((A-c                     t        |t              r.|j                  t        j                  k(  r| j	                          y || j                  |       y y r   )
isinstanceOSErrorerrnoEIOrU   r@   r>   s     r	   connection_lostzPatternWaiter.connection_lostj   s<    c7#		UYY(>_JJsO r   )__name__
__module____qualname__r   r   r;   r@   rB   rQ   rU   r[   r   r   r	   r   r   8   s*    I$+
+
#&	r   r   r   ))__doc__r   rY   r)   pexpectr   	coroutiner   r2   Protocolr   r   r   r	   <module>rd      s^        	# #0 	. .$7G$$ 7r   