
    h                        S r SSKrSSKJr  SSKJr  SSKJrJr  Sr	Sr
 " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\R                   5      r " S S5      r " S S\R                   5      r/ SQrg)z 
Ident protocol implementation.
    N)defer)basic)failurelog   i  c                   *    \ rS rSrSrSrS\4S jrSrg)
IdentError   z3
Can't determine connection owner; reason unknown.
zUNKNOWN-ERRORreturnc                     U R                   $ N)identDescriptionselfs    ^/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/protocols/ident.py__str__IdentError.__str__   s    $$$     N)	__name__
__module____qualname____firstlineno____doc__r   strr   __static_attributes__r   r   r   r	   r	      s     '% %r   r	   c                       \ rS rSrSrSrSrg)NoUser   zu
The connection specified by the port pair is not currently in use or
currently not owned by an identifiable entity.
zNO-USERr   Nr   r   r   r   r   r   r   r   r   r   r   r      s    
 !r   r   c                       \ rS rSrSrSrSrg)InvalidPort'   a  
Either the local or foreign port was improperly specified. This should
be returned if either or both of the port ids were out of range (TCP
port numbers are from 1-65535), negative integers, reals or in any
fashion not recognized as a non-negative integer.
zINVALID-PORTr   Nr    r   r   r   r"   r"   '   s     &r   r"   c                       \ rS rSrSrSrSrg)
HiddenUser2   zy
The server was able to identify the user of this port, but the
information was not returned at the request of the user.
zHIDDEN-USERr   Nr    r   r   r   r%   r%   2   s    
 %r   r%   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)IdentServer;   a  
The Identification Protocol (a.k.a., "ident", a.k.a., "the Ident
Protocol") provides a means to determine the identity of a user of a
particular TCP connection. Given a TCP port number pair, it returns a
character string which identifies the owner of that connection on the
server's system.

Server authors should subclass this class and override the lookup method.
The default implementation returns an UNKNOWN-ERROR response for every
query.
c                    UR                  S5      n[        U5      S:w  a  U R                  5         g  [        [        U5      u  p4[
        Us=::  a
  [        ::  a-  O  O*[
        Us=::  a
  [        ::  a  O  OU R                  X45        g U R                  [        R                  " [        5       5      X45        g ! [         a    U R                  5          g f = f)N,   )splitleninvalidQuerymapint	_MIN_PORT	_MAX_PORT
validQuery	_ebLookupr   Failurer"   
ValueError)r   linepartsportOnServerportOnClients        r   lineReceivedIdentServer.lineReceivedH   s    

3u:?-0e_*
 ::!\>Y>OOL?NN6  $!!#$s   B6 6CCc                 8    U R                   R                  5         g r   )	transportloseConnectionr   s    r   r/   IdentServer.invalidQuery\   s    %%'r   c                 F   U R                   R                  5       R                  U4nU R                   R                  5       R                  U4n[        R
                  " U R                  X45      R                  U R                  X5      R                  U R                  X5        g)z
Called when a valid query is received to look up and deliver the
response.

@param portOnServer: The server port from the query.
@param portOnClient: The client port from the query.
N)r?   getHosthostgetPeerr   maybeDeferredlookupaddCallback	_cbLookup
addErrbackr5   )r   r:   r;   
serverAddr
clientAddrs        r   r4   IdentServer.validQuery_   sv     ^^++-22L@
^^++-22L@
DKK@LLNNL	

*T^^\
@r   c                 8    Uu  pEU R                  SX#XE4-  5        g )Nz%d, %d : USERID : %s : %s)sendLine)r   resultsportcportsysNameuserIds         r   rI   IdentServer._cbLookupm   s!    "1U74SSTr   c                     UR                   " [        5      (       a!  U R                  SX#UR                  4-  5        g [        R
                  " U5        U R                  SX#[        UR                  5      4-  5        g )Nz%d, %d : ERROR : %s)checkr	   rO   valuer   err)r   r   rQ   rR   s       r   r5   IdentServer._ebLookupq   sZ    ==$$MM/52OOPGGGMM%z'--7P(QQr   c                     [        5       e)a  
Lookup user information about the specified address pair.

Return value should be a two-tuple of system name and username.
Acceptable values for the system name may be found online at::

    U{http://www.iana.org/assignments/operating-system-names}

This method may also raise any IdentError subclass (or IdentError
itself) to indicate user information will not be provided for the
given query.

A Deferred may also be returned.

@param serverAddress: A two-tuple representing the server endpoint
of the address being queried.  The first element is a string holding
a dotted-quad IP address.  The second element is an integer
representing the port.

@param clientAddress: Like I{serverAddress}, but represents the
client endpoint of the address being queried.
r	   )r   serverAddressclientAddresss      r   rG   IdentServer.lookupz   s    . lr   r   N)r   r   r   r   r   r<   r/   r4   rI   r5   rG   r   r   r   r   r(   r(   ;   s'    
((AUr   r(   c                   x    \ rS rSrSrSr SSKJr  \4S jrCS	 r
S
 rS rS rS rSrg! \	 a    SS jr Nf = f)ProcServerMixin   zDImplements lookup() to grab entries for responses from /proc/net/tcpLINUXr   )getpwuidc                     U" U5      S   $ Nr   r   r   uidrd   s      r   getUsernameProcServerMixin.getUsername   s    C=##r   Nc                     [        5       er   r\   rg   s      r   ri   rj      s
    ,r   c              #      #    [        S5       nUR                  5         U H  nUR                  5       v   M     S S S 5        g ! , (       d  f       g = f7f)Nz/proc/net/tcp)openreadlinestrip)r   fLs      r   entriesProcServerMixin.entries   s8     /"aJJLggi  #""s   A,A	A
AAc                     SR                  [        [        [        R                  " S[        R
                  " S[        US5      5      5      5      5      $ )N.4Bz=L   )joinr0   r   structunpackpackr1   )r   hexstrs     r   dottedQuadFromHexString'ProcServerMixin.dottedQuadFromHexString   s9    xxV]]4T3vr?)KLM
 	
r   c                 h    UR                  S5      u  p#U R                  U5      n[        US5      nX#4$ )N:rw   )r-   r}   r1   )r   packedaddrports       r   unpackAddressProcServerMixin.unpackAddress   s5    \\#&
++D14}zr   c                     UR                  5       R                  5       nU R                  US   5      u  p4U R                  US   5      u  pV[        US   5      nX44XV4U4$ )Nr   r,      )ro   r-   r   r1   )r   r8   r9   	localAddr	localPort
remoteAddr
remotePortrh   s           r   	parseLineProcServerMixin.parseLine   sd    

""$#11%(;	!%!3!3E!H!=
%(m%
'?DDr   c                     U R                  5        HI  nU R                  U5      u  pEnXR:X  d  M  US   US   :X  d  M,  U R                  U R                  U5      4s  $    [	        5       e)Nr   )rr   r   SYSTEM_NAMEri   r   )r   r]   r^   entr   r   rh   s          r   rG   ProcServerMixin.lookup   s`    <<>C)-)<&I3*y|}Q?O/O(($*:*:3*?@@ "
 hr   r   r   )r   r   r   r   r   r   pwdrd   ri   ImportErrorrr   r}   r   r   rG   r   r   r   r   ra   ra      sO    NK
 ,4 	$  

E;  	s   + 99ra   c                   >    \ rS rSr\\\\4rS r	S r
S rS rS rSrg)	IdentClient   c                     / U l         g r   queriesr   s    r   __init__IdentClient.__init__   s	    r   c                    U R                   R                  [        R                  " 5       X45        [	        U R                   5      S:  a  U R                   S   S   $ U R                  SX4-  5        U R                   S   S   $ )z;
Lookup user information about the specified address pair.
r   r   %d, %d)r   appendr   Deferredr.   rO   )r   r:   r;   s      r   rG   IdentClient.lookup   so     	U^^-|JKt||q <<#A&&h,!==>||B""r   c                 L   U R                   (       d  [        R                  " SU< 35        g U R                   R                  S5      u  n  nU R	                  X!5        U R                   (       a7  U R                  SU R                   S   S   U R                   S   S   4-  5        g g )NzUnexpected server response: r   r   r   r,   )r   r   msgpopparseResponserO   )r   r8   d_s       r   r<   IdentClient.lineReceived   s    ||GG24(;<ll&&q)GAq!q'||h$,,q/!*<dll1oa>P)QQR r   c                 r    U R                    H   nUS   R                  [        U5      5        M"     / U l         g rf   )r   errbackr	   )r   reasonqs      r   connectionLostIdentClient.connectionLost   s,    AaDLLF+, r   c                    UR                  SS5      n[        U5      S:w  a  UR                  [        U5      5        g [	        [
        R                  U5      u  pEnUS:X  aW  U R                   H,  nUR                  U:X  d  M  UR                  U" U5      5          g    UR                  [        U5      5        g UR                  XV45        g )Nr   r,      ERROR)
r-   r.   r   r	   r0   r   ro   
errorTypesr   callback)r   deferredr8   r9   portstypeaddInfoets           r   r   IdentClient.parseResponse   s    

3"u:?Z-.#&syy%#8 Ew//B**g5 ((D2 *   D!12!!4/2r   r   N)r   r   r   r   r	   r   r"   r%   r   r   rG   r<   r   r   r   r   r   r   r   r      s*    fk:>J	#S
3r   r   )r	   r   r"   r%   r(   r   ra   )r   ry   twisted.internetr   twisted.protocolsr   twisted.pythonr   r   r2   r3   	Exceptionr	   r   r"   r%   LineOnlyReceiverr(   ra   r   __all__r   r   r   <module>r      s   
  " # '		% %!Z !&* &% %V%(( Vr/ /d,3%(( ,3^r   