HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/channel.cpython-38.pyc
U


W[|&�@shdZddlmZmZddlmZddlmZddlm	Z	m
Z
ddlmZeej
�Gdd�dej��Zd	S)
z�
The parent class for all the SSH Channels.  Currently implemented channels
are session, direct-tcp, and forwarded-tcp.

Maintainer: Paul Swartz
�)�division�absolute_import)�implementer)�log)�nativeString�
intToBytes)�
interfacesc@s�eZdZdZdZd.dd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)/�
SSHChannela�
    A class that represents a multiplexed channel over an SSH connection.
    The channel has a local window which is the maximum amount of data it will
    receive, and a remote which is the maximum amount of data the remote side
    will accept.  There is also a maximum packet size for any individual data
    packet going each way.

    @ivar name: the name of the channel.
    @type name: L{bytes}
    @ivar localWindowSize: the maximum size of the local window in bytes.
    @type localWindowSize: L{int}
    @ivar localWindowLeft: how many bytes are left in the local window.
    @type localWindowLeft: L{int}
    @ivar localMaxPacket: the maximum size of packet we will accept in bytes.
    @type localMaxPacket: L{int}
    @ivar remoteWindowLeft: how many bytes are left in the remote window.
    @type remoteWindowLeft: L{int}
    @ivar remoteMaxPacket: the maximum size of a packet the remote side will
        accept in bytes.
    @type remoteMaxPacket: L{int}
    @ivar conn: the connection this channel is multiplexed through.
    @type conn: L{SSHConnection}
    @ivar data: any data to send to the other side when the channel is
        requested.
    @type data: L{bytes}
    @ivar avatar: an avatar for the logged-in user (if a server channel)
    @ivar localClosed: True if we aren't accepting more data.
    @type localClosed: L{bool}
    @ivar remoteClosed: True if the other side isn't accepting more data.
    @type remoteClosed: L{bool}
    NrcCsn|pd|_|j|_|pd|_||_||_d|_||_||_||_d|_	d|_
g|_d|_d|_
d|_d|_dS)Nii���r)ZlocalWindowSize�localWindowLeft�localMaxPacket�remoteWindowLeft�remoteMaxPacket�
areWriting�conn�data�avatar�specificData�buf�extBuf�closingZlocalClosedZremoteClosed�id)�selfZlocalWindowr
ZremoteWindowrrrr�r�;/usr/lib/python3/dist-packages/twisted/conch/ssh/channel.py�__init__:s 

zSSHChannel.__init__cCst|���S)N)r�	__bytes__�rrrr�__str__OszSSHChannel.__str__cCs6|j}|sd}d|dt|j�dt|j�dS)zD
        Return a byte string representation of the channel
        sNones<SSHChannel s (lw s rw s)>)�namerrr)rr rrrrSs�����zSSHChannel.__bytes__cCs>|jdk	rt|j�pd}|j}|r*t|�}d|||j��fS)N�unknownzSSHChannel %s (%s) on %s)r�strr rr�	logPrefix)rrr rrrr#as�zSSHChannel.logPrefixcCst�d�dS)z�
        Called when the channel is opened.  specificData is any data that the
        other side sent us when opening the channel.

        @type specificData: L{bytes}
        zchannel openN�r�msg)rrrrr�channelOpenjszSSHChannel.channelOpencCst�d|�dS)z�
        Called when the open failed for some reason.
        reason.desc is a string descrption, reason.code the SSH error code.

        @type reason: L{error.ConchError}
        z"other side refused open
reason: %sNr$)r�reasonrrr�
openFailedtszSSHChannel.openFailedcCsr|j||_|js&|js&d|_|��|jrB|j}d|_|�|�|jrn|j}g|_|D]\}}|�||�qXdS)z�
        Called when bytes are added to the remote window.  By default it clears
        the data buffers.

        @type data:    L{bytes}
        TrN)rrr�startWritingr�writer�
writeExtended)rr�b�typerrr�addWindowBytes~s
zSSHChannel.addWindowBytescCs>t|�dd��}t|d|d�}|r,||�St�d|�dS)aJ
        Called when a request is sent to this channel.  By default it delegates
        to self.request_<requestType>.
        If this function returns true, the request succeeded, otherwise it
        failed.

        @type requestType:  L{bytes}
        @type data:         L{bytes}
        @rtype:             L{bool}
        �-�_z
request_%sNzunhandled request for %sr)r�replace�getattrrr%)rZrequestTyperZfoo�frrr�requestReceived�szSSHChannel.requestReceivedcCst�dt|��dS)zL
        Called when we receive data.

        @type data: L{bytes}
        zgot data %sN�rr%�repr�rrrrr�dataReceived�szSSHChannel.dataReceivedcCst�d|t|�f�dS)z�
        Called when we receive extended data (usually standard error).

        @type dataType: L{int}
        @type data:     L{str}
        zgot extended data %s %sNr5�rZdataTyperrrr�extReceived�szSSHChannel.extReceivedcCst�d�dS)zD
        Called when the other side will send no more data.
        z
remote eofNr$rrrr�eofReceived�szSSHChannel.eofReceivedcCst�d�|��dS)zD
        Called when the other side has closed the channel.
        zremote closeN)rr%�loseConnectionrrrr�
closeReceived�s
zSSHChannel.closeReceivedcCst�d�dS)z�
        Called when the channel is closed.  This means that both our side and
        the remote side have closed the channel.
        �closedNr$rrrrr>�szSSHChannel.closedcCs�|jr|j|7_dSt|�}||jkr^|d|j�||jd�}|_d|_|��|j}|j}|jj}td||�}|D]}||||||��q||j|8_|j	r�|js�|�
�dS)z�
        Write some data to the channel.  If there is not enough remote window
        available, buffer until it is.  Otherwise, split the data into
        packets of length remoteMaxPacket and send them.

        @type data: L{bytes}
        Nr)r�lenrr�stopWritingrrZsendData�rangerr<)rr�topZrmpr*�r�offsetrrrr*�s&
�zSSHChannel.writecCs|jrD|jdd|kr0|jdd|7<n|j�||g�dSt|�|jkr�|d|j�|||jd�gg}|_d|_|��t|�|jkr�|j�|||d|j��||jd�}|j|j8_q�|r�|j�|||�|jt|�8_|j	�r|�
�dS)a
        Send extended data to this channel.  If there is not enough remote
        window available, buffer until there is.  Otherwise, split the data
        into packets of length remoteMaxPacket and send them.

        @type dataType: L{int}
        @type data:     L{bytes}
        ���rr
N)r�appendr?rrr@rrZsendExtendedDatarr<r9rrrr+�s,	�
�zSSHChannel.writeExtendedcCs|�d�|��dS)z�
        Part of the Transport interface.  Write a list of strings to the
        channel.

        @type data: C{list} of L{str}
        rN)r*�joinr7rrr�
writeSequence
szSSHChannel.writeSequencecCs"d|_|js|js|j�|�dS)zr
        Close the channel if there is no buferred data.  Otherwise, note the
        request and return.
        r
N)rrrrZ	sendCloserrrrr<szSSHChannel.loseConnectioncCs|jj��S)z�
        See: L{ITransport.getPeer}

        @return: The remote address of this connection.
        @rtype: L{SSHTransportAddress}.
        )r�	transport�getPeerrrrrrJ!szSSHChannel.getPeercCs|jj��S)z�
        See: L{ITransport.getHost}

        @return: An address describing this side of the connection.
        @rtype: L{SSHTransportAddress}.
        )rrI�getHostrrrrrK+szSSHChannel.getHostcCsdS)z�
        Called when the remote buffer is full, as a hint to stop writing.
        This can be ignored, but it can be helpful.
        Nrrrrrr@5szSSHChannel.stopWritingcCsdS)ze
        Called when the remote buffer has more room, as a hint to continue
        writing.
        Nrrrrrr)<szSSHChannel.startWriting)rrrrNNN)�__name__�
__module__�__qualname__�__doc__r rrrr#r&r(r.r4r8r:r;r=r>r*r+rHr<rJrKr@r)rrrrr	s: �
	

	
 



r	N)rOZ
__future__rrZzope.interfacerZtwisted.pythonrZtwisted.python.compatrrZtwisted.internetrZ
ITransportZLoggerr	rrrr�<module>s