Ë
    ojî&  ã                   óŒ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ  eej                  «       G d„ dej                  «      «       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                   óÈ   — e Zd ZU dZ e«       ZdZeed<   	 	 	 	 	 	 	 dd„Z	de
fd„Zdefd„Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)Ú
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                 ó  — |xs d| _         | j                   | _        |xs d| _        || _        || _        d| _        || _        || _        || _        d| _	        d| _
        g | _        d| _        d| _        d| _        d | _        y )Ni   i €  é   ó    r   )ÚlocalWindowSizeÚlocalWindowLeftÚlocalMaxPacketÚremoteWindowLeftÚremoteMaxPacketÚ
areWritingÚconnÚdataÚavatarÚspecificDataÚbufÚextBufÚclosingÚlocalClosedÚremoteClosedÚid)ÚselfÚlocalWindowr   ÚremoteWindowr   r   r   r   s           ú;/usr/lib/python3/dist-packages/twisted/conch/ssh/channel.pyÚ__init__zSSHChannel.__init__9   sŒ   € ð  +Ò4¨fˆÔØ#×3Ñ3ˆÔØ,Ò5°ˆÔØ ,ˆÔØ.ˆÔØˆŒØˆŒ	ØˆŒ	ØˆŒØˆÔØˆŒØˆŒØˆŒØˆÔØˆÔØˆ�r   Úreturnc                 ó@   — | j                  «       j                  d«      S )NÚascii)Ú	__bytes__Údecode©r   s    r    Ú__str__zSSHChannel.__str__T   s   € Ø�~‰~Ó×&Ñ& wÓ/Ð/r   c                 óZ   — | j                   }|sd}d|| j                  | j                  fz  S )zD
        Return a byte string representation of the channel
        s   Nones   <SSHChannel %b (lw %d rw %d)>)r	   r   r   )r   r	   s     r    r%   zSSHChannel.__bytes__W   s<   € ð �y‰yˆÙØˆDà/ØØ× Ñ Ø×!Ñ!ð3
ñ 
ð 	
r   c                 óî   — | j                   d uxr t        | j                   «      xs d}| j                  r| j                  j                  d«      }nd}d|› d|› d| j                  j                  «       › �S )NÚunknownr$   ÚNonezSSHChannel z (z) on )r   Ústrr	   r&   r   Ú	logPrefix)r   r   r	   s      r    r.   zSSHChannel.logPrefixe   si   € Ø�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                 ó:   — | j                   j                  d«       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)r   r   s     r    ÚchannelOpenzSSHChannel.channelOpenm   s   € ð 	�	‰	�‰�~Õ&r   c                 ó>   — | j                   j                  d|¬«       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)r   r5   s     r    Ú
openFailedzSSHChannel.openFailedv   s   € ð 	�	‰	�‰ÐCÈFˆÕSr   c                 ób  — | j                   |z   | _         | j                  s#| j                  sd| _        | j                  «        | j                  r$| j                  }d| _        | j                  |«       | j                  r0| j                  }g | _        |D ]  \  }}| j                  ||«       Œ yy)z”
        Called when bytes are added to the remote window.  By default it clears
        the data buffers.

        @type data:    L{bytes}
        Tr   N)r   r   r   ÚstartWritingr   Úwriter   ÚwriteExtended)r   r   ÚbÚtypes       r    ÚaddWindowByteszSSHChannel.addWindowBytes   s˜   € ð !%× 5Ñ 5¸Ñ <ˆÔØ�Š t§|¢|Ø"ˆDŒOØ×ÑÔØ�8Š8Ø—‘ˆAØˆDŒHØ�J‰J�qŒMØ�;Š;Ø—‘ˆAØˆDŒKØò /‘
��dØ×"Ñ" 4¨Õ.ñ/ð r   c                 ó´   — |j                  dd«      j                  d«      }t        | d|z   d«      }|r ||«      S | j                  j	                  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&   Úgetattrr1   r2   )r   rC   r   ÚfooÚfs        r    ÚrequestReceivedzSSHChannel.requestReceived”   sX   € ð ×!Ñ! $¨Ó-×4Ñ4°WÓ=ˆÜ�D˜* sÑ*¨DÓ1ˆÙÙ�T“7ˆNØ�	‰	�‰Ð<È+ˆÔVØr   c                 ó>   — | j                   j                  d|¬«       y)zL
        Called when we receive data.

        @type data: L{bytes}
        zgot data {data})r   N©r1   Údebug©r   r   s     r    ÚdataReceivedzSSHChannel.dataReceived¦   s   € ð 	�	‰	�‰Ð)°ˆÕ5r   c                 ó@   — | j                   j                  d||¬«       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})ÚdataTyper   NrJ   ©r   rO   r   s      r    ÚextReceivedzSSHChannel.extReceived®   s    € ð 	�	‰	�‰Ø3¸hÈTð 	õ 	
r   c                 ó:   — | j                   j                  d«       y)zD
        Called when the other side will send no more data.
        z
remote eofNr0   r'   s    r    ÚeofReceivedzSSHChannel.eofReceived¹   s   € ð 	�	‰	�‰�|Õ$r   c                 óZ   — | j                   j                  d«       | j                  «        y)zD
        Called when the other side has closed the channel.
        zremote closeN)r1   r2   ÚloseConnectionr'   s    r    ÚcloseReceivedzSSHChannel.closeReceived¿   s    € ð 	�	‰	�‰�~Ô&Ø×ÑÕr   c                 ó:   — | j                   j                  d«       y)zˆ
        Called when the channel is closed.  This means that both our side and
        the remote side have closed the channel.
        ÚclosedNr0   r'   s    r    rX   zSSHChannel.closedÆ   s   € ð
 	�	‰	�‰�xÕ r   c                 ó  — | j                   r| xj                   |z  c_         yt        |«      }|| j                  kD  rG|d| j                   || j                  d c}| _         d| _        | j	                  «        | j                  }| j
                  }| j                  j                  }t        d||«      }|D ]  } || ||||z    «       Œ | xj                  |z  c_        | j                  r| j                   s| j                  «        yyy)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   Úlenr   r   ÚstopWritingr   r   ÚsendDataÚranger   rU   )r   r   ÚtopÚrmpr:   ÚrÚoffsets          r    r:   zSSHChannel.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                 ó*  — | j                   rN| j                   d   d   |k(  r| j                   d   dxx   |z  cc<   y| j                   j                  ||g«       yt        |«      | j                  kD  r>|d| j                   ||| j                  d ggc}| _         d| _        | j                  «        t        |«      | j                  kD  rq| j                  j                  | ||d| j                   «       || j                  d }| xj                  | j                  z  c_        t        |«      | j                  kD  rŒq|r;| j                  j                  | ||«       | xj                  t        |«      z  c_        | j                  r| j                  «        yy)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}
        éÿÿÿÿr   r   N)r   ÚappendrZ   r   r   r[   r   r   ÚsendExtendedDatar   rU   rP   s      r    r;   zSSHChannel.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   — | j                  dj                  |«      «       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:   ÚjoinrL   s     r    ÚwriteSequencezSSHChannel.writeSequence
  s   € ð 	�
‰
�3—8‘8˜D“>Õ"r   c                 ó|   — d| _         | j                  s)| j                  s| j                  j	                  | «       yyy)zr
        Close the channel if there is no buferred data.  Otherwise, note the
        request and return.
        r   N)r   r   r   r   Ú	sendCloser'   s    r    rU   zSSHChannel.loseConnection  s1   € ð
 ˆŒØ�xŠx §¢Ø�I‰I×Ñ Õ%ð !,ˆxr   c                 óJ   — | j                   j                  j                  «       S )z�
        See: L{ITransport.getPeer}

        @return: The remote address of this connection.
        @rtype: L{SSHTransportAddress}.
        )r   Ú	transportÚgetPeerr'   s    r    rm   zSSHChannel.getPeer  ó   € ð �y‰y×"Ñ"×*Ñ*Ó,Ð,r   c                 óJ   — | j                   j                  j                  «       S )z™
        See: L{ITransport.getHost}

        @return: An address describing this side of the connection.
        @rtype: L{SSHTransportAddress}.
        )r   rl   ÚgetHostr'   s    r    rp   zSSHChannel.getHost%  rn   r   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[   zSSHChannel.stopWriting.  ó   � r   c                  ó   — y)ze
        Called when the remote buffer has more room, as a hint to continue
        writing.
        Nrr   r'   s    r    r9   zSSHChannel.startWriting4  rs   r   )r   r   r   r   NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r	   ÚbytesÚ__annotations__r!   r-   r(   r%   r.   r3   r7   r>   rH   rM   rQ   rS   rV   rX   r:   r;   rh   rU   rm   rp   r[   r9   rr   r   r    r   r      s¬   … ññ@ ‹8€DØ€Dˆ%Óð ØØØØØØóð60˜ó 0ð
˜5ó 
òFò'òTò/ò*ò$6ò	
ò%òò!ò"ò:"ò@#ò&ò-ò-òór   r   N)rx   Úzope.interfacer   Útwisted.internetr   Útwisted.loggerr   Útwisted.pythonr   Ú
ITransportr   rr   r   r    ú<module>r€      sE   ðñ
õ 'å 'Ý !Ý ñ ˆZ×"Ñ"Ó#ôc�—‘ó có $ñcr   