
    h&                         S r SSKJr  SSKJr  SSKJr  SSKJr  \" \R                  5       " S S\R                  5      5       r
g)	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                       \ rS rSr% Sr\" 5       rSr\\	S'          SS jr
S\4S jrS\4S jrS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSr g)
SSHChannel   aF  
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                    U=(       d    SU l         U R                   U l        U=(       d    SU l        X0l        X@l        SU l        XPl        X`l        Xpl        SU l	        SU l
        / U l        SU l        SU l        SU l        S U l        g )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           `/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/conch/ssh/channel.py__init__SSHChannel.__init__9   s      +4f#33,5 ,.		r   returnc                 @    U R                  5       R                  S5      $ )Nascii)	__bytes__decoder   s    r!   __str__SSHChannel.__str__T   s    ~~&&w//r   c                 d    U R                   nU(       d  SnSUU R                  U R                  4-  $ )z4
Return a byte string representation of the channel
s   Nones   <SSHChannel %b (lw %d rw %d)>)r
   r   r   )r   r
   s     r!   r'   SSHChannel.__bytes__W   s<     yyD/  !!3
 
 	
r   c                    U R                   S L=(       a    [        U R                   5      =(       d    SnU R                  (       a  U R                  R                  S5      nOSnSU SU SU R                  R                  5        3$ )Nunknownr&   NonezSSHChannel z (z) on )r   strr
   r(   r   	logPrefix)r   r   r
   s      r!   r2   SSHChannel.logPrefixe   si    ggT!2c$''l@y9999##G,DDTF"RDdii.A.A.C-DEEr   c                 :    U R                   R                  S5        g)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!   channelOpenSSHChannel.channelOpenm   s     			~&r   c                 8    U R                   R                  SUS9  g)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)r6   error)r   r;   s     r!   
openFailedSSHChannel.openFailedv   s     			CFSr   c                    U R                   U-   U l         U R                  (       d(  U R                  (       d  SU l        U R                  5         U R                  (       a$  U R                  nSU l        U R                  U5        U R                  (       a0  U R                  n/ U l        U H  u  p1U R                  X15        M     gg)zt
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!   addWindowBytesSSHChannel.addWindowBytes   s     !% 5 5 <t||"DO88ADHJJqM;;ADK
""4.   r   c                     UR                  SS5      R                  S5      n[        U SU-   S5      nU(       a  U" U5      $ U R                  R	                  SUS9  g)	a
  
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(   getattrr6   r7   )r   rK   r   foofs        r!   requestReceivedSSHChannel.requestReceived   sX     !!$-44W=D*s*D1T7N		<+Vr   c                 8    U R                   R                  SUS9  g)z4
Called when we receive data.

@type data: L{bytes}
zgot data {data})r   Nr6   debugr   r   s     r!   dataReceivedSSHChannel.dataReceived   s     			)5r   c                 8    U R                   R                  SXS9  g)zo
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   NrS   r   rY   r   s      r!   extReceivedSSHChannel.extReceived   s     			3h 	 	
r   c                 :    U R                   R                  S5        g)z4
Called when the other side will send no more data.
z
remote eofNr5   r)   s    r!   eofReceivedSSHChannel.eofReceived   s     			|$r   c                 Z    U R                   R                  S5        U R                  5         g)z4
Called when the other side has closed the channel.
zremote closeN)r6   r7   loseConnectionr)   s    r!   closeReceivedSSHChannel.closeReceived   s      			~&r   c                 :    U R                   R                  S5        g)zp
Called when the channel is closed.  This means that both our side and
the remote side have closed the channel.
closedNr5   r)   s    r!   re   SSHChannel.closed   s    
 			x r   c                 *   U R                   (       a  U =R                   U-  sl         g[        U5      nX R                  :  aE  USU R                   XR                  S sol         SU l        U R	                  5         U R                  nU R
                  nU R                  R                  n[        SX#5      nU H  nU" XXfU-    5        M     U =R                  U-  sl        U R                  (       a#  U R                   (       d  U R                  5         ggg)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   ra   )r   r   toprmprA   roffsets          r!   rA   SSHChannel.write   s     88HHH$i&&&,t,,-**,- D(  DO''C""		""!SF$Vsl34 $<<! !)<r   c                 F   U R                   (       aN  U R                   S   S   U:X  a  U R                   S   S==   U-  ss'   gU R                   R                  X/5        g[        U5      U R                  :  a<  USU R                   XU R                  S //so l         SU l        U R                  5         [        U5      U R                  :  aq  U R                  R                  XUSU R                   5        X R                  S nU =R                  U R                  -  sl        [        U5      U R                  :  a  Mq  U(       a:  U R                  R                  XU5        U =R                  [        U5      -  sl        U R                  (       a  U R                  5         gg)z
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   appendrh   r   r   ri   r   r   sendExtendedDatar   ra   rZ   s      r!   rB   SSHChannel.writeExtended   se    ;;{{2q!X-B"d*"  ""H#34t9t,,,,t,,-!6!6!89:; D+  DO$i$...II&&tt<Rd>R>R7ST,,./D!!T%9%99! $i$... II&&tt<!!SY.!<<! r   c                 D    U R                  SR                  U5      5        g)zj
Part of the Transport interface.  Write a list of strings to the
channel.

@type data: C{list} of L{str}
r   N)rA   joinrU   s     r!   writeSequenceSSHChannel.writeSequence
  s     	

388D>"r   c                     SU l         U R                  (       d.  U R                  (       d  U R                  R	                  U 5        ggg)zZ
Close the channel if there is no buferred data.  Otherwise, note the
request and return.
r   N)r   r   r   r   	sendCloser)   s    r!   ra   SSHChannel.loseConnection  s1    
 xxII% !,xr   c                 J    U R                   R                  R                  5       $ )zm
See: L{ITransport.getPeer}

@return: The remote address of this connection.
@rtype: L{SSHTransportAddress}.
)r   	transportgetPeerr)   s    r!   r   SSHChannel.getPeer       yy""**,,r   c                 J    U R                   R                  R                  5       $ )zy
See: L{ITransport.getHost}

@return: An address describing this side of the connection.
@rtype: L{SSHTransportAddress}.
)r   r~   getHostr)   s    r!   r   SSHChannel.getHost%  r   r   c                     g)zo
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!   ri   SSHChannel.stopWriting.      r   c                     g)zM
Called when the remote buffer has more room, as a hint to continue
writing.
Nr   r)   s    r!   r@   SSHChannel.startWriting4  r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   NNN)!__name__
__module____qualname____firstlineno____doc__r   r6   r
   bytes__annotations__r"   r1   r*   r'   r2   r8   r=   rE   rP   rV   r[   r^   rb   re   rA   rB   rx   ra   r   r   ri   r@   __static_attributes__r   r   r!   r   r      s    @ 8DD% 60 0
5 
F'T/*$6	
%!":"@#&--r   r   N)r   zope.interfacer   twisted.internetr   twisted.loggerr   twisted.pythonr   
ITransportr   r   r   r!   <module>r      sE   
 ' ' !  Z""#c c $cr   