+
    Dfj<                        R t ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt  ! R R	]P                   4      t ! R
 R]P$                  4      t ! R R]P$                  4      t ! R R]4      t ! R R]P                   4      t]P0                  ! R^4      R,          R8X  d   RtRtMRtRt ! R R]P                   4      tR# )z0
Test cases for twisted.protocols.ident module.
N)StringIO)defererror)StringTransport)ident)failure)unittestc                   H   a  ] tR t^t o RtR tR tR tR tR t	R t
RtV tR	# )
ClassParserTestsz"
Test parsing of ident responses.
c                :    \         P                  ! 4       V n        R# )z'
Create an ident client used in tests.
N)r   IdentClientclientselfs   &9/usr/lib/python3/dist-packages/twisted/test/test_ident.pysetUpClassParserTests.setUp   s     '')    c                    \         P                  ! 4       pV P                  P                  P	                  V^{R34       V P                  P                  R4       V P                  V\        P                  4      # )zH
'UNKNOWN-ERROR' error should map to the L{ident.IdentError} exception.
  z 123, 456 : ERROR : UNKNOWN-ERROR)	r   Deferredr   queriesappendlineReceivedassertFailurer   
IdentErrorr   ds   & r   test_indentError!ClassParserTests.test_indentError   sZ     NN""AsC=1  !CD!!!U%5%566r   c                    \         P                  ! 4       pV P                  P                  P	                  V^R34       V P                  P                  R4       V P                  V\        P                  4      # )z>
'NO-USER' error should map to the L{ident.NoUser} exception.
r   z234, 456 : ERROR : NO-USER)	r   r   r   r   r   r   r   r   NoUserr   s   & r   test_noUSerError!ClassParserTests.test_noUSerError(   sX     NN""AsC=1  !=>!!!U\\22r   c                    \         P                  ! 4       pV P                  P                  P	                  VRR34       V P                  P                  R4       V P                  V\        P                  4      # )zH
'INVALID-PORT' error should map to the L{ident.InvalidPort} exception.
iY  7  z 345, 567 :  ERROR : INVALID-PORT)	r   r   r   r   r   r   r   r   InvalidPortr   s   & r   test_invalidPortError&ClassParserTests.test_invalidPortError1   sZ     NN""AsC=1  !CD!!!U%6%677r   c                    \         P                  ! 4       pV P                  P                  P	                  VRR34       V P                  P                  R4       V P                  V\        P                  4      # )zF
'HIDDEN-USER' error should map to the L{ident.HiddenUser} exception.
r%   i  z567, 789 : ERROR : HIDDEN-USER)	r   r   r   r   r   r   r   r   
HiddenUserr   s   & r   test_hiddenUserError%ClassParserTests.test_hiddenUserError:   sZ     NN""AsC=1  !AB!!!U%5%566r   c                @   \         P                  ! 4       pV P                  P                  P	                  VRR34       V P                  P                  \        P                  ! \        P                  ! 4       4      4       V P                  V\        P                  4      # )za
A pending query which failed because of a ConnectionLost should
receive an L{ident.IdentError}.
i  i  )r   r   r   r   r   connectionLostr   Failurer   ConnectionLostr   r   r   r   s   & r   test_lostConnection$ClassParserTests.test_lostConnectionC   sk    
 NN""AsC=1""7??53G3G3I#JK!!!U%5%566r   )r   N)__name__
__module____qualname____firstlineno____doc__r   r   r"   r'   r+   r1   __static_attributes____classdictcell____classdict__s   @r   r
   r
      s-     *73877 7r   r
   c                   &   a  ] tR t^Nt o R tRtV tR# )TestIdentServerc                    V P                   # N)resultValuer   serverAddressclientAddresss   &&&r   lookupTestIdentServer.lookupO   s    r    Nr3   r4   r5   r6   rD   r8   r9   r:   s   @r   r=   r=   N   s        r   r=   c                   &   a  ] tR t^St o R tRtV tR# )TestErrorIdentServerc                "    V P                  4       hr?   )exceptionTyperA   s   &&&r   rD   TestErrorIdentServer.lookupT   s      ""r   rF   NrG   r:   s   @r   rI   rI   S   s     # #r   rI   c                       ] tR t^XtRtR# )NewExceptionrF   N)r3   r4   r5   r6   r8   rF   r   r   rN   rN   X   s    r   rN   c                   ,   a  ] tR t^\t o R tR tRtV tR# )ServerParserTestsc                   \        4       pVP                  \        4       4       . pVP                  Vn        \
        P                  Vn        VP                  R 4       V P                  V^ ,          R4       \
        P                  Vn        VP                  R4       V P                  V^,          R4       \
        P                  Vn        VP                  R4       V P                  V^,          R4       \
        P                  Vn        VP                  R4       V P                  V^,          R4       \        Vn        VP                  R4       V P                  V^,          R	4       V P                  \        4      pV P                  \        V4      ^4       R F\  pVR
 VP                  RV3,          4       VP                  RV3,          4       V P                  VRV3,          RV3,          .4       K^  	  R# )z123, 345z 123, 345 : ERROR : UNKNOWN-ERRORz432, 210z432, 210 : ERROR : NO-USERz987, 654z987, 654 : ERROR : INVALID-PORTz756, 827z756, 827 : ERROR : HIDDEN-USERz987, 789z 987, 789 : ERROR : UNKNOWN-ERROR:NNNz%d, 5z5, %dz%d, 5 : ERROR : INVALID-PORTz5, %d : ERROR : INVALID-PORTN)    i   i  )rI   makeConnectionr   r   sendLiner   r   rK   r   assertEqualr!   r&   r*   rN   flushLoggedErrorslen)r   pLerrsports   &    r   
testErrorsServerParserTests.testErrors]   s    "	*+XX
**	z"1AB,,	z"1;<++	z"1@A**	z"1?@&	z"1AB%%l3TA&'D!NN7dW,-NN7dW,-2dW<2dW<	 (r   c                    \        4       pVP                  \        4       4       . pVP                  Vn        RVn        VP                  R4       V P                  V^ ,          R4       R# )SYSz123, 456z123, 456 : USERID : SYS : USERN)r`   USER)r=   rT   r   r   rU   r@   r   rV   )r   rY   rZ   s   &  r   testSuccessServerParserTests.testSuccess   sS    	*+XX
'	z"1?@r   rF   N)r3   r4   r5   r6   r]   rb   r8   r9   r:   s   @r   rP   rP   \   s     &PA Ar   rP   z=L:rS      N   0100007F040302017F00000101020304c                   l   a  ] tR t^t o R]: R]: R2tR],           tR tR t	R t
R tR	 tR
 tRtV tR# )ProcMixinTestsz4: z:0019 z]:02FA 0A 00000000:00000000 00:00000000 00000000     0        0 10927 1 f72a5b80 3000 0 0 2 -1zd  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
   c                z    \         P                  ! 4       pV P                  VP                  \        4      R 4       R# )	127.0.0.1N)r   ProcServerMixinrV   dottedQuadFromHexString_addr1r   rY   s   & r   testDottedQuadFromHexString*ProcMixinTests.testDottedQuadFromHexString   s+    !!#226:KHr   c                    \         P                  ! 4       pV P                  VP                  \        R ,           4      R4       R# )z:0277N)rm   iw  )r   rn   rV   unpackAddressrp   rq   s   & r   testUnpackAddress ProcMixinTests.testUnpackAddress   s/    !!#')9:<NOr   c                    \         P                  ! 4       pV P                  VP                  V P                  4      R4       R# )rm   N)rm      1.2.3.4  rS   )r   rn   rV   	parseLinelinerq   s   & r   testLineParserProcMixinTests.testLineParser   s1    !!#KK		"$L	
r   c                   a a . o\         P                  ! 4       pV 3R  lVn        V3R lVn        S P	                  VP                  RR4      VP                  R34       S P	                  S^ .4       R# )c                  0   < \        S P                  .4      # r?   iterr   r   s   r   <lambda>4ProcMixinTests.testExistingAddress.<locals>.<lambda>       D$))-r   c                 8   < SP                  V 4      R 3^,          # )root)r   )uidusernames   &r   r   r      s    X__S%96$B1$Er   r   Nry   r{   )r   rn   entriesgetUsernamerV   rD   SYSTEM_NAME)r   rY   r   s   f @r   testExistingAddress"ProcMixinTests.testExistingAddress   sa    !!#-	EHH&(89AMM6;R	
 	A3'r   c                P  a  \         P                  ! 4       pV 3R  lVn        S P                  \         P                  VP
                  RR4       S P                  \         P                  VP
                  RR4       S P                  \         P                  VP
                  RR4       R# )c                  0   < \        S P                  .4      # r?   r   r   s   r   r   7ProcMixinTests.testNonExistingAddress.<locals>.<lambda>   r   r   Nrm      r{   ry   )z1.2.3.5r}   )r|   i  )r   rn   r   assertRaisesr!   rD   rq   s   f r   testNonExistingAddress%ProcMixinTests.testNonExistingAddress   sr    !!#-	%,,2CEUV%,,2CEUV%,,2CEUVr   c                   a a . oVV 3R lpS P                  \        RV4       \        P                  ! 4       pS P	                  \        P
                  VP                  RR4       S P                  R/ 3.S4       R# )zC
L{ident.ProcServerMixin.lookup} uses the Linux TCP process table.
c                 R   < SP                  W34       \        SP                  4      # )zC
Mock for the open call to prevent actually opening /proc/net/tcp.
)r   r   
sampleFile)argskwargs
open_callsr   s   *,r   mocked_open8ProcMixinTests.testLookupProcNetTcp.<locals>.mocked_open   s$     tn-DOO,,r   openNr   r{   )z/proc/net/tcp)patchbuiltinsr   rn   r   r!   rD   rV   )r   r   rY   r   s   f  @r   testLookupProcNetTcp#ProcMixinTests.testLookupProcNetTcp   sf     
	- 	

8V[1!!#%,,2CEUV-r23Z@r   rF   N)r3   r4   r5   r6   rp   _addr2r   r   rr   rv   r   r   r   r   r8   r9   r:   s   @r   rk   rk      sM     
 
	D	68<	= 
IP
(WA Ar   rk   )r7   r   structior   twisted.internetr   r   twisted.internet.testingr   twisted.protocolsr   twisted.pythonr   twisted.trialr   TestCaser
   IdentServerr=   rI   RuntimeErrorrN   rP   packrp   r   rk   rF   r   r   <module>r      s   
    ) 4 # " "77x(( 77t e''  
#5,, #
	< 	1A)) 1Ah 
;;tQ'FFFF;AX&& ;Ar   