HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/channel.cpython-312.pyc
�

Ϫ�f�&���dZddlmZddlmZddlmZddlmZeej�Gd�dej��Z
y)	z�
The parent class for all the SSH Channels.  Currently implemented channels
are session, direct-tcp, and forwarded-tcp.

Maintainer: Paul Swartz
�)�implementer)�
interfaces)�Logger)�logc���eZdZUdZe�ZdZeed<							dd�Z	de
fd�Zdefd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�
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}
    N�namec��|xsd|_|j|_|xsd|_||_||_d|_||_||_||_d|_	d|_
g|_d|_d|_
d|_d|_y)Nii���r)�localWindowSize�localWindowLeft�localMaxPacket�remoteWindowLeft�remoteMaxPacket�
areWriting�conn�data�avatar�specificData�buf�extBuf�closing�localClosed�remoteClosed�id)�self�localWindowr�remoteWindowrrrrs        �;/usr/lib/python3/dist-packages/twisted/conch/ssh/channel.py�__init__zSSHChannel.__init__9s��� +�4�f���#�3�3���,�5���� ,���.��������	���	������������������������r�returnc�@�|j�jd�S)N�ascii)�	__bytes__�decode�rs r �__str__zSSHChannel.__str__Ts���~�~��&�&�w�/�/rc�Z�|j}|sd}d||j|jfzS)zD
        Return a byte string representation of the channel
        sNones<SSHChannel %b (lw %d rw %d)>)r	rr)rr	s  r r%zSSHChannel.__bytes__Ws<���y�y����D�/��� � ��!�!�3
�
�	
rc���|jduxrt|j�xsd}|jr|jjd�}nd}d|�d|�d|jj���S)N�unknownr$�NonezSSHChannel z (z) on )r�strr	r&r�	logPrefix)rrr	s   r r.zSSHChannel.logPrefixesi���g�g�T�!�2�c�$�'�'�l�
@�y���9�9��9�9�#�#�G�,�D��D��T�F�"�R�D��d�i�i�.A�.A�.C�-D�E�Erc�:�|jjd�y)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��_log�info)rrs  r �channelOpenzSSHChannel.channelOpenms��	
�	�	���~�&rc�>�|jjd|��y)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: {reason})�reasonN)r1�error)rr5s  r �
openFailedzSSHChannel.openFailedvs��	
�	�	���C�F��Src�b�|j|z|_|js#|jsd|_|j�|jr$|j}d|_|j|�|jr0|j}g|_|D]\}}|j||��yy)z�
        Called when bytes are added to the remote window.  By default it clears
        the data buffers.

        @type data:    L{bytes}
        TrN)rrr�startWritingr�writer�
writeExtended)rr�b�types    r �addWindowByteszSSHChannel.addWindowBytess���!%� 5� 5�� <������t�|�|�"�D�O������8�8����A��D�H��J�J�q�M��;�;����A��D�K��
/�
��d��"�"�4��.�
/�rc��|jdd�jd�}t|d|zd�}|r||�S|jj	d|��y)	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}
        �-�_r$�request_Nz#unhandled request for {requestType})�requestTyper)�replacer&�getattrr1r2)rrCr�foo�fs     r �requestReceivedzSSHChannel.requestReceived�sX���!�!�$��-�4�4�W�=���D�*�s�*�D�1����T�7�N��	�	���<�+��V�rc�>�|jjd|��y)zL
        Called when we receive data.

        @type data: L{bytes}
        zgot data {data})rN�r1�debug�rrs  r �dataReceivedzSSHChannel.dataReceived�s��	
�	�	���)���5rc�@�|jjd||��y)z�
        Called when we receive extended data (usually standard error).

        @type dataType: L{int}
        @type data:     L{str}
        z%got extended data {dataType} {data!r})�dataTyperNrJ�rrOrs   r �extReceivedzSSHChannel.extReceived�s ��	
�	�	���3�h�T�	�	
rc�:�|jjd�y)zD
        Called when the other side will send no more data.
        z
remote eofNr0r's r �eofReceivedzSSHChannel.eofReceived�s��	
�	�	���|�$rc�Z�|jjd�|j�y)zD
        Called when the other side has closed the channel.
        zremote closeN)r1r2�loseConnectionr's r �
closeReceivedzSSHChannel.closeReceived�s ��	
�	�	���~�&����rc�:�|jjd�y)z�
        Called when the channel is closed.  This means that both our side and
        the remote side have closed the channel.
        �closedNr0r's r rXzSSHChannel.closed�s��
	
�	�	���x� rc��|jr|xj|z
c_yt|�}||jkDrG|d|j||jdc}|_d|_|j	�|j}|j
}|jj}td||�}|D]}||||||z��|xj|zc_|jr|js|j�yyy)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�stopWritingrr�sendData�rangerrU)rr�top�rmpr:�r�offsets       r r:zSSHChannel.write�s����8�8��H�H���H���$�i����&�&�&��,�t�,�,�-��T�*�*�,�-�
�D�$�(� �D�O������'�'�C��"�"���	�	�"�"���!�S�#����	5�F��$��V�f�s�l�3�4�	5�����$���<�<�������!�!)�<rc�*�|jrN|jdd|k(r|jddxx|z
cc<y|jj||g�yt|�|jkDr>|d|j|||jdggc}|_d|_|j�t|�|jkDrq|jj|||d|j�||jd}|xj|jzc_t|�|jkDr�q|r;|jj|||�|xjt|�zc_|jr|j�yy)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}
        ���rrN)r�appendrZrrr[rr�sendExtendedDatarrUrPs   r r;zSSHChannel.writeExtended�sq���;�;��{�{�2��q�!�X�-����B���"�d�*�"�
����"�"�H�d�#3�4���t�9�t�,�,�,��,�t�,�,�-��D��!6�!6�!8�9�:�;�
�D�$�+� �D�O������$�i�$�.�.�.��I�I�&�&�t�X�t�<R�d�>R�>R�7S�T���,�,�.�/�D��!�!�T�%9�%9�9�!��$�i�$�.�.�.���I�I�&�&�t�X�t�<��!�!�S��Y�.�!��<�<����!�rc�D�|jdj|��y)z�
        Part of the Transport interface.  Write a list of strings to the
        channel.

        @type data: C{list} of L{str}
        rN)r:�joinrLs  r �
writeSequencezSSHChannel.writeSequence
s��	
�
�
�3�8�8�D�>�"rc�|�d|_|js)|js|jj	|�yyy)zr
        Close the channel if there is no buferred data.  Otherwise, note the
        request and return.
        rN)rrrr�	sendCloser's r rUzSSHChannel.loseConnections1��
����x�x�����I�I����%�!,�xrc�J�|jjj�S)z�
        See: L{ITransport.getPeer}

        @return: The remote address of this connection.
        @rtype: L{SSHTransportAddress}.
        )r�	transport�getPeerr's r rmzSSHChannel.getPeer����y�y�"�"�*�*�,�,rc�J�|jjj�S)z�
        See: L{ITransport.getHost}

        @return: An address describing this side of the connection.
        @rtype: L{SSHTransportAddress}.
        )rrl�getHostr's r rpzSSHChannel.getHost%rnrc��y)z�
        Called when the remote buffer is full, as a hint to stop writing.
        This can be ignored, but it can be helpful.
        N�r's r r[zSSHChannel.stopWriting.��rc��y)ze
        Called when the remote buffer has more room, as a hint to continue
        writing.
        Nrrr's r r9zSSHChannel.startWriting4rsr)rrrrNNN)�__name__�
__module__�__qualname__�__doc__rr1r	�bytes�__annotations__r!r-r(r%r.r3r7r>rHrMrQrSrVrXr:r;rhrUrmrpr[r9rrrr rrs����@�8�D��D�%������
�
���60��0�
�5�
�F�'�T�/�*�$6�	
�%��!�"�:"�@#�&�-�-��rrN)rx�zope.interfacer�twisted.internetr�twisted.loggerr�twisted.pythonr�
ITransportrrrrr �<module>r�sE��
�'�'�!��
�Z�
"�
"�#�c����c�$�cr