+
    Dfj$                         R t ^ RIt^ RIHt ^ RIHtHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHt ^ RIHt ^ R	IHt ^ R
IHt  ! R R]4      t ! R R]P2                  4      t ! R R]P6                  4      tR# )z-
Test cases for L{twisted.names.srvconnect}.
N)verifyObject)deferprotocol)DNSLookupErrorServiceNameUnknownError)
IConnector)MemoryReactor)clientdns
srvconnect)ResolverBase)DNSNameError)unittestc                   4   a  ] tR t^t o RtRR ltR tRtV tR# )FakeResolverah  
Resolver that only gives out one given result.

Either L{results} or L{failure} must be set and will be used for
the return value of L{_lookup}

@ivar results: List of L{dns.RRHeader} for the desired result.
@type results: C{list}
@ivar failure: Failure with an exception from L{twisted.names.error}.
@type failure: L{Failure<twisted.python.failure.Failure>}
Nc                ,    Wn         W n        . V n        R # N)resultsfailurelookups)selfr   r   s   &&&D/usr/lib/python3/dist-packages/twisted/names/test/test_srvconnect.py__init__FakeResolver.__init__$   s        c                    V P                   P                  WW434       V P                  e$   \        P                  ! V P                  . . 34      # \        P
                  ! V P                  4      # )z)
Return the result or failure on lookup.
)r   appendr   r   succeedfailr   )r   nameclsqtypetimeouts   &&&&&r   _lookupFakeResolver._lookup)   sR     	T78<<#==$,,B!788::dll++r   )r   r   r   )NN)	__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes____classdictcell____classdict__s   @r   r   r      s     

, ,r   r   c                   0   a  ] tR t^4t o RtR tR tRtV tR# )DummyFactoryzD
Dummy client factory that stores the reason of connection failure.
c                    R V n         R # r   reasonr   s   &r   r   DummyFactory.__init__9   s	    r   c                    W n         R # r   r1   )r   	connectorr2   s   &&&r   clientConnectionFailed#DummyFactory.clientConnectionFailed<   s    r   r1   N)	r%   r&   r'   r(   r)   r   r7   r*   r+   r,   s   @r   r/   r/   4   s      r   r/   c                   ~   a  ] tR t^@t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tRtV tR# )SRVConnectorTestsz'
Tests for L{srvconnect.SRVConnector}.
c                    V P                  \        R \        4       4       \        4       V n        \        4       V n        \        P                  ! V P                  RRV P                  4      V n	        . V n
        . V n        R# )theResolverxmpp-serverexample.orgN)patchr	   r   r   reactorr/   factoryr   SRVConnectorr6   randIntArgsrandIntResultsr3   s   &r   setUpSRVConnectorTests.setUpE   s[    

6=,.9$#~#00LL-
  r   c                p    V P                   P                  W34       V P                  P                  ^ 4      # )a@  
Fake randint.

Returns the first element of L{randIntResults} and records the
arguments passed to it in L{randIntArgs}.

@param min: Lower bound of the random number.
@type min: L{int}

@param max: Higher bound of the random number.
@type max: L{int}

@return: Fake random number from L{randIntResults}.
@rtype: L{int}
)rC   r   rD   pop)r   minmaxs   &&&r   _randintSRVConnectorTests._randintO   s1      	
+""&&q))r   c                :    \        \        V P                  4       R# )z6
L{srvconnect.SRVConnector} implements L{IConnector}.
N)r   r   r6   r3   s   &r   test_interface SRVConnectorTests.test_interfaceb   s     	Z0r   c                   \         P                  ! RR^<R7      p\         P                  ! R\         P                  \         P                  ^<VR7      .\
        P                  n        V P                  P                  4        V P                  V P                  P                  4       V P                  V P                  P                  P!                  4       R,          R4       R# )	zC
Test connectTCP gets called with the address from the SRV record.
}  host.example.orgporttargetttlr>   r   typer    rV   payloadN   NN)rR   rQ   )r
   
Record_SRVRRHeaderSRVINr	   r<   r   r6   connectassertIsNonerA   r2   assertEqualr@   
tcpClientsrH   r   rY   s   & r   test_SRVPresent!SRVConnectorTests.test_SRVPresenth   s     ..d3E2NLL"cff"g&
"
 	 $,,--.00446r:<VWr   c                6   \        R4      \        P                  n        V P                  P                  4        V P                  V P                  P                  4       V P                  V P                  P                  P                  4       R,          R4       R# )zC
Test connectTCP gets called with fallback parameters on NXDOMAIN.
s   example.orgrZ   Nr>   r=   )r   r	   r<   r   r6   r`   ra   rA   r2   rb   r@   rc   rH   r3   s   &r   test_SRVNotPresent$SRVConnectorTests.test_SRVNotPresentw   sk     &2.%A" $,,--.LL##'')"-/M	
r   c                $   . \         P                  n        V P                  P	                  4        V P                  V P                  P                  4       V P                  V P                  P                  P                  4       R,          R4       R# )zG
Test connectTCP gets called with fallback parameters on empty result.
rZ   Nrh   )r	   r<   r   r6   r`   ra   rA   r2   rb   r@   rc   rH   r3   s   &r   test_SRVNoResult"SRVConnectorTests.test_SRVNoResult   sf     &(" $,,--.LL##'')"-/M	
r   c                   \         P                  ! V P                  RRV P                  RR7      V n        \        4       \        P                  n        V P                  P                  4        V P                  V P                  P                  4       V P                  V P                  P                  P                  4       R,          R4       R# )zI
connectTCP gets called with default port if the service is not defined.
thisbetternotexistr>   f  )defaultPortrZ   N)r>   rp   )r   rB   r@   rA   r6   r   r	   r<   r   r`   ra   r2   rb   rc   rH   r3   s   &r   )test_SRVNoResultUnknownServiceDefaultPort;SRVConnectorTests.test_SRVNoResultUnknownServiceDefaultPort   s     $00LL LL
 &=%>" $,,--.00446r:<QRr   c                H   \         P                  ! V P                  RRV P                  4      V n        \        4       \        P                  n        V P                  P                  4        V P                  V P                  P                  P                  \
        4      4       R# )zB
Connect fails on no result, unknown service and no default port.
ro   r>   N)r   rB   r@   rA   r6   r   r	   r<   r   r`   
assertTruer2   checkr3   s   &r   +test_SRVNoResultUnknownServiceNoDefaultPort=SRVConnectorTests.test_SRVNoResultUnknownServiceNoDefaultPort   sm     $00LL.t||
 &=%>" ++112IJKr   c                   \         P                  ! R\         P                  \         P                  ^<RR7      .\        P
                  n        V P                  P                  4        V P                  V P                  P                  4       V P                  V P                  P                  P                  4       R,          R4       R# )zE
Test connectTCP gets called with fallback parameters on bad result.
r>   NrW   rZ   rh   )r
   r]   CNAMEr_   r	   r<   r   r6   r`   ra   rA   r2   rb   r@   rc   rH   r3   s   &r   test_SRVBadResult#SRVConnectorTests.test_SRVBadResult   s    
 LL"BPT&
"
 	 $,,--.LL##'')"-/M	
r   c                   \         P                  ! RR^<R7      p\         P                  ! R\         P                  \         P                  ^<VR7      .\
        P                  n        V P                  P                  4        V P                  V P                  P                  4       V P                  P                  P                  \        4       V P                  V P                   P"                  . 4       R# )z8
Test that connecting fails when no service is present.
i     .rS   r>   rW   N)r
   r\   r]   r^   r_   r	   r<   r   r6   r`   assertIsNotNonerA   r2   trapr   rb   r@   rc   rd   s   & r   test_SRVNoService#SRVConnectorTests.test_SRVNoService   s     ..d4R@LL"cff"g&
"
 	 T\\001  000"5r   c                    . \         P                  n        V P                  P	                  4        \         P                  P
                  R,          ^ ,          pV P                  RV4       R# )zG
The lookup name is a native string from service, protocol and domain.
s   _xmpp-server._tcp.example.orgN)r	   r<   r   r6   r`   r   rb   )r   r   s   & r   test_SRVLookupName$SRVConnectorTests.test_SRVLookupName   sN     &(" !!))"-a094@r   c                    \         P                  ! V P                  RRV P                  4      V n        V P                  RV P                  P                  4       R# )zY
L{srvconnect.SRVConnector} automatically encodes unicode domain using
C{idna} encoding.
zxmpp-clientu   échec.example.orgs   xn--chec-9oa.example.orgN)r   rB   r@   rA   r6   rb   domainr3   s   &r   test_unicodeDomain$SRVConnectorTests.test_unicodeDomain   sE    
 $00LL-)A4<<
 	4dnn6K6KLr   c                   \         P                  ! ^
^
RR4      p\         P                  ! ^
^RR4      pW.V P                  n        . V P                  n        V P                  \        RV P                  4       ^^ .V n        V P                  P                  4        V P                  V P                  ^ ,          R4       V P                  P                  4        V P                  V P                  ^,          R4       ^
^ .V n        V P                  P                  4        V P                  V P                  ^,          R4       V P                  P                  4        V P                  V P                  ^,          R4       R# )	z
pickServer calculates running sum of weights and calls randint.

This exercises the server selection algorithm specified in RFC 2782 by
preparing fake L{random.randint} results and checking the values it was
called with.
rp   host1.example.orghost2.example.orgrandintN)       )r   
   )r      )r
   r\   r6   orderedServersserversr?   randomrK   rD   
pickServerrb   rC   r   record1record2s   &  r   test_pickServerWeights(SRVConnectorTests.test_pickServerWeights   s%    ..R/BC..R/BC)0(:%!#

69dmm4  "1g!!#))!,g6!!#))!,g6  "1g!!#))!,g6!!#))!,g6r   c                   \         P                  ! ^
^
RR4      p\         P                  ! ^
^RR4      pW!.V P                  n        . V P                  n        V P                  \        RV P                  4       ^ ^ .V n        V P                  RV P                  P                  4       4       V P                  RV P                  P                  4       4       R# )zB
Two records with equal priorities compare on weight (ascending).
rp   r   r   r   Nr   rp   r   rp   r
   r\   r6   r   r   r?   r   rK   rD   rb   r   r   s   &  r   test_pickServerSamePriorities/SRVConnectorTests.test_pickServerSamePriorities  s     ..R/BC..R/BC)0(:%!#

69dmm4 !f4dnn6O6O6QR4dnn6O6O6QRr   c                   \         P                  ! ^
^ RR4      p\         P                  ! ^^ RR4      pW!.V P                  n        . V P                  n        V P                  \        RV P                  4       ^ ^ .V n        V P                  RV P                  P                  4       4       V P                  RV P                  P                  4       4       R# )zH
Two records with differing priorities compare on priority (ascending).
rp   r   r   r   Nr   r   r   r   s   &  r   test_srvDifferentPriorities-SRVConnectorTests.test_srvDifferentPriorities  s     ..Q.AB..Q.AB)0(:%!#

69dmm4 !f4dnn6O6O6QR4dnn6O6O6QRr   )r6   rA   rC   rD   r@   N)r%   r&   r'   r(   r)   rE   rK   rN   re   ri   rl   rr   rw   r{   r   r   r   r   r   r   r*   r+   r,   s   @r   r:   r:   @   sc     !*&1X



S$L
 6 AM7BS S Sr   r:   )r)   r   zope.interface.verifyr   twisted.internetr   r   twisted.internet.errorr   r   twisted.internet.interfacesr   twisted.internet.testingr   twisted.namesr	   r
   r   twisted.names.commonr   twisted.names.errorr   twisted.trialr   r   ClientFactoryr/   TestCaser:    r   r   <module>r      sa   
  . , J 2 2 1 1 - , ",< ,:	8)) 	aS)) aSr   