§
    Ètºfî&  ã                   óŒ   — 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
dS )	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dS )Ú
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Únamer   c                 óø   — |pd| _         | j         | _        |pd| _        || _        || _        d| _        || _        || _        || _        d| _	        d| _
        g | _        d| _        d| _        d| _        d | _        d S )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           úX/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/ssh/channel.pyÚ__init__zSSHChannel.__init__9   s�   € ð  +Ð4¨fˆÔØ#Ô3ˆÔØ,Ð5°ˆÔØ ,ˆÔØ.ˆÔØˆŒØˆŒ	ØˆŒ	ØˆŒØˆÔØˆŒØˆŒØˆŒØˆÔØˆÔØˆŒˆˆr   Úreturnc                 óP   — |                       ¦   «                              d¦  «        S )NÚascii)Ú	__bytes__Údecode©r   s    r    Ú__str__zSSHChannel.__str__T   s    € Ø�~Š~ÑÔ×&Ò& wÑ/Ô/Ð/r   c                 ó<   — | 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   s9   € ð ŒyˆØð 	ØˆDà/ØØÔ ØÔ!ð3
ñ 
ð 	
r   c                 óÌ   — | j         d urt          | j         ¦  «        pd}| j        r| j                             d¦  «        }nd}d|› d|› d| j                             ¦   «         › �S )NÚunknownr$   ÚNonezSSHChannel z (z) on )r   Ústrr	   r&   r   Ú	logPrefix)r   r   r	   s      r    r.   zSSHChannel.logPrefixe   sr   € ØŒg˜TÐ!Ð2¥c¨$¬'¡l¤lÐ@°yˆØŒ9ð 	Ø”9×#Ò# GÑ,Ô,ˆDˆDàˆDØE˜TÐEÐE RÐEÐE¨d¬i×.AÒ.AÑ.CÔ.CÐEÐEÐEr   c                 ó:   — | j                              d¦  «         dS )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                              d|¬¦  «         dS )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ˆÑSÔSÐSÐSÐSr   c                 ó4  — | j         |z   | _         | j        s"| j        sd| _        |                      ¦   «          | j        r#| j        }d| _        |                      |¦  «         | j        r,| j        }g | _        |D ]\  }}|                      ||¦  «         ŒdS dS )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¸Ñ <ˆÔØŒð 	  t¤|ð 	 Ø"ˆDŒOØ×ÒÑÔÐØŒ8ð 	Ø”ˆAØˆDŒHØ�JŠJ�q‰MŒMˆMØŒ;ð 	/Ø”ˆAØˆDŒKØð /ð /‘
��dØ×"Ò" 4¨Ñ.Ô.Ð.Ð.ð		/ð 	/ð/ð /r   c                 óÒ   — |                      dd¦  «                             d¦  «        }t          | d|z   d¦  «        }|r ||¦  «        S | j                             d|¬¦  «         dS )	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”   sp   € ð ×!Ò! $¨Ñ-Ô-×4Ò4°WÑ=Ô=ˆÝ�D˜* sÑ*¨DÑ1Ô1ˆØð 	Ø�1�T‘7”7ˆNØŒ	�ŠÐ<È+ˆÑVÔVÐVØˆqr   c                 ó>   — | j                              d|¬¦  «         dS )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#   € ð 	Œ	�ŠÐ)°ˆÑ5Ô5Ð5Ð5Ð5r   c                 ó@   — | j                              d||¬¦  «         dS )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®   s2   € ð 	Œ	�ŠØ3¸hÈTð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r   c                 ó:   — | j                              d¦  «         dS )zD
        Called when the other side will send no more data.
        z
remote eofNr0   r'   s    r    ÚeofReceivedzSSHChannel.eofReceived¹   s   € ð 	Œ	�Š�|Ñ$Ô$Ð$Ð$Ð$r   c                 ób   — | j                              d¦  «         |                      ¦   «          dS )zD
        Called when the other side has closed the channel.
        zremote closeN)r1   r2   ÚloseConnectionr'   s    r    ÚcloseReceivedzSSHChannel.closeReceived¿   s0   € ð 	Œ	�Š�~Ñ&Ô&Ð&Ø×ÒÑÔÐÐÐr   c                 ó:   — | j                              d¦  «         dS )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_         dS t          |¦  «        }|| j        k    rF|d| j        …         || j        d…         c}| _         d| _        |                      ¦   «          | j        }| j        }| j        j        }t          d||¦  «        }|D ]} || ||||z   …         ¦  «         Œ| xj        |z  c_        | j	        r| j         s|  
                    ¦   «          dS dS dS )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Í   s4  € ð Œ8ð 	ØˆHŒH˜ÑˆHŒHØˆFÝ�$‰iŒiˆØ�Ô&Ò&Ð&àÐ,�tÔ,Ð,Ô-Ø�TÔ*Ð,Ð,Ô-ð ˆD�$”(ð  ˆDŒOØ×ÒÑÔÐØÔ'ˆCØÔ"ˆØ”	Ô"ˆÝ�!�S˜#ÑÔˆØð 	5ð 	5ˆFØˆE�$˜˜V f¨s¡lÐ2Ô3Ñ4Ô4Ð4Ð4ØÐÔ Ñ$ÐÔØŒ<ð 	" ¤ð 	"Ø×ÒÑ!Ô!Ð!Ð!Ð!ð	"ð 	"ð 	"ð 	"r   c                 ó  — | j         rQ| j         d         d         |k    r| j         d         dxx         |z  cc<   n| j                              ||g¦  «         dS t          |¦  «        | j        k    rB|d| j        …         ||| j        d…         ggc}| _         d| _        |                      ¦   «          t          |¦  «        | j        k    re| j                             | ||d| j        …         ¦  «         || j        d…         }| xj        | j        z  c_        t          |¦  «        | j        k    °e|r9| j                             | ||¦  «         | xj        t          |¦  «        z  c_        | j	        r|  
                    ¦   «          dS dS )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ê   s³  € ð Œ;ð 	ØŒ{˜2Œ˜qÔ! XÒ-Ð-Ø”˜B” Ð"Ð"Ô" dÑ*Ð"Ð"Ñ"Ð"à”×"Ò" H¨dÐ#3Ñ4Ô4Ð4ØˆFÝˆt‰9Œ9�tÔ,Ò,Ð,àÐ,�tÔ,Ð,Ô-Ø˜D Ô!6Ð!8Ð!8Ô9Ð:Ð;ð ˆD�$”+ð  ˆDŒOØ×ÒÑÔÐÝ�$‰iŒi˜$Ô.Ò.Ð.ØŒI×&Ò& t¨X°tÐ<R¸dÔ>RÐ<RÔ7SÑTÔTÐTØ˜Ô,Ð.Ð.Ô/ˆDØÐ!Ô! TÔ%9Ñ9Ð!Ô!õ �$‰iŒi˜$Ô.Ò.Ð.ð ð 	/ØŒI×&Ò& t¨X°tÑ<Ô<Ð<ØÐ!Ô!¥S¨¡Y¤YÑ.Ð!Ô!ØŒ<ð 	"Ø×ÒÑ!Ô!Ð!Ð!Ð!ð	"ð 	"r   c                 óV   — |                       d                     |¦  «        ¦  «         dS )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                 ól   — d| _         | j        s#| j        s| j                             | ¦  «         dS dS dS )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  sN   € ð
 ˆŒØŒxð 	& ¤ð 	&ØŒI×Ò Ñ%Ô%Ð%Ð%Ð%ð	&ð 	&ð 	&ð 	&r   c                 ó>   — | 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Ô"×*Ò*Ñ,Ô,Ð,r   c                 ó>   — | 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                 ó   — dS )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                 ó   — dS )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´  € € € € € € ðð ð@ ˆ6‰8Œ8€DØ€Dˆ%ÐÐÑð ØØØØØØðð ð ð ð60˜ð 0ð 0ð 0ð 0ð
˜5ð 
ð 
ð 
ð 
ðFð Fð Fð'ð 'ð 'ðTð Tð Tð/ð /ð /ð*ð ð ð$6ð 6ð 6ð	
ð 	
ð 	
ð%ð %ð %ðð ð ð!ð !ð !ð"ð "ð "ð:"ð "ð "ð@#ð #ð #ð&ð &ð &ð-ð -ð -ð-ð -ð -ðð ð ðð ð ð ð r   r   N)rx   Úzope.interfacer   Útwisted.internetr   Útwisted.loggerr   Útwisted.pythonr   Ú
ITransportr   rr   r   r    ú<module>r€      s³   ðð
ð ð 'Ð &Ð &Ð &Ð &Ð &à 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð ð €ˆZÔ"Ñ#Ô#ðcð cð cð cð c�”ñ cô cñ $Ô#ðcð cð cr   