HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/__pycache__/stream.cpython-310.pyc
o

�hw�@s�dZddlZddlZddlZddlmZmZmZmZddlm	Z	m
Z
mZmZm
Z
ddlmZmZmZmZmZmZddlmZddlmZdd	lmZmZmZdd
lmZmZddlmZm Z m!Z!ddlm"Z"m#Z#m$Z$dd
l%m&Z&m'Z'ddl(m)Z)er�ddl*m+Z+ddl,m-Z-er�ej.dZ/nej.Z/e
eee0fZ1e
ee1efZ2e
eej3fZ4e
eee/fZ5e
eee/fZ6e	ddgedfZ7ee7Z8e	gd�edfZ9ee9Z:e	dgee&fZ;ee;Z<e=�Z>Gdd�dee�Z?Gdd�dee�Z@Gdd�dee�ZAGdd�deAee e�ZBGdd�deAee!e�ZCGdd�deAe�ZDGdd �d eDee"e�ZEGd!d"�d"eDee#e�ZFGd#d$�d$eDeGe$�ZHdS)%zSSH 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@s�eZdZdZ	d*dddddefdd	�Zd
eefdd�Ze	d+d
d��Z
e	d
efdd��Zd*de
ded
efdd�Zded
dfdd�Zd,dd�Zd-ded
efdd�Zd
efdd�Z	 d.d!ed
efd"d#�Zded
efd$d%�Zd
efd&d'�Zd
edeffd(d)�ZdS)/r$zSSH read stream handlerN�session�SSHStreamSession[AnyStr]�chan�SSHChannel[AnyStr]�datatypecC�||_||_||_dS�N��_session�_chan�	_datatype��selfr'r)r+�r4�B/usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/stream.py�__init__K�
zSSHReader.__init__�returncCs*�|j�|j�2z	3dHW}|Vq6dS��'Allow SSHReader to be an async iteratorN)r/�aiterr1)r3�resultr4r4r5�	__aiter__Qs��zSSHReader.__aiter__cC�|jS�z+The SSH channel associated with this stream�r0�r3r4r4r5�channelW�zSSHReader.channelcC�|jjS�z*The SSH logger associated with this stream�r0�loggerrAr4r4r5rG]�zSSHReader.logger�name�defaultcC�|j�||�S�a3Return 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.

        �r0�get_extra_info�r3rIrJr4r4r5rNc�
zSSHReader.get_extra_info�datacCs|j�||j�dS)aNFeed 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)r/�
data_receivedr1�r3rQr4r4r5�	feed_dataoszSSHReader.feed_datacCs|j��dS)aaFeed 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)r/�eof_receivedrAr4r4r5�feed_eof|szSSHReader.feed_eof����nc���|jj|j|dd�IdHS)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�r/�readr1�r3rXr4r4r5r]�s�zSSHReader.readc�s�|j�|j�IdHS)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)r/�readliner1rAr4r4r5r_�s�zSSHReader.readliner�	separatorc�s�|j�||j|�IdHS)aRead 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)r/�	readuntilr1)r3r`�max_separator_lenr4r4r5ra�s�(
�zSSHReader.readuntilc�rY)aRead 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.

        TrZNr\r^r4r4r5�readexactly�s�zSSHReader.readexactlycCs|j�|j�S)z�Return whether the stream is at EOF

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

        )r/�at_eofr1rAr4r4r5rd�szSSHReader.at_eofcC�|j|jfS)z6Get information needed to redirect from this SSHReader�r/r1rAr4r4r5�get_redirect_info��zSSHReader.get_redirect_infor-�r8r*�r8N)rW�r)�__name__�
__module__�__qualname__�__doc__rr6rrr=�propertyrBrrG�strrrNrTrV�intr]r_�objectrarc�boolrdrrgr4r4r4r5r$Hs2��
�


�
�+
c@s�eZdZdZ	d'dddddefdd	�Zed(dd��Zed
efd
d��Z	d'de
ded
efdd�Zd
e
fdd�Zd)dd�Zd
e
fdd�Zd)dd�Zd)dd�Zded
dfdd�Zd eed
dfd!d"�Zd)d#d$�Zd
edeffd%d&�ZdS)*r%zSSH write stream handlerNr'r(r)r*r+cCr,r-r.r2r4r4r5r6r7zSSHWriter.__init__r8cCr>r?r@rAr4r4r5rB
rCzSSHWriter.channelcCrDrErFrAr4r4r5rGrHzSSHWriter.loggerrIrJcCrKrLrMrOr4r4r5rNrPzSSHWriter.get_extra_infocC�
|j��S)z4Return whether the stream supports :meth:`write_eof`)r0�
can_write_eofrAr4r4r5rv"�
zSSHWriter.can_write_eofcCru)z�Close the channel

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

        )r0�closerAr4r4r5rx's
zSSHWriter.closecCru)z,Return if the stream is closing or is closed)r0�
is_closingrAr4r4r5ry1rwzSSHWriter.is_closingc�s�|j��IdHdS)z�Wait until the stream is closed

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

        N)r0�wait_closedrAr4r4r5rz6s�zSSHWriter.wait_closedc�s�|j�|j�IdHdS)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)r/�drainr1rAr4r4r5r{@s�zSSHWriter.drainrQcC�|j�||j�S)atWrite 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.

        )r0�writer1rSr4r4r5r}MszSSHWriter.write�list_of_datacCr|)z(Write a collection of data to the stream)r0�
writelinesr1)r3r~r4r4r5r[�zSSHWriter.writelinescCru)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.

        )r0�	write_eofrAr4r4r5r�`s

zSSHWriter.write_eofcCre)z4Get information needed to redirect to this SSHWriterrfrAr4r4r5rgorhzSSHWriter.get_redirect_infor-rirj)rlrmrnrorr6rprBrrGrqrrNrtrvrxryrzr{rr}r	rr�rrgr4r4r4r5r%s,��
�






c@sdeZdZdZd5dd�Zdedeefdd�Zdeddfd	d
�Z	deddfdd�Z
dedefd
d�Zdeddfdd�Z
defdd�Zdefdd�Zdefdd�Zd6dd�Zdeeddfdd�Zdededdfdd �Zdefd!d"�Zdedefd#d$�Zd5d%d&�Zd5d'd(�Zded)ed*edefd+d,�Zdedefd-d.�Z	/d7d0ededefd1d2�Zdeddfd3d4�ZdS)8�SSHStreamSessionzSSH stream session handlerr8NcCszd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
d|_dgi|_dt
��i|_ddi|_dt�i|_dS)N�strictrF)r0�_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_waitersrAr4r4r5r6xs 

zSSHStreamSession.__init__r+cCs0�|�|�s|�|�IdHV|�|�rdSdSr9)rdr_�r3r+r4r4r5r;�s�
�zSSHStreamSession.aiterc	�sL�z|jdus	J�|j��}||j|<|IdHWd|j|<dSd|j|<w)z*Wait for more data to arrive on the streamN)r��
create_futurer��r3r+�waiterr4r4r5�_block_read�s�

zSSHStreamSession._block_readcCs,|j|}|r|��s|�d�dSdSdS)z/Signal that more data has arrived on the streamN)r��done�
set_resultr�r4r4r5�
_unblock_read�s
�zSSHStreamSession._unblock_readcCs|jo|jS)z;Return whether output is still being written to the channel)r�r�r�r4r4r5�_should_block_drain�sz$SSHStreamSession._should_block_draincCs4|�|�s|j|D]
}|��s|�d�q
dSdS)z2Signal that more data can be written on the streamN)r�r�r�r�r�r4r4r5�_unblock_drain�s

��zSSHStreamSession._unblock_draincCst|j�o
|j|jkS)z0Return whether to pause reading from the channel)rtr�r�rAr4r4r5�_should_pause_reading�sz&SSHStreamSession._should_pause_readingcCs4|js|��r|jdusJ�d|_|j��dSdS)zPause reading if necessaryNTF)r�r�r0�
pause_readingrAr4r4r5�_maybe_pause_reading��
z%SSHStreamSession._maybe_pause_readingcCs4|jr|��s|jdusJ�d|_|j��dSdS)zResume reading if necessaryNFT)r�r�r0�resume_readingrAr4r4r5�_maybe_resume_reading�r�z&SSHStreamSession._maybe_resume_readingr)r*cCs�||_|��|_|��\|_|_|��|_|j��|_	|�
�D]}g|j|<t�
�|j|<d|j|<q|��D]}t�|j|<q7dS)zHandle a newly opened channelN)r0�get_connectionr��get_encodingr�r��get_loopr��get_recv_windowr��get_read_datatypesr�r�r�r�r��get_write_datatypesr�r�)r3r)r+r4r4r5�connection_made�s


�z SSHStreamSession.connection_made�exccCsTd|_||_|js|r|jD]
}|j|�|�q|��|jD]}|�|�q dS)z Handle an incoming channel closeTN)	r�r�r�r�r��appendrUr�r�)r3r�r+r4r4r5�connection_lost�s

�z SSHStreamSession.connection_lostrQcCs8|j|�|�|jt|�7_|�|�|��dS)z#Handle incoming data on the channelN)r�r�r��lenr�r�)r3rQr+r4r4r5rR�s
zSSHStreamSession.data_receivedcCs d|_|jD]}|�|�qdS)z-Handle an incoming end of file on the channelT)r�r�r�r�r4r4r5rU�s
zSSHStreamSession.eof_receivedcCs|jo|j|S)z;Return whether end of file has been received on the channel)r�r�r�r4r4r5rd��zSSHStreamSession.at_eofcCs
d|_dS)z0Handle a request to pause writing on the channelTN)r�rAr4r4r5�
pause_writingrwzSSHStreamSession.pause_writingcCs d|_|jD]}|�|�qdS)z1Handle a request to resume writing on the channelFN)r�r�r�r�r4r4r5�resume_writing	s
�zSSHStreamSession.resume_writingrXr[c
	�s��|j|}g}d}|j|4IdH��	|r�|dkr�t|dt�r9|r'd}n_tt|�d��}t|t�r7d}nO|�t|d�}||krIdkrjnn|�|dd|��|d|d�|d<|j	|8_	d}n|�tt
|�d���|j	|8_	||8}|r�|dks|��r�q|dks�|dkr�|r�|r�|dkr�|s�|js�|r�n	|�
|�IdHqWd�IdHn1IdHs�wYtt
|jr�dnd��|�}	|dkr�|r�t�tt|	�t|	�|��|	S)zRead data from the channelFNTr��)r�r��
isinstance�	Exceptionr�poprr�r�r�rr�r�r�r��joinr��IncompleteReadError�bytes)
r3r+rXr[�recv_bufrQ�
break_readr��lr<r4r4r5r]sZ�

����(�'
�zSSHStreamSession.readc
�sJ�z
|�t|�IdHWStjy$}ztt|j�WYd}~Sd}~ww)zRead one line from the streamN)ra�_NEWLINEr�r�rr�partial)r3r+r�r4r4r5r_Gs���zSSHStreamSession.readlinerr`c	�s��|std��tt|jrdnd�}|j|}|tur,d}tt|jr#dnd�}t�|�}nQt|t	t
f�rCt|�}t�t�tt|���}n:t|t
�rR|}tt
t|�}n+tt|jrYdnd�}	tttt|��}
td	d
�|
D��}|	�dd
�|
D��}t�|�}d}d}|j|4Id
H��	|t|�k�r9t||t�r�|r�g|d
|�<|j|8_t�tt	|�d
��|�d�}
t|
t�r�|Wd
�Id
HStt|
��tt||�}||7}|dkr�dnt|d|d�}|�||�}|�r)|��}g|d
|�<||d
�|d<|d
|�}|j|8_|d�s|�d�|��|Wd
�Id
HS|t|�7}|d7}|t|�ks�|j�sA|j�r[g|d
|�<|j|8_|��t�tt	|�d
��|�|�Id
Hq�1Id
H�skwYd
S)z4Read data from the channel until a separator is seenzSeparator cannot be emptyr�r�r�
�
�|�|css�|]}t|�VqdSr-)r���.0�sepr4r4r5�	<genexpr>fs�z-SSHStreamSession.readuntil.<locals>.<genexpr>css�|]}t�|�VqdSr-)�re�escaper�r4r4r5r�gs�rN)�
ValueErrorrrr�r�r�r��compiler�r�rqr�r�r�listr	�maxr�r�r�r�r�r�r�r�search�endr�r�r�r�)r3r`r+rb�bufr��seplen�
separators�pat�bar�seplist�curbuf�buflenr��newbuf�start�match�idxr4r4r5raOs~�



�

�


�#�$��zSSHStreamSession.readuntilc	�s��|�|�r8z#|jdusJ�|j��}|j|�|�|IdHW|j|�|�n	|j|�|�w|�|�s|jrJ|j}|sF|jrFt	�}|rL|�dSdS)z-Wait for data written to the channel to drainN)
r�r�r�r��add�remover�r�r��BrokenPipeError)r3r+r�r�r4r4r5r{�s"�

$
�	
�zSSHStreamSession.drainrj)r)r*r8Nrk) rlrmrnror6rrrr;r�r�rtr�r�r�r�r�r�rr�r�rRrUrdr�r�rrr]r_rsrar{r4r4r4r5r�us2




6	�
�Lr�c@�eZdZdZdS)�SSHClientStreamSessionz!SSH client stream session handlerN�rlrmrnror4r4r4r5r���r�c
s�eZdZdZ		d'dedef�fdd�
Zd	eefd
d�Z	d	e
fdd
�Zded	e
fdd�Z
ded	e
fdd�Zd(dd�Zded	dfdd�Zded	e
fdd�Zded	dfdd�Zd(dd �Zd!ed"ed#ed$ed	df
d%d&�Z�ZS))�SSHServerStreamSessionz!SSH server stream session handlerNrF�session_factory�sftp_factorycs.t���||_||_||_|ot|�|_dSr-)�superr6�_session_factory�
_sftp_factory�
_sftp_versionrt�
_allow_scp)r3r�r��sftp_version�	allow_scp��	__class__r4r5r6�s

zSSHServerStreamSession.__init__r8cCs@|jdusJ�|j�d�d|_|jdusJ�|�td|j��S)z0Initialize an SFTP server for this stream to useNr&)r0�set_encodingr�r�rrAr4r4r5�_init_sftp_server�s
z(SSHServerStreamSession._init_sftp_servercCs
t|j�S)z'Return whether a shell can be requested)rtr�rAr4r4r5�shell_requested�rwz&SSHServerStreamSession.shell_requested�commandcCs|jr|�d�pt|j�S)z6Return whether execution of a command can be requested�scp )r��
startswithrtr�)r3r�r4r4r5�exec_requested�s�z%SSHServerStreamSession.exec_requested�	subsystemcCs|dkr	t|j�St|j�S)z4Return whether starting a subsystem can be requested�sftp)rtr�r�)r3r�r4r4r5�subsystem_requested�s

z*SSHServerStreamSession.subsystem_requestedc	Cs*|jdusJ�|j��}tt||j�}tt||j�}tt||jt�}|j��dkrEttt|�}ttt|�}t	|�
�|||j�}n8|jro|ro|�
d�rottt|�}ttt|�}ttt|�}t|�
�||||�}n|jdusvJ�|�|||�}t�|�r�|jdus�J�|j�||j�dSdS)z4Start a session for this newly opened server channelNr�r�)r0�get_commandr$rr%r�
get_subsystemrr�r r�r�r�r�r!r��inspect�isawaitabler��create_taskrG)	r3r��stdin�stdout�stderr�stdin_bytes�stdout_bytes�handler�stderr_bytesr4r4r5�session_started�s2
�
�
�z&SSHServerStreamSession.session_startedr�cCs|jd�|�|�d�dS)z+Handle an incoming exception on the channelN)r�r�r�)r3r�r4r4r5�exception_receivedsz)SSHServerStreamSession.exception_received�mseccC�|�t|��dS)z'Handle an incoming break on the channelT)rr)r3rr4r4r5�break_receivedsz%SSHServerStreamSession.break_received�signalcCr	)z(Handle an incoming signal on the channelN)rr)r3rr4r4r5�signal_receivedr�z&SSHServerStreamSession.signal_receivedcCs|�t��dS)z*Handle an incoming soft EOF on the channelN)rrrAr4r4r5�soft_eof_receivedr�z(SSHServerStreamSession.soft_eof_received�width�height�pixwidth�	pixheightcCs|�t||||��dS)z6Handle an incoming terminal size change on the channelN)rr)r3rrrrr4r4r5�terminal_size_changeds

�z,SSHServerStreamSession.terminal_size_changed)NrFrj)rlrmrnro�_OptServerSessionFactory�_OptSFTPServerFactoryr6rrr�rtr�rqr�r�rr�rrrr
rr
r�
__classcell__r4r4r�r5r��s.��
	
#

���r�cs2eZdZdZd	def�fdd�
Zd
dd�Z�ZS)�SSHSocketStreamSessionzSocket stream session handlerNr�cst���||_dSr-)r�r6r�)r3r�r�r4r5r6)s

zSSHSocketStreamSession.__init__r8cCst|jr6|jdus
J�tt||j�}tt||j�}|�||�}t�|�r8|jdus,J�|j�||j	�dSdSdS)z4Start a session for this newly opened socket channelN)
r�r0r$rr%r�r�r�r�rG)r3�reader�writerrr4r4r5r.s
�z&SSHSocketStreamSession.session_startedr-rj)rlrmrnro�_OptSocketSessionFactoryr6rrr4r4r�r5r&src@r�)�SSHTCPStreamSessionzTCP stream session handlerNr�r4r4r4r5r=r�rc@r�)�SSHUNIXStreamSessionzUNIX stream session handlerNr�r4r4r4r5rBr�rc	@sFeZdZdZdedeefdd�Z		d
deded	e	defd
d�Z
dS)�SSHTunTapStreamSessionzTUN/TAP stream session handlerr+r8cCs&�	|�|�IdH}|r|VndSq)r:TN)r])r3r+�packetr4r4r5r;Is��zSSHTunTapStreamSession.aiterrWFrXr[c�s^�|j|}|js-|r"tt|�d��}|jt|�8_|��|S|�|�IdH|jr	dS)z3Override read to preserve TUN/TAP packet boundariesrNr�)	r�r�rr�r�r�r�r�r�)r3r+rXr[r�rQr4r4r5r]Ts�
�	zSSHTunTapStreamSession.readN)rWF)rlrmrnrorrr�r;rrrtr]r4r4r4r5rFs���r)Iror�r�r��typingrrrrrrrr	r
rrr
rrr�	constantsr�loggingr�miscrrrrrr'rrrrrrr�rr �scpr!rBr"�
connectionr#�Future�
_WaiterFuturer��_RecvBuf�_RecvBufMapr��
_ReadLocks�_ReadWaiters�
_DrainWaiters�SSHSocketSessionFactoryr�SSHServerSessionFactoryr�SFTPServerFactoryrrsr�r$r%r�r�r�rrrr�rr4r4r4r5�<module>sr ��:t>��p��