
    mgLw                     H   d Z ddlZddlZddlZddlmZmZmZmZ ddlm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZmZ ddlmZm Z m!Z! ddlm"Z"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) erddl*m+Z+ ddl,m-Z- erej\                  d   Z/nej\                  Z/eeee0f      Z1e
ee1e   f   Z2e
eejf                  f   Z4e
eee/   f   Z5e
eee/   f   Z6e	ddged   f   Z7ee7   Z8e	g ded   f   Z9ee9   Z:e	dge&f   Z;ee;   Z< e=       Z> G d dee         Z? G d dee         Z@ G d dee         ZA G d deAe   e e         ZB G d deAe   e!e         ZC G d deAe         ZD G d d eDe   e"e         ZE G d! d"eDe   e#e         ZF G d# d$eDeG   e$      ZHy)%zSSH stream handlers    N)TYPE_CHECKINGAnyAnyStrAsyncIterator)CallableDictGenericIterableList)OptionalPatternSetTupleUnioncast   )EXTENDED_DATA_STDERR)	SSHLogger)
MaybeAwaitBreakReceivedSignalReceived)SoftEOFReceivedTerminalSizeChanged)DataTypeSSHClientSessionSSHServerSession)SSHTCPSessionSSHUNIXSessionSSHTunTapSession)
SFTPServerrun_sftp_server)run_scp_server)
SSHChannel)SSHConnection	SSHReader	SSHWriter)r%   r&   r&   SSHChannel[bytes]c                       e Zd ZdZ	 ddddddefdZd	ee   fd
Ze	dd       Z
e	d	efd       Zddeded	efdZded	dfdZddZdded	efdZd	efdZ	 dded	efdZded	efdZd	efdZd	edef   fdZy) r%   zSSH read stream handlerNsessionSSHStreamSession[AnyStr]chanSSHChannel[AnyStr]datatypec                 .    || _         || _        || _        y N_session_chan	_datatypeselfr)   r+   r-   s       /lib/python3.12/site-packages/asyncssh/stream.py__init__zSSHReader.__init__K       4;+/
!    returnc                z   K   | j                   j                  | j                        2 3 d{   }| 7 
6 ywz'Allow SSHReader to be an async iteratorN)r1   aiterr3   )r5   results     r6   	__aiter__zSSHReader.__aiter__Q   s3      !MM//? 	&L	?s   &;979;9;c                     | j                   S z+The SSH channel associated with this streamr2   r5   s    r6   channelzSSHReader.channelW        zzr9   c                 .    | j                   j                  S z*The SSH logger associated with this streamr2   loggerrC   s    r6   rI   zSSHReader.logger]        zz   r9   namedefaultc                 :    | j                   j                  ||      S a3  Return additional information about this stream

           This method returns extra information about the channel
           associated with this stream. See :meth:`get_extra_info()
           <SSHClientChannel.get_extra_info>` on :class:`SSHClientChannel`
           for additional information.

        r2   get_extra_infor5   rK   rL   s      r6   rP   zSSHReader.get_extra_infoc        zz((w77r9   datac                 P    | j                   j                  || j                         y)aN  Feed data to the associated session

           This method feeds data to the SSH session associated with
           this stream, providing compatibility with the
           :meth:`feed_data() <asyncio.StreamReader.feed_data>` method
           on :class:`asyncio.StreamReader`. This is mostly useful
           for testing.

        N)r1   data_receivedr3   r5   rS   s     r6   	feed_datazSSHReader.feed_datao   s     	##D$..9r9   c                 8    | j                   j                          y)aa  Feed EOF to the associated session

           This method feeds an end-of-file indication to the SSH session
           associated with this stream, providing compatibility with the
           :meth:`feed_eof() <asyncio.StreamReader.feed_data>` method
           on :class:`asyncio.StreamReader`. This is mostly useful
           for testing.

        N)r1   eof_receivedrC   s    r6   feed_eofzSSHReader.feed_eof|   s     	""$r9   nc                 n   K   | j                   j                  | j                  |d       d{   S 7 w)a  Read data from the stream

           This method is a coroutine which reads up to `n` bytes
           or characters from the stream. If `n` is not provided or
           set to `-1`, it reads until EOF or a signal is received.

           If EOF is received and the receive buffer is empty, an
           empty `bytes` or `str` object is returned.

           If the next data in the stream is a signal, the signal is
           delivered as a raised exception.

           .. note:: Unlike traditional `asyncio` stream readers,
                     the data will be delivered as either `bytes` or
                     a `str` depending on whether an encoding was
                     specified when the underlying channel was opened.

        FexactNr1   readr3   r5   r[   s     r6   r`   zSSHReader.read   s.     ( ]]'''GGGG   ,535c                 h   K   | j                   j                  | j                         d{   S 7 w)a  Read one line from the stream

           This method is a coroutine which reads one line, ending in
           `'\n'`.

           If EOF is received before `'\n'` is found, the partial
           line is returned. If EOF is received and the receive buffer
           is empty, an empty `bytes` or `str` object is returned.

           If the next data in the stream is a signal, the signal is
           delivered as a raised exception.

           .. note:: In Python 3.5 and later, :class:`SSHReader` objects
                     can also be used as async iterators, returning input
                     data one line at a time.

        N)r1   readliner3   rC   s    r6   rd   zSSHReader.readline   s'     & ]]++DNN;;;;s   )202	separatorc                 l   K   | j                   j                  || j                  |       d{   S 7 w)a  Read data from the stream until `separator` is seen

           This method is a coroutine which reads from the stream until
           the requested separator is seen. If a match is found, the
           returned data will include the separator at the end.

           The `separator` argument can be a single `bytes` or `str`
           value, a sequence of multiple `bytes` or `str` values,
           or a compiled regex (`re.Pattern`) to match against,
           returning data as soon as a matching separator is found
           in the stream.

           When passing a regex pattern as the separator, the
           `max_separator_len` argument should be set to the
           maximum length of an expected separator match. This
           can greatly improve performance, by minimizing how far
           back into the stream must be searched for a match.
           When passing literal separators to match against, the
           max separator length will be set automatically.

           .. note:: For best results, a separator regex should
                     both begin and end with data which is as
                     unique as possible, and should not start or
                     end with optional or repeated elements.
                     Otherwise, you run the risk of failing to
                     match parts of a separator when it is split
                     across multiple reads.

           If EOF or a signal is received before a match occurs, an
           :exc:`IncompleteReadError <asyncio.IncompleteReadError>`
           is raised and its `partial` attribute will contain the
           data in the stream prior to the EOF or signal.

           If the next data in the stream is a signal, the signal is
           delivered as a raised exception.

        N)r1   	readuntilr3   )r5   re   max_separator_lens      r6   rg   zSSHReader.readuntil   s9     P ]],,Y->@ @ 	@ @s   +424c                 n   K   | j                   j                  | j                  |d       d{   S 7 w)a  Read an exact amount of data from the stream

           This method is a coroutine which reads exactly n bytes or
           characters from the stream.

           If EOF or a signal is received in the stream before `n`
           bytes are read, an :exc:`IncompleteReadError
           <asyncio.IncompleteReadError>` is raised and its `partial`
           attribute will contain the data before the EOF or signal.

           If the next data in the stream is a signal, the signal is
           delivered as a raised exception.

        Tr]   Nr_   ra   s     r6   readexactlyzSSHReader.readexactly   s.       ]]'''FFFFrb   c                 L    | j                   j                  | j                        S )zReturn whether the stream is at EOF

           This method returns `True` when EOF has been received and
           all data in the stream has been read.

        )r1   at_eofr3   rC   s    r6   rl   zSSHReader.at_eof   s     }}##DNN33r9   c                 2    | j                   | j                  fS )z6Get information needed to redirect from this SSHReaderr1   r3   rC   s    r6   get_redirect_infozSSHReader.get_redirect_info        }}dnn,,r9   r/   r:   r,   r:   N)r   )__name__
__module____qualname____doc__r   r7   r   r   r?   propertyrD   r   rI   strr   rP   rW   rZ   intr`   rd   objectrg   rj   boolrl   r   ro    r9   r6   r%   r%   H   s   ! CG" : "+"7?"v!6   
 !	 ! !

83 
8 
8 
8:f : :%HC H H,< <, -.)@ )@28)@VG3 G6 G$4 4-5)CX)M#N -r9   c                       e Zd ZdZ	 ddddddefdZedd
       Zed	efd       Z	dde
ded	efdZd	efdZddZd	efdZddZddZded	dfdZdee   d	dfdZddZd	edef   fdZy)r&   zSSH write stream handlerNr)   r*   r+   r,   r-   c                 .    || _         || _        || _        y r/   r0   r4   s       r6   r7   zSSHWriter.__init__  r8   r9   r:   c                     | j                   S rA   rB   rC   s    r6   rD   zSSHWriter.channel
  rE   r9   c                 .    | j                   j                  S rG   rH   rC   s    r6   rI   zSSHWriter.logger  rJ   r9   rK   rL   c                 :    | j                   j                  ||      S rN   rO   rQ   s      r6   rP   zSSHWriter.get_extra_info  rR   r9   c                 6    | j                   j                         S )z4Return whether the stream supports :meth:`write_eof`)r2   can_write_eofrC   s    r6   r   zSSHWriter.can_write_eof"  s     zz''))r9   c                 6    | j                   j                         S )zClose the channel

           .. note:: After this is called, no data can be read or written
                     from any of the streams associated with this channel.

        )r2   closerC   s    r6   r   zSSHWriter.close'  s     zz!!r9   c                 6    | j                   j                         S )z,Return if the stream is closing or is closed)r2   
is_closingrC   s    r6   r   zSSHWriter.is_closing1  s     zz$$&&r9   c                 T   K   | j                   j                          d{    y7 w)zWait until the stream is closed

           This should be called after :meth:`close` to wait until
           the underlying connection is closed.

        N)r2   wait_closedrC   s    r6   r   zSSHWriter.wait_closed6  s      jj$$&&&s   (&(c                 j   K   | j                   j                  | j                         d{    y7 w)a  Wait until the write buffer on the channel is flushed

           This method is a coroutine which blocks the caller if the
           stream is currently paused for writing, returning when
           enough data has been sent on the channel to allow writing
           to resume. This can be used to avoid buffering an excessive
           amount of data in the channel's send buffer.

        N)r1   drainr3   rC   s    r6   r   zSSHWriter.drain@  s$      mm!!$..111s   )313rS   c                 N    | j                   j                  || j                        S )at  Write data to the stream

           This method writes bytes or characters to the stream.

           .. note:: Unlike traditional `asyncio` stream writers,
                     the data must be supplied as either `bytes` or
                     a `str` depending on whether an encoding was
                     specified when the underlying channel was opened.

        )r2   writer3   rV   s     r6   r   zSSHWriter.writeM  s     zzdnn55r9   list_of_datac                 N    | j                   j                  || j                        S )z(Write a collection of data to the stream)r2   
writelinesr3   )r5   r   s     r6   r   zSSHWriter.writelines[  s     zz$$\4>>BBr9   c                 6    | j                   j                         S )a  Write EOF on the channel

           This method sends an end-of-file indication on the channel,
           after which no more data can be written.

           .. note:: On an :class:`SSHServerChannel` where multiple
                     output streams are created, writing EOF on one
                     stream signals EOF for all of them, since it
                     applies to the channel as a whole.

        )r2   	write_eofrC   s    r6   r   zSSHWriter.write_eof`  s     zz##%%r9   c                 2    | j                   | j                  fS )z4Get information needed to redirect to this SSHWriterrn   rC   s    r6   ro   zSSHWriter.get_redirect_infoo  rp   r9   r/   rq   rr   )ru   rv   rw   rx   r   r7   ry   rD   r   rI   rz   r   rP   r}   r   r   r   r   r   r   r   r
   r   r   r   ro   r~   r9   r6   r&   r&     s    " CG" : "+"7?"  
 !	 ! !

83 
8 
8 
8*t *
"'D '
'26& 6T 6Cx'7 CD C
&-5)CX)M#N -r9   c                   @   e Zd ZdZddZdedee   fdZdeddfdZ	deddfdZ
dedefd	Zdeddfd
ZdefdZdefdZdefdZddZdee   ddfdZdededdfdZdefdZdedefdZddZddZdedededefdZdedefdZ	 d dededefdZdeddfdZy)!SSHStreamSessionzSSH stream session handlerr:   Nc                 (   d | _         d | _        d | _        d| _        d | _        d| _        d | _        d| _        d| _        d| _	        d| _
        d| _        d g i| _        d t        j                         i| _        d d i| _        d t#               i| _        y )Nstrictr   F)r2   _conn	_encoding_errors_loop_limit
_exception_eof_received_connection_lost_read_paused_write_paused_recv_buf_len	_recv_bufasyncioLock_read_locks_read_waitersset_drain_waitersrC   s    r6   r7   zSSHStreamSession.__init__x  s    59
04
(,:>
/3" %!"/3Rj(,glln'=,0$<.2CE]r9   r-   c                   K   | j                  |      s/| j                  |       d{    | j                  |      s.yy7 wr<   )rl   rd   r5   r-   s     r6   r=   zSSHStreamSession.aiter  s7      ++h'h/// ++h'/s   &AAAAc                    K   	 | j                   J | j                   j                         }|| j                  |<   | d{    d| j                  |<   y7 # d| j                  |<   w xY ww)z*Wait for more data to arrive on the streamN)r   create_futurer   r5   r-   waiters      r6   _block_readzSSHStreamSession._block_read  sj     	0::)))$(JJ$<$<$>F+1Dx(LL+/Dx( +/Dx(s.   A+<A  AA A+A A((A+c                 l    | j                   |   }|r#|j                         s|j                  d       yyy)z/Signal that more data has arrived on the streamN)r   done
set_resultr   s      r6   _unblock_readzSSHStreamSession._unblock_read  s4     ##H-&++-d# (6r9   c                 8    | j                   xr | j                   S )z;Return whether output is still being written to the channel)r   r   r   s     r6   _should_block_drainz$SSHStreamSession._should_block_drain  s    
 !!?$*?*?&??r9   c                     | j                  |      s7| j                  |   D ]$  }|j                         r|j                  d       & yy)z2Signal that more data can be written on the streamN)r   r   r   r   r   s      r6   _unblock_drainzSSHStreamSession._unblock_drain  sC     ''1--h7{{}%%d+ 8 2r9   c                 b    t        | j                        xr | j                  | j                  k\  S )z0Return whether to pause reading from the channel)r}   r   r   rC   s    r6   _should_pause_readingz&SSHStreamSession._should_pause_reading  s'     DKK FT%7%74;;%FFr9   c                     | j                   s@| j                         r0| j                  J d| _         | j                  j                          yy)zPause reading if necessaryTF)r   r   r2   pause_readingrC   s    r6   _maybe_pause_readingz%SSHStreamSession._maybe_pause_reading  sF       T%?%?%A::))) $DJJ$$&r9   c                     | j                   r@| j                         s0| j                  J d| _         | j                  j                          yy)zResume reading if necessaryFT)r   r   r2   resume_readingrC   s    r6   _maybe_resume_readingz&SSHStreamSession._maybe_resume_reading  sF     T%?%?%A::))) %DJJ%%'r9   c                    || _         |j                         | _        |j                         \  | _        | _        |j                         | _        | j                   j                         | _	        |j                         D ]A  }g | j                  |<   t        j                         | j                  |<   d| j                  |<   C |j!                         D ]  }t#               | j$                  |<    y)zHandle a newly opened channelN)r2   get_connectionr   get_encodingr   r   get_loopr   get_recv_windowr   get_read_datatypesr   r   r   r   r   get_write_datatypesr   r   )r5   r+   r-   s      r6   connection_madez SSHStreamSession.connection_made  s     
((*
'+'8'8':$]]_
jj002//1H')DNN8$)0DX&+/Dx( 2
 002H,/ED) 3r9   excc                     d| _         || _        | j                  sA|r/| j                  D ]   }| j                  |   j                  |       " | j                          | j                  D ]  }| j                  |        y)z Handle an incoming channel closeTN)	r   r   r   r   r   appendrY   r   r   )r5   r   r-   s      r6   connection_lostz SSHStreamSession.connection_lost  sr     !%!! $ 2 2HNN8,33C8 !3 ++H) ,r9   rS   c                     | j                   |   j                  |       | xj                  t        |      z  c_        | j	                  |       | j                          y)z#Handle incoming data on the channelN)r   r   r   lenr   r   )r5   rS   r-   s      r6   rU   zSSHStreamSession.data_received  sJ     	x ''-c$i'8$!!#r9   c                 V    d| _         | j                  D ]  }| j                  |        y)z-Handle an incoming end of file on the channelT)r   r   r   r   s     r6   rY   zSSHStreamSession.eof_received  s/     "**Hx( + r9   c                 >    | j                   xr | j                  |    S )z;Return whether end of file has been received on the channel)r   r   r   s     r6   rl   zSSHStreamSession.at_eof  s!     !!B$..*B&BBr9   c                     d| _         y)z0Handle a request to pause writing on the channelTN)r   rC   s    r6   pause_writingzSSHStreamSession.pause_writing  s     "r9   c                 V    d| _         | j                  D ]  }| j                  |        y)z1Handle a request to resume writing on the channelFN)r   r   r   r   s     r6   resume_writingzSSHStreamSession.resume_writing	  s*     #++H) ,r9   r[   r^   c           	        K   | j                   |   }g }d}| j                  |   4 d{    	 |r|dk7  rt        |d   t              r9|rd}nt	        t        |j                  d            }t        |t              rd}n|t        |d         }||cxkD  rdkD  r=n n:|j                  |d   d|        |d   |d |d<   | xj                  |z  c_	        d}nP|j                  t	        t        |j                  d                   | xj                  |z  c_	        ||z  }|r|dk7  r| j                         r|dk(  s|dkD  r|r|r|dk  r|s| j                  s|rn| j                  |       d{    Jddd      d{    t	        t        | j                  rdnd      j                  |      }	|dkD  r2|r0t!        j"                  t	        t$        |	      t        |	      |z         |	S 7 7 7 o# 1 d{  7  sw Y   xY ww)zRead data from the channelFNTr    r9   )r   r   
isinstance	Exceptionr   popr   r   r   r   r   r   r   r   r   joinr   IncompleteReadErrorbytes)
r5   r-   r[   r^   recv_bufrS   
break_readr   lr>   s
             r6   r`   zSSHStreamSession.read  s     >>(+
##H--16!(1+y9)-J!"&y(,,q/"BC)#?$% %&)	HQK(A1yqyHQKO4&.qk!"o**a/*KKVX\\!_ =>&&!+&FA3 166 --/6a!eUQ8**j&&x000I  .-N fDNNb<AA$Gq5U--d5&.A.1&kAo? ? [ .J 1K .---s_   'HG/HC:G6(A
G62G23G69HG4A+H2G64H6H<G?=HHc                    K   	 | j                  t        |       d{   S 7 # t        j                  $ r$}t	        t
        |j                        cY d}~S d}~ww xY ww)zRead one line from the streamN)rg   _NEWLINEr   r   r   r   partial)r5   r-   r   s      r6   rd   zSSHStreamSession.readlineG  sH     	-(;;;;** 	-,,	-s<   A$ "$ A$ AAAAAAre   c                 n  K   |st        d      t        t        | j                  rdnd      }| j                  |   }|t
        u r6d}t        t        | j                  rdnd      }t        j                  |      }nt        |t        t        f      rBt        |      }t        j                  t        j                  t        t        |                  }nt        |t              r|}t        t        t           |      }n}t        t        | j                  rdnd      }	t        t        t        t           |            }
t!        d	 |
D              }|	j#                  d
 |
D              }t        j                  |      }d}d}| j$                  |   4 d{    	 |t        |      k  rot        ||   t&              r|r>g |d| | xj(                  |z  c_        t+        j,                  t        t        |      d      |j/                  d      }t        |t0              r|cddd      d{    S t        t&        |      t        t        ||         }||z  }|dk(  rdnt!        |dz   |z
  d      }|j3                  ||      }|rp|j5                         }g |d| ||d |d<   |d| }| xj(                  |z  c_        |d   s|j/                  d       | j7                          |cddd      d{    S |t        |      z  }|dz  }|t        |      k  ro| j8                  s| j:                  rNg |d| | xj(                  |z  c_        | j7                          t+        j,                  t        t        |      d      | j=                  |       d{    7 7 r7 7 # 1 d{  7  sw Y   yxY ww)z4Read data from the channel until a separator is seenzSeparator cannot be emptyr   r9   r   
   
|   |c              3   2   K   | ]  }t        |        y wr/   )r   .0seps     r6   	<genexpr>z-SSHStreamSession.readuntil.<locals>.<genexpr>f  s     5WcSWs   c              3   F   K   | ]  }t        j                  |        y wr/   )reescaper   s     r6   r   z-SSHStreamSession.readuntil.<locals>.<genexpr>g  s     !DGS"))C.Gs   !r   N)
ValueErrorr   r   r   r   r   r   compiler   r   rz   r   r   r   listr
   maxr   r   r   r   r   r   r   r   searchendr   r   r   r   )r5   re   r-   rh   bufr   seplen
separatorspatbarseplistcurbufbuflenr   newbufstartmatchidxs                     r6   rg   zSSHStreamSession.readuntilO  s:     89962S9>>(+ Ffdnnd%HJ**Z(C	E3<0^F**RYYtFI'>?@C	7+&Fwv	2Cvdnns$?C4 0)<=G5W55F!DG!DDJ**Z(C##H--s8},!(6"2I>02HWf- ..&8.")"="= $UC 0$#8 8 #+,,q/C)#?'* .-- '+9c&: :!&(6*:;F6MC!'1A#fqj66I12MEJJsE2E#iik,.&)&)#$i!$3i**c1*'{$LLO224"C .--F c&k)FaKFE s8},H $$(:(:(*HWf%&&&0&..0!55d5#6FMM&&x000W  .--X 1Y .--s   FN5NN5BN N5'N(N5-B3N  N5,N-N52!N A:N NN N5N5N5N  N2&N)'N2.N5c                   K   | j                  |      r	 | j                  J | j                  j                         }| j                  |   j	                  |       | d{    | j                  |   j                  |       | j                  |      r| j                  r)| j                  }|s| j                  r
t               }|r|yy7 j# | j                  |   j                         w xY ww)z-Wait for data written to the channel to drainN)
r   r   r   r   addremover   r   r   BrokenPipeError)r5   r-   r   r   s       r6   r   zSSHStreamSession.drain  s      &&x0=zz---(,

(@(@(B##H-11&9##H-44V< &&x0   //C4--%'	  !	 ##H-44V<s5   C0AC  C!C %/C06C0C  C--C0rr   )r+   r,   r:   Nrt   ) ru   rv   rw   rx   r7   r   r   r   r=   r   r   r}   r   r   r   r   r   r   r   r   r   rU   rY   rl   r   r   r{   r`   rd   r|   rg   r   r~   r9   r6   r   r   u  sg   $;$0H 0v1F 0	0( 	0t 	0$h $4 $@H @ @,x ,D ,Gt G
	d 		t 	2"*8I#6 *4 * $& $H $ $d Cx CD C
"
*48 4 4D 4V 4l-x -F - -.J1 J18 J128J1XH  r9   r   c                       e Zd ZdZy)SSHClientStreamSessionz!SSH client stream session handlerNru   rv   rw   rx   r~   r9   r6   r	  r	    s    +r9   r	  c            
            e Zd ZdZ	 	 ddedef fdZdefdZde	fdZ
d	ede	fd
Zdede	fdZddZdeddfdZdede	fdZdeddfdZddZdededededdf
dZ xZS )SSHServerStreamSessionz!SSH server stream session handlerNsession_factorysftp_factoryc                 t    t         |           || _        || _        || _        |xr t        |      | _        y r/   )superr7   _session_factory_sftp_factory_sftp_versionr}   
_allow_scp)r5   r  r  sftp_version	allow_scp	__class__s        r6   r7   zSSHServerStreamSession.__init__  s9     	 /))#:\(:r9   r:   c                     | j                   J | j                   j                  d       d| _        | j                  J | j                  t	        d| j                               S )z0Initialize an SFTP server for this stream to useNr'   )r2   set_encodingr   r  r   rC   s    r6   _init_sftp_serverz(SSHServerStreamSession._init_sftp_server  s\     zz%%%

%!!---!!$':DJJ"GHHr9   c                 ,    t        | j                        S )z'Return whether a shell can be requested)r}   r  rC   s    r6   shell_requestedz&SSHServerStreamSession.shell_requested  s     D))**r9   commandc                 n    | j                   xr |j                  d      xs t        | j                        S )z6Return whether execution of a command can be requestedscp )r  
startswithr}   r  )r5   r  s     r6   exec_requestedz%SSHServerStreamSession.exec_requested  s3     ?W%7%7%? ,T**+	-r9   	subsystemc                 `    |dk(  rt        | j                        S t        | j                        S )z4Return whether starting a subsystem can be requestedsftp)r}   r  r  )r5   r"  s     r6   subsystem_requestedz*SSHServerStreamSession.subsystem_requested  s.     **++--..r9   c                    | j                   J | j                   j                         }t        t           | | j                         }t	        t           | | j                         }t	        t           | | j                   t
              }| j                   j                         dk(  rUt        t        t           |      }t        t        t           |      }t        | j                         ||| j                        }n| j                  rv|rt|j                  d      rct        t        t           |      }t        t        t           |      }t        t        t           |      }t        | j                         ||||      }n!| j                  J | j                  |||      }t!        j"                  |      r9| j$                  J |J | j$                  j'                  ||j(                         yy)z4Start a session for this newly opened server channelNr$  r  )r2   get_commandr%   r   r&   r   get_subsystemr   r   r!   r  r  r  r   r"   r  inspectisawaitabler   create_taskrI   )	r5   r  stdinstdoutstderrstdin_bytesstdout_byteshandlerstderr_bytess	            r6   session_startedz&SSHServerStreamSession.session_started  s    zz%%%**((*&!$

36"446"45IJ ::##%/y/7K	% 0&9L%d&<&<&>&1<&*&8&8:G __W-?-?-Gy/7K	% 0&9L	% 0&9L$T%;%;%=w%0,NG ((444++E66BGw'::)))&&&JJ""7ELL9 (r9   r   c                 b    | j                   d   j                  |       | j                  d       y)z+Handle an incoming exception on the channelN)r   r   r   )r5   r   s     r6   exception_receivedz)SSHServerStreamSession.exception_received	  s)     	t##C(4 r9   msecc                 8    | j                  t        |             y)z'Handle an incoming break on the channelT)r5  r   )r5   r6  s     r6   break_receivedz%SSHServerStreamSession.break_received  s     	d 34r9   signalc                 8    | j                  t        |             y)z(Handle an incoming signal on the channelN)r5  r   )r5   r9  s     r6   signal_receivedz&SSHServerStreamSession.signal_received  s     	v 67r9   c                 6    | j                  t                      y)z*Handle an incoming soft EOF on the channelN)r5  r   rC   s    r6   soft_eof_receivedz(SSHServerStreamSession.soft_eof_received  s     	 12r9   widthheightpixwidth	pixheightc                 >    | j                  t        ||||             y)z6Handle an incoming terminal size change on the channelN)r5  r   )r5   r>  r?  r@  rA  s        r6   terminal_size_changedz,SSHServerStreamSession.terminal_size_changed  s%     	 3E64<i!I 	Jr9   )Nr   Frr   )ru   rv   rw   rx   _OptServerSessionFactory_OptSFTPServerFactoryr7   r    r  r}   r  rz   r!  r%  r3  r   r5  r{   r8  r;  r=  rC  __classcell__r  s   @r6   r  r    s    + 8</4;(@ ;4;	I: 	I+ +
-c -d -/S /T /":H!i !D !3 4 8c 8d 8
3
J3 J J(+J8;J@DJr9   r  c                   2     e Zd ZdZddef fdZddZ xZS )SSHSocketStreamSessionzSocket stream session handlerr  c                 0    t         |           || _        y r/   )r  r7   r  )r5   r  r  s     r6   r7   zSSHSocketStreamSession.__init__*  s     /r9   c                 n   | j                   r| j                  J t        t           | | j                        }t	        t           | | j                        }| j                  ||      }t        j                  |      r9| j                  J |J | j                  j                  ||j                         yyy)z4Start a session for this newly opened socket channelN)
r  r2   r%   r   r&   r)  r*  r   r+  rI   )r5   readerwriterr1  s       r6   r3  z&SSHSocketStreamSession.session_started/  s       ::)))v&tTZZ8Fv&tTZZ8F++FF;G""7+zz---***

&&w> , !r9   r/   rr   )ru   rv   rw   rx   _OptSocketSessionFactoryr7   r3  rF  rG  s   @r6   rI  rI  '  s    '0(@ 0
?r9   rI  c                       e Zd ZdZy)SSHTCPStreamSessionzTCP stream session handlerNr
  r~   r9   r6   rP  rP  ?  s    $r9   rP  c                       e Zd ZdZy)SSHUNIXStreamSessionzUNIX stream session handlerNr
  r~   r9   r6   rR  rR  D  s    %r9   rR  c            	       D    e Zd ZdZdedee   fdZ	 	 d	dedede	defdZ
y)
SSHTunTapStreamSessionzTUN/TAP stream session handlerr-   r:   c                V   K   	 | j                  |       d{   }|r| ny#7 wr<   )r`   )r5   r-   packets      r6   r=   zSSHTunTapStreamSession.aiterK  s/      99X..F .s   )')r[   r^   c                 4  K   | j                   |   }| j                  sw|rOt        t        |j	                  d            }| xj
                  t        |      z  c_        | j                          |S | j                  |       d{    | j                  swy7 w)z3Override read to preserve TUN/TAP packet boundariesr   Nr9   )	r   r   r   r   r   r   r   r   r   )r5   r-   r[   r^   r   rS   s         r6   r`   zSSHTunTapStreamSession.readV  s      >>(+$$E8<<?3""c$i/"**,&&x000 $$  1s   BBBBBN)rs   F)ru   rv   rw   rx   r   r   r   r=   r{   r}   r`   r~   r9   r6   rT  rT  H  sH    (	H 	u1E 	 79!&8  +0r9   rT  )Irx   r   r)  r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   	constantsr   loggingr   miscr   r   r   r   r   r)   r   r   r   r   r   r   r$  r    r!   scpr"   rD   r#   
connectionr$   Future_WaiterFuturer   _RecvBuf_RecvBufMapr   
_ReadLocks_ReadWaiters_DrainWaitersSSHSocketSessionFactoryrN  SSHServerSessionFactoryrD  SFTPServerFactoryrE  r|   r   r%   r&   r   r	  r  rI  rP  rR  r   rT  r~   r9   r6   <module>rh     s  *    	 < < : : = = +  ; ; 6 A A D D -  #) NN4(MNNMfi'()8Xf--.(GLL()
Hh}556Xs=112"K#=$.t$4$5 6 #$;< " $12<T2B$C D #$;< 12J>?  !23  8v- v-rq- q-hywv yx	,-f5-f5,
nJ-f5-f5nJb?-f5 ?0%08'/%
&1&9)&1&3E:<L r9   