+
    üÐ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ä—:’:˜dŸl™lÓ+Ð+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Ø�L‰L˜-¨¸¿¹ó
ˆŒð ˆÔØ ˆÖ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   ÚpayloadºNé   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™   € ô —.’. dÐ3EÈ2ÔNˆä�LŠLØ"¬¯©´c·f±fÀ"Ègôð&
Œ×ÑÔ"ð
 	�‰×ÑÔ à×Ñ˜$Ÿ,™,×-Ñ-Ô.Ø×Ñ˜Ÿ™×0Ñ0×4Ñ4Ó6°rÕ:Ð<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Œ×ÑÔ"Ø�‰×ÑÔ à×Ñ˜$Ÿ,™,×-Ñ-Ô.Ø×ÑØ�L‰L×#Ñ#×'Ñ'Ó)¨"Õ-Ð/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   € ð &(Œ×ÑÔ"Ø�‰×ÑÔ à×Ñ˜$Ÿ,™,×-Ñ-Ô.Ø×ÑØ�L‰L×#Ñ#×'Ñ'Ó)¨"Õ-Ð/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Ø�L‰LØ ØØ�L‰LØô
ˆŒô &=Ó%>Œ×ÑÔ"Ø�‰×ÑÔ à×Ñ˜$Ÿ,™,×-Ñ-Ô.Ø×Ñ˜Ÿ™×0Ñ0×4Ñ4Ó6°rÕ:Ð<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Ø�L‰LÐ.°¸t¿|¹|ó
ˆŒô &=Ó%>Œ×ÑÔ"Ø�‰×ÑÔ à�‰˜Ÿ™×+Ñ+×1Ñ1Ô2IÓ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Š   € ô
 �LŠLØ"¬¯©¼¿¹ÀBÐPTôð&
Œ×ÑÔ"ð
 	�‰×ÑÔ à×Ñ˜$Ÿ,™,×-Ñ-Ô.Ø×ÑØ�L‰L×#Ñ#×'Ñ'Ó)¨"Õ-Ð/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¡   € ô —.’. d°4¸RÔ@ˆä�LŠLØ"¬¯©´c·f±fÀ"È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ˆØ×ÑÐ9¸4Ö@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Ø�L‰L˜-Ð)AÀ4Ç<Á<ó
ˆŒð 	×ÑÐ4°d·n±n×6KÑ6KÖ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Ð(:ˆ�‰Ô%Ø!#ˆ�‰ÔØ�
‰
”6˜9 d§m¡mÔ4ð  " 1˜gˆÔà�‰×!Ñ!Ô#Ø×Ñ˜×)Ñ)¨!Õ,¨gÔ6à�‰×!Ñ!Ô#Ø×Ñ˜×)Ñ)¨!Õ,¨gÔ6ð  " 1˜gˆÔà�‰×!Ñ!Ô#Ø×Ñ˜×)Ñ)¨!Õ,¨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Ð(:ˆ�‰Ô%Ø!#ˆ�‰ÔØ�
‰
”6˜9 d§m¡mÔ4Ø  !˜fˆÔà×ÑÐ4°d·n±n×6OÑ6OÓ6QÔRà×ÑÐ4°d·n±n×6OÑ6OÓ6QÖ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Ð(:ˆ�‰Ô%Ø!#ˆ�‰ÔØ�
‰
”6˜9 d§m¡mÔ4Ø  !˜fˆÔà×ÑÐ4°d·n±n×6OÑ6OÓ6QÔRà×ÑÐ4°d·n±n×6OÑ6OÓ6QÖ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ò7òB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   