
    Vh                        d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'  e#jP                         sdZ)ndZ) G d de      Z* G d d      Z+ G d d      Z, G d de'jZ                        Z. G d de'jZ                  e      Z/ G d de'jZ                        Z0 G d  d!e'jZ                        Z1 G d" d#e'jZ                        Z2 G d$ d%      Z3 G d& d'e'jZ                        Z4 G d( d)e'jZ                        Z5y)*z)
Test cases for L{twisted.names.client}.
    N)verifyClassverifyObject)defer)CannotListenErrorConnectionRefusedError)	IResolver)Clock)AlternateReactor)cacheclientdnserrorhosts)ResolverBase)DNSQueryTimeoutError)	test_util)GoodTempPathMixin)failure)FilePath)platform)proto_helpers)unittestz:These tests need more work before they'll work on Windows.c                       e Zd Zd Zy)FakeResolverc           
          |dk(  r>t        j                  |t         j                  |dt        j                  dd            }nt        j                  |||d      }|g}g }g }t	        j
                  |||f      S )z
        The getHostByNameTest does a different type of query that requires it
        return an A record from an ALL_RECORDS lookup, so we accommodate that
        here.
           getHostByNameTest<   	127.0.0.1)addressttl)nametypeclsr    payload)r!   r"   r#   r    )r   RRHeaderARecord_Ar   succeed)	selfr!   r#   qtypetimeoutrrresults	authority
additionals	            N/home/dcms/DCMS/lib/python3.12/site-packages/twisted/names/test/test_client.py_lookupzFakeResolver._lookup$   sv     ''UU[bAB 4e"EB$	
}}gy*=>>    N)__name__
__module____qualname__r1    r2   r0   r   r   #   s    ?r2   r   c                       e Zd ZdZdZd Zy)StubPortz
    A partial implementation of L{IListeningPort} which only keeps track of
    whether it has been stopped.

    @ivar disconnected: A C{bool} which is C{False} until C{stopListening} is
        called, C{True} afterwards.
    Fc                     d| _         y )NT)disconnectedr)   s    r0   stopListeningzStubPort.stopListeningF   s
     r2   N)r3   r4   r5   __doc__r:   r<   r6   r2   r0   r8   r8   ;   s     L!r2   r8   c                       e Zd ZdZd ZddZy)StubDNSDatagramProtocolz
    L{dns.DNSDatagramProtocol}-alike.

    @ivar queries: A C{list} of tuples giving the arguments passed to
        C{query} along with the L{defer.Deferred} which was returned from
        the call.
    c                 0    g | _         t               | _        y Nqueriesr8   	transportr;   s    r0   __init__z StubDNSDatagramProtocol.__init__S       !r2   Nc                 n    t        j                         }| j                  j                  |||||f       |S )zv
        Record the given arguments and return a Deferred which will not be
        called back by this code.
        )r   DeferredrC   append)r)   r   rC   r+   idresults         r0   queryzStubDNSDatagramProtocol.queryW   s2    
 !WgwFCDr2   
   N)r3   r4   r5   r=   rE   rL   r6   r2   r0   r?   r?   J   s    $r2   r?   c                        e Zd ZdZeZd Zd Zy)GetResolverTestsz*
    Tests for L{client.getResolver}.
    c                     t        t                     5  t        j                         }ddd       | j	                  t        t                     y# 1 sw Y   )xY w)zQ
        L{client.getResolver} returns an object providing L{IResolver}.
        N)r
   r	   r   getResolver
assertTruer   r   r)   resolvers     r0   test_interfacezGetResolverTests.test_interfaceh   sD     eg& 	,))+H	,Y9:	, 	,s   AAc                     t        t                     5  t        j                         }t        j                         }ddd       | j	                         y# 1 sw Y   xY w)zn
        Multiple calls to L{client.getResolver} return the same L{IResolver}
        implementation.
        N)r
   r	   r   rR   assertIs)r)   abs      r0   test_idempotentz GetResolverTests.test_idempotentp   sO    
 eg& 	%""$A""$A	% 	a	% 	%s   )AA!N)r3   r4   r5   r=   windowsSkipskiprV   r[   r6   r2   r0   rP   rP   a   s     D;r2   rP   c                   P    e Zd ZdZeZd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zy)CreateResolverTestsz-
    Tests for L{client.createResolver}.
    c                     |j                   D cg c]  }t        |t        j                        s|! }}| j	                  dt        |             | j	                  |d   j                  |       y c c}w )N   r   )	resolvers
isinstancer   ResolverassertEquallenfiler)   rU   filenamerress        r0   
_hostsTestzCreateResolverTests._hostsTest   sZ    ",,NQ
1enn0MqNNCH%Qh/ O
   A0A0c                     t        t                     5  t        j                         }ddd       | j	                  d       y# 1 sw Y   xY w)z
        L{client.createResolver} returns a L{resolve.ResolverChain} including a
        L{hosts.Resolver} using I{/etc/hosts} if no alternate hosts file is
        specified.
        Ns
   /etc/hostsr
   r	   r   createResolverrl   rT   s     r0   test_defaultHostsz%CreateResolverTests.test_defaultHosts   s?     eg& 	/,,.H	/-0	/ 	/   AAc                     t        t                     5  t        j                  d      }ddd       | j	                  d       y# 1 sw Y   xY w)z
        The I{hosts} parameter to L{client.createResolver} overrides the hosts
        file used by the L{hosts.Resolver} in the L{resolve.ResolverChain} it
        returns.
           /foo/bar)r   Nro   rT   s     r0   test_overrideHostsz&CreateResolverTests.test_overrideHosts   sE     eg& 	@,,;?H	@+.	@ 	@   AAc                     |j                   D cg c]  }t        |t        j                        s|! }}| j	                  dt        |             | j	                  |d   j                  |       yc c}w )z|
        Verify that C{resolver} has a L{client.Resolver} with a configuration
        filename set to C{filename}.
        ra   r   N)rb   rc   r   rd   re   rf   resolvrh   s        r0   _resolvConfTestz#CreateResolverTests._resolvConfTest   s\    
 #,,OQ
1foo0NqOOCH%Q1 Prm   c                 f   t               }t        |      5  t        j                         }ddd       j                  D cg c]  }t        |t        j                        s|! }}| j                  dt        |             | j                  ||d   j                         y# 1 sw Y   xxY wc c}w )z
        The L{client.Resolver} included in the L{resolve.ResolverChain} returned
        by L{client.createResolver} uses the global reactor.
        Nra   r   )r	   r
   r   rp   rb   rc   rd   re   rf   rX   _reactor)r)   reactorrU   rj   rk   s        r0   test_reactorz CreateResolverTests.test_reactor   s    
 'g& 	/,,.H	/",,OQ
1foo0NqOOCH%gs1v/		/ 	/Os   B"B.!B."B+c                     t        t                     5  t        j                         }ddd       | j	                  d       y# 1 sw Y   xY w)z
        L{client.createResolver} returns a L{resolve.ResolverChain} including a
        L{client.Resolver} using I{/etc/resolv.conf} if no alternate resolver
        configuration file is specified.
        Ns   /etc/resolv.confr
   r	   r   rp   ry   rT   s     r0   test_defaultResolvConfz*CreateResolverTests.test_defaultResolvConf   sB     eg& 	/,,.H	/X':;	/ 	/rr   c                     t        t                     5  t        j                  d      }ddd       | j	                  d       y# 1 sw Y   xY w)z
        The I{resolvconf} parameter to L{client.createResolver} overrides the
        resolver configuration file used by the L{client.Resolver} in the
        L{resolve.ResolverChain} it returns.
        rt   
resolvconfNr   rT   s     r0   test_overrideResolvConfz+CreateResolverTests.test_overrideResolvConf   sG     eg& 	E,,DH	EX{3	E 	Erv   c                    | j                         }|j                  d       t        t                     5  t	        j
                  |j                         }ddd       j                  D cg c]  }t        |t        j                        s|! }}| j                  dt        |             | j                  g |d   j                         | j                  dg|d   j                         y# 1 sw Y   xY wc c}w )z
        If no servers are given, addresses are taken from the file given by the
        I{resolvconf} parameter to L{client.createResolver}.
           nameserver 127.1.2.3
r   Nra   r   z	127.1.2.35   path
setContentr
   r	   r   rp   rb   rc   rd   re   rf   servers
dynServersr)   r   rU   rj   rk   s        r0   test_defaultServersz'CreateResolverTests.test_defaultServers   s    
 YY[
78eg& 	I,,
HH	I",,OQ
1foo0NqOOCH%SV^^,+,c!f.?.?@	I 	IOs   !C-,C9C9-C6c                    | j                         }|j                  d       t        t                     5  t	        j
                  dg|j                         }ddd       j                  D cg c]  }t        |t        j                        s|! }}| j                  dt        |             | j                  dg|d   j                         | j                  dg|d   j                         y# 1 sw Y   xY wc c}w )z
        Servers passed to L{client.createResolver} are used in addition to any
        found in the file given by the I{resolvconf} parameter.
        r   )z	127.3.2.1r   )r   r   Nra   r   r   r   r   s        r0   test_overrideServersz(CreateResolverTests.test_overrideServers   s    
 YY[
78eg& 	,,*+
H	 #,,OQ
1foo0NqOOCH%+,c!fnn=+,c!f.?.?@	 	 Ps   #C0.C<C<0C9c                 $   t        t                     5  t        j                         }ddd       j                  D cg c]  }t        |t        j                        s|! }}| j                  dt        |             y# 1 sw Y   YxY wc c}w )zy
        L{client.createResolver} returns a L{resolve.ResolverChain} including a
        L{cache.CacheResolver}.
        Nra   )
r
   r	   r   rp   rb   rc   r   CacheResolverre   rf   )r)   rU   rj   rk   s       r0   
test_cachezCreateResolverTests.test_cache   so    
 eg& 	/,,.H	/",,SQ
1e>Q>Q0RqSSCH%	/ 	/Ss   BBBB
N)r3   r4   r5   r=   r\   r]   rl   rq   ru   ry   r}   r   r   r   r   r   r6   r2   r0   r_   r_   {   sB     D0
1/2
0<4AA &r2   r_   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)ResolverTestsz'
    Tests for L{client.Resolver}.
    c                 ,    t        t        t               y)z]
        L{client} provides L{IResolver} through a series of free
        functions.
        N)r   r   r   r;   s    r0   test_clientProvidesIResolverz*ResolverTests.test_clientProvidesIResolver   s    
 	Y'r2   c                 @    t        t        t        j                         y)z;
        L{client.Resolver} provides L{IResolver}.
        N)r   r   r   rd   r;   s    r0   $test_clientResolverProvidesIResolverz2ResolverTests.test_clientResolverProvidesIResolver   s     	Iv/r2   c                 L    | j                  t        t        j                         y)z
        L{client.Resolver} raises L{ValueError} if constructed with neither
        servers nor a nameserver configuration file.
        N)assertRaises
ValueErrorr   rd   r;   s    r0   test_noServerszResolverTests.test_noServers   s    
 	*foo6r2   c                     t        j                  | j                         t                     }| j	                  dg|j
                         y)z
        A missing nameserver configuration file results in no server information
        being loaded from it (ie, not an exception) and a default server being
        provided.
        rx   r|   r   r   N)r   rd   mktempr	   re   r   rT   s     r0   test_missingConfigurationz'ResolverTests.test_missingConfiguration  s6     ??$++-I+,h.A.ABr2   c                     t        | j                               }|j                  d       G fddt        j                        } |ddgdt                      | j                  j                         y	)
z
        As part of its constructor, C{StubResolver} opens C{/etc/resolv.conf};
        then, explicitly closes it and does not count on the GC to do so for
        it.
        zw+)modec                       e Zd Z fdZy)9ResolverTests.test_closesResolvConf.<locals>.StubResolverc                     S rA   r6   )r)   r!   
resolvConfs     r0   	_openFilezCResolverTests.test_closesResolvConf.<locals>.StubResolver._openFile  s	    !!r2   N)r3   r4   r5   r   )r   s   r0   StubResolverr     s    "r2   r   example.comr   z/etc/resolv.conf)r   rx   r|   N)r   r   openr   rd   r	   rS   closed)r)   handler   r   s      @r0   test_closesResolvConfz#ResolverTests.test_closesResolvConf  sb     $++-([[d[+
	"6?? 	" 	"B'0BEG	
 	
))*r2   c                     t        j                  dg      }|j                  dg       | j                  d|j                         y)z
        L{client.Resolver.parseConfig} treats a I{domain} line without an
        argument as indicating a domain of C{b""}.
        r   r   s   domain
r2   N)r   rd   parseConfigre   domainrT   s     r0   test_domainEmptyArgumentz&ResolverTests.test_domainEmptyArgument!  s:    
 ??,=+>?k]+hoo.r2   c                     t        j                  dg      }|j                  dg       | j                  g |j                         y)z
        L{client.Resolver.parseConfig} treats a I{search} line without an
        argument as indicating an empty search suffix.
        r   r   s   search
N)r   rd   r   re   searchrT   s     r0   test_searchEmptyArgumentz&ResolverTests.test_searchEmptyArgument*  s:    
 ??,=+>?k]+X__-r2   c                 v   t               ddg}ddg}t        j                  |      }||_        fd|_        t               }|j                  d      }|j                  | j                  |       | j                  t        j                        d       | j                  j                  d	   d	   |d	          j                  d	   d
   j                  t        d	             | j                  t        j                        d       | j                  j                  d   d	   |d          j                  d   d
   j                  t        d             | j                  t        j                        d       | j                  j                  d   d	   |d	          j                  d   d
   j                  t        d             | j                  t        j                        d       | j                  j                  d   d	   |d          j                  d   d
   j                  |       |S )a  
        L{client.Resolver.queryUDP} should issue queries to its
        L{dns.DNSDatagramProtocol} with server addresses taken from its own
        C{servers} and C{dynServers} lists, proceeding through them in order
        as L{DNSQueryTimeoutError}s occur.
        z::1r   )z::2r   )z::3r   )z::4r   r   c                     S rA   r6   )	interfaceprotocols    r0   <lambda>z=ResolverTests.test_datagramQueryServerOrder.<locals>.<lambda>@  s     r2   Nra   r            )r?   r   rd   r   _connectedProtocolobjectqueryUDPaddCallbackre   rf   rC   rX   errbackr   callback)r)   r   r   rU   expectedResultqueryResultr   s         @r0   test_datagramQueryServerOrderz+ResolverTests.test_datagramQueryServerOrder3  s    +,,!;/
??73(&@#''- 0 0.AX--.2h&&q)!,gaj9B''(<Q(?@X--.2h&&q)!,gaj9B''(<Q(?@X--.2h&&q)!,jm<B''(<Q(?@X--.2h&&q)!,jm<B((8r2   c                    	
 t               
t        j                  dg      }
fd|_        
j                  }t        j                  dt
        j                  t
        j                        }|j                  |      } j                  t        |      d       |j                  |      } j                  t        |      d       t               	t        j                         }|j                  j                  	       |j!                         d   j#                  |       t%        j&                  ||g      }	 fd}|j)                  |       |S )z
        L{client.Resolver.query} only issues one request at a time per query.
        Subsequent requests made before responses to prior ones are received
        are queued and given the same response as is given to the first one.
        r   r   r   c                       S rA   r6   r   s   r0   r   z<ResolverTests.test_singleConcurrentRequest.<locals>.<lambda>]      h r2      foo.example.comra   r   c                 h    | \  }}j                  |gg g f       j                  |gg g f       y rA   re   )	responsesfirstResponsesecondResponseanswerr)   s      r0   
cbFinishedz>ResolverTests.test_singleConcurrentRequest.<locals>.cbFinishedr  s?    ,5)M>]fXr2,>?^vhB-?@r2   )r?   r   rd   r   rC   r   Queryr&   INrL   re   rf   r   MessageanswersrI   popr   r   gatherResultsr   )r)   rU   rC   rL   firstResultsecondResultresponsedr   r   r   s   `        @@r0   test_singleConcurrentRequestz*ResolverTests.test_singleConcurrentRequestU  s    +,??,?+@A&6#""		,ceeSVV<nnU+Wq)  ~~e,Wq) ;;='b""8,l ;<	A
 	
j!r2   c                 T   t               t        j                  dg      }fd|_        j                  }t        j                  dt
        j                        }|j                  |       | j                  t        |      d       t        j                  dt
        j                        }|j                  |       | j                  t        |      d       t        j                  dt
        j                        }|j                  |       | j                  t        |      d       y	)
zh
        L{client.Resolver.query} issues a request for each different concurrent
        query.
        r   r   c                       S rA   r6   r   s   r0   r   z?ResolverTests.test_multipleConcurrentRequests.<locals>.<lambda>  r   r2   r   ra      bar.example.comr   r   N)r?   r   rd   r   rC   r   r   r&   rL   re   rf   A6)r)   rU   rC   
firstQuerysecondQuery
thirdQueryr   s         @r0   test_multipleConcurrentRequestsz-ResolverTests.test_multipleConcurrentRequestsz  s    
 +,??,?+@A&6#"" YY13559
z"Wq) ii 2CEE:{#Wq) YY1366:
z"Wq)r2   c                    t               t        j                  dg      }fd|_        j                  }t        j                  dt
        j                        }|j                  |       | j                  t        |      d       |j                         d   j                  t        j                                |j                  |       | j                  t        |      d       y)z
        After a response is received to a query issued with
        L{client.Resolver.query}, another query with the same parameters
        results in a new network request.
        r   r   c                       S rA   r6   r   s   r0   r   z?ResolverTests.test_multipleSequentialRequests.<locals>.<lambda>  r   r2   r   ra   r   N)r?   r   rd   r   rC   r   r   r&   rL   re   rf   r   r   r   )r)   rU   rC   rL   r   s       @r0   test_multipleSequentialRequestsz-ResolverTests.test_multipleSequentialRequests  s     +,??,?+@A&6#""		,cee4 	uWq) 	b""3;;=1 	uWq)r2   c                    t               t        j                  dg      }fd|_        j                  }t        j                  dt
        j                        }|j                  |      }|j                  |      } G d dt              }|j                         d   j                  t        j                   |                    t        j                  | j!                  ||      | j!                  ||      g      S )z
        If the result of a request is an error response, the Deferreds for all
        concurrently issued requests associated with that result fire with the
        L{Failure}.
        r   r   c                       S rA   r6   r   s   r0   r   z>ResolverTests.test_multipleConcurrentFailure.<locals>.<lambda>  r   r2   r   c                       e Zd Zy)GResolverTests.test_multipleConcurrentFailure.<locals>.ExpectedExceptionNr3   r4   r5   r6   r2   r0   ExpectedExceptionr         r2   r   r   )r?   r   rd   r   rC   r   r   r&   rL   	Exceptionr   r   r   Failurer   r   assertFailure)r)   rU   rC   rL   r   r   r   r   s          @r0   test_multipleConcurrentFailurez,ResolverTests.test_multipleConcurrentFailure  s     +,??,?+@A&6#""		,cee4nnU+~~e,		 	 	b!!'//2C2E"FG"""";0AB""<1BC
 	
r2   c                 R   t        j                  dg      }|j                         }|j                         }| j                  |j                         | j                  |j                         | j                  |j                  j                         j                  |j                  j                         j                         t        j                  t        j                  |j                  j                        t        j                  |j                  j                        g      S )z
        L{client.Resolver._connectedProtocol} returns a new
        L{DNSDatagramProtocol} connected to a new address with a
        cryptographically secure random port number.
        r   r   )r   rd   r   assertIsNotNonerD   assertNotEqualgetHostportr   r   maybeDeferredr<   )r)   rU   
firstProtosecondProtos       r0   test_connectedProtocolz$ResolverTests.test_connectedProtocol  s     ??,?+@A002
113Z112[223  ((*//1F1F1N1N1P1U1U	
 ""##J$8$8$F$FG##K$9$9$G$GH
 	
r2   c                     t        j                         }t        j                  | j	                         |      }|j                         }| j                  |j                  |       y)z
        If a reactor instance is supplied to L{client.Resolver}
        L{client.Resolver._connectedProtocol} should pass that reactor
        to L{twisted.names.dns.DNSDatagramProtocol}.
        r   N)r   MemoryReactorr   rd   r   r   rX   r{   )r)   r|   rU   protos       r0   )test_resolverUsesOnlyParameterizedReactorz7ResolverTests.test_resolverUsesOnlyParameterizedReactor  sH     ))+??$++-I++-enng.r2   c                 6   t        j                  dg      }g  G fdd      }||_        |j                  t	        j
                  d             |j                  t	        j
                  d             | j                  t        t                    d       y)	z
        L{client.Resolver._connectedProtocol} is called once each time a UDP
        request needs to be issued and the resulting protocol instance is used
        for that request.
        r   r   c                        e Zd Zd Zd fd	Zy):ResolverTests.test_differentProtocol.<locals>.FakeProtocolc                 "    t               | _        y rA   r8   rD   r;   s    r0   rE   zCResolverTests.test_differentProtocol.<locals>.FakeProtocol.__init__      !)r2   Nc                 t    j                  |        t        j                  t        j                               S rA   )rI   r   r(   r   r   )r)   r   rL   r+   rJ   	protocolss        r0   rL   z@ResolverTests.test_differentProtocol.<locals>.FakeProtocol.query  s&      &}}S[[]33r2   rM   r3   r4   r5   rE   rL   )r  s   r0   FakeProtocolr	    s    ,4r2   r  r   r   r   N)	r   rd   r   rL   r   r   re   rf   set)r)   rU   r  r  s      @r0   test_differentProtocolz$ResolverTests.test_differentProtocol  su     ??,?+@A		4 	4 '3#syy!345syy!345S^,a0r2   c                 :   t        j                         }t        j                  dg|      }|j	                  t        j                  d             |j                  j                         \  \  }}|j                         j                  }| j                  d|       y)z<
        If the resolver is ipv6, open a ipv6 port.
        r   r   r|   r   z::N)r   r  r   rd   rL   r   r   udpPortsitemsr   hostre   )r)   fakerU   r  rD   r   s         r0   test_ipv6ResolverzResolverTests.test_ipv6Resolver   sx    
 &&(??K=$Gsyy!345#}}224	%%%',,	y)r2   c                     g  G fdd      }t        j                  dg      } |       |_        |j                          | j	                  t        t                    d       y)z
        If a port number is initially selected which cannot be bound, the
        L{CannotListenError} is handled and another port number is attempted.
        c                       e Zd Z fdZy)6ResolverTests.test_disallowedPort.<locals>.FakeReactorc                 ^    j                  |       t              dk(  rt        d |d       y )Nra   )rI   rf   r   r)   r   argskwargsportss       r0   	listenUDPz@ResolverTests.test_disallowedPort.<locals>.FakeReactor.listenUDP  s.    T"u:?+D$== #r2   Nr3   r4   r5   r"  r!  s   r0   FakeReactorr    s    >r2   r%  r   r   r   N)r   rd   r{   r   re   rf   r  r)   r%  rU   r!  s      @r0   test_disallowedPortz!ResolverTests.test_disallowedPort  sV    
 	> 	> ??,?+@A'M##%SZ!,r2   c                     g  G fdd      }t        j                  dg      } |       |_        | j                  t        |j
                         | j                  t              d       y)z
        If port numbers that cannot be bound are repeatedly selected,
        L{resolver._connectedProtocol} will give up eventually.
        c                       e Zd Z fdZy)@ResolverTests.test_disallowedPortRepeatedly.<locals>.FakeReactorc                 @    j                  |       t        d |d       rA   )rI   r   r  s       r0   r"  zJResolverTests.test_disallowedPortRepeatedly.<locals>.FakeReactor.listenUDP'  s    T"'dD99r2   Nr#  r$  s   r0   r%  r*  &  s    :r2   r%  r   r   i  N)r   rd   r{   r   r   r   re   rf   r&  s      @r0   test_disallowedPortRepeatedlyz+ResolverTests.test_disallowedPortRepeatedly  s]    
 	: 	:
 ??,?+@A'M+X-H-HIUT*r2   c                 F   g  G fdd      }t        j                  dg      } |       |_        | j                  t        |j
                        }| j                  |j                  j                  t        j                         | j                  t              d       y)zf
        If the process is out of files, L{Resolver._connectedProtocol}
        will give up.
        c                       e Zd Z fdZy)5ResolverTests.test_runOutOfFiles.<locals>.FakeReactorc                 t    j                  |       t        t        j                  d      }t	        d ||      )NzOut of files :()rI   OSErrorerrnoEMFILEr   )r)   r   r  r   errr!  s        r0   r"  z?ResolverTests.test_runOutOfFiles.<locals>.FakeReactor.listenUDP:  s/    T"ell,=>'dC88r2   Nr#  r$  s   r0   r%  r/  9  s    9r2   r%  r   r   ra   N)r   rd   r{   r   r   r   re   socketErrorr2  r3  rf   )r)   r%  rU   excr!  s       @r0   test_runOutOfFilesz ResolverTests.test_runOutOfFiles2  s    
 	9 	9 ??,?+@A'M 183N3NO 	..=UQ'r2   c                    t        j                  dg      }g t        j                  t	        j
                  t        d                  t        j                  t        j                               g G fdd      }||_
        |j                  t        j                  d             | j                  t        t                    d       y)z|
        When a query issued by L{client.Resolver.query} times out, the retry
        uses a new protocol instance.
        r   r   Nc                   "    e Zd Zd Zd fd	Zy)FResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocolc                 "    t               | _        y rA   r  r;   s    r0   rE   zOResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocol.__init__U  r  r2   Nc                 H    j                  |        j                  d      S Nr   rI   r   r)   r   rL   r+   rJ   r  r-   s        r0   rL   zLResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocol.queryX        &{{1~%r2   rM   r  r  r-   s   r0   r  r:  T      ,&r2   r  r   r   )r   rd   r   failr   r   r   r(   r   r   r   rL   r   re   rf   r  )r)   rU   r  r  r-   s      @@r0   "test_differentProtocolAfterTimeoutz0ResolverTests.test_differentProtocolAfterTimeoutH  s    
 ??,?+@A	JJw';D'ABCMM#++-(

	& 	& '3#syy!345S^,a0r2   c                    t        j                  dg      }g t        j                          G fdd      }||_        |j                  t        j                  d             | j                  d   j                  j                         j                  t        j                                | j                  d   j                  j                         y)z
        After the L{Deferred} returned by L{DNSDatagramProtocol.query} is
        called back, the L{DNSDatagramProtocol} is disconnected from its
        transport.
        r   r   c                   "    e Zd Zd Zd fd	Zy)9ResolverTests.test_protocolShutDown.<locals>.FakeProtocolc                 "    t               | _        y rA   r  r;   s    r0   rE   zBResolverTests.test_protocolShutDown.<locals>.FakeProtocol.__init__k  r  r2   Nc                 *    j                  |        S rA   rI   r)   r   rL   r+   rJ   r  rK   s        r0   rL   z?ResolverTests.test_protocolShutDown.<locals>.FakeProtocol.queryn        &r2   rM   r  r  rK   s   r0   r  rG  j      ,r2   r  r   r   N)r   rd   r   rH   r   rL   r   r   assertFalserD   r:   r   r   rS   )r)   rU   r  r  rK   s      @@r0   test_protocolShutDownz#ResolverTests.test_protocolShutDown`  s     ??,?+@A	!	 	 '3#syy!3451//<<=&	!..;;<r2   c                    t        j                  dg      }g t        j                         }t        j                  t        j                  t        d                  |g G fdd      }||_        |j                  t        j                  d             | j                  d   j                  j                         |j                  t        j                                 | j#                  d   j                  j                         y)z
        The L{DNSDatagramProtocol} created when an interim timeout occurs is
        also disconnected from its transport after the Deferred returned by its
        query method completes.
        r   r   Nc                   "    e Zd Zd Zd fd	Zy)EResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocolc                 "    t               | _        y rA   r  r;   s    r0   rE   zNResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocol.__init__  r  r2   Nc                 H    j                  |        j                  d      S r=  r>  r?  s        r0   rL   zKResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocol.query  r@  r2   rM   r  rA  s   r0   r  rS    rB  r2   r  r   ra   )r   rd   r   rH   rC  r   r   r   r   rL   r   r   rO  rD   r:   r   r   rS   )r)   rU   rK   r  r  r-   s       @@r0   !test_protocolShutDownAfterTimeoutz/ResolverTests.test_protocolShutDownAfterTimeouty  s     ??,?+@A	!::goo.B4.HIJFS	& 	& '3#syy!3451//<<=&	!..;;<r2   c                     G d dt               }t        j                  dg      }g t        j                          G fdd      }||_        |j                  t        j                  d            }| j                  d   j                  j                         j                  t        j                   |                    | j                  d   j                  j                         | j!                  ||      S )	z
        If the L{Deferred} returned by L{DNSDatagramProtocol.query} fires with
        a failure, the L{DNSDatagramProtocol} is still disconnected from its
        transport.
        c                       e Zd Zy)JResolverTests.test_protocolShutDownAfterFailure.<locals>.ExpectedExceptionNr   r6   r2   r0   r   rY    r   r2   r   r   r   c                   "    e Zd Zd Zd fd	Zy)EResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocolc                 "    t               | _        y rA   r  r;   s    r0   rE   zNResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocol.__init__  r  r2   Nc                 *    j                  |        S rA   rJ  rK  s        r0   rL   zKResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocol.query  rL  r2   rM   r  rM  s   r0   r  r[    rN  r2   r  r   r   )r   r   rd   r   rH   r   rL   r   r   rO  rD   r:   r   r   r   rS   r   )r)   r   rU   r  r   r  rK   s        @@r0   !test_protocolShutDownAfterFailurez/ResolverTests.test_protocolShutDownAfterFailure  s    		 	 ??,?+@A	!	 	 '3#nnSYY/A%BC1//<<=w'8':;<	!..;;<!!+/@AAr2   c                    t        j                  dg      }|j                  j                  d      }|j	                  d       | j                  ||j                         |j                  d       | j                  ||j                         y)z
        When a TCP DNS protocol associated with a Resolver disconnects, it is
        removed from the Resolver's connection list.
        r   r   N)	r   rd   factorybuildProtocolmakeConnectionassertInconnectionsconnectionLostassertNotIn)r)   rU   r   s      r0   (test_tcpDisconnectRemovesFromConnectionsz6ResolverTests.test_tcpDisconnectRemovesFromConnections  st    
 ??,?+@A##11$7%h 4 45 	%8#7#78r2   c                 ~   t        j                         }t        j                  dg|      }|j	                  t        j                  d            }|j                  d   \  }}}}} G d dt              }	|j                  |j                  d   t        j                   |	                    | j                  ||	       y)z
        The deferred returned by L{client.Resolver.queryTCP} will
        errback when the TCP connection attempt fails. The reason for
        the connection failure is passed as the argument to errback.
        z192.0.2.100r   r  r   r   c                       e Zd Zy)VResolverTests.test_singleTCPQueryErrbackOnConnectionFailure.<locals>.SentinelExceptionNr   r6   r2   r0   SentinelExceptionrk    r   r2   rl  N)r   r  r   rd   queryTCPr   r   
tcpClientsr   clientConnectionFailed
connectorsr   r   failureResultOf)
r)   r|   rU   r   r  r   r`  r+   bindAddressrl  s
             r0   -test_singleTCPQueryErrbackOnConnectionFailurez;ResolverTests.test_singleTCPQueryErrbackOnConnectionFailure  s      --/??,?+@'Rcii674;4F4Fq4I1dGWk		 	 	&&q!7??3D3F#G	
 	Q 12r2   c                    t        j                         }t        j                  dg|      }|j	                  t        j                  d            }|j	                  t        j                  d            }|j                  d   \  }}}}}	 G d dt              }
|j                  |j                  d   t        j                   |
                    | j                  ||
      }| j                  ||
      }| j                  ||       y)	z
        All pending L{resolver.queryTCP} C{deferred}s will C{errback}
        with the same C{Failure} if the connection attempt fails.
        ri  r  r   zexample.netr   c                       e Zd Zy)XResolverTests.test_multipleTCPQueryErrbackOnConnectionFailure.<locals>.SentinelExceptionNr   r6   r2   r0   rl  rv    r   r2   rl  N)r   r  r   rd   rm  r   r   rn  r   ro  rp  r   r   rq  rX   )r)   r|   rU   d1d2r  r   r`  r+   rr  rl  f1f2s                r0   /test_multipleTCPQueryErrbackOnConnectionFailurez=ResolverTests.test_multipleTCPQueryErrbackOnConnectionFailure  s    
  --/??,?+@'Rsyy78syy784;4F4Fq4I1dGWk		 	 	&&q!7??3D3F#G	
 !!"&78!!"&78b"r2   c                    t        j                         }t        j                  dg|      t	        j
                  d      j                        }fd}|j                  |       | j                  t        |j                        d       | j                  t        |j                        d       |j                  d   \  }}}}}t        j                  t                     }	|j                  |j                  d   |	       | j                  t        |j                        d       | j                  t        |j                        d       | j!                  |       t        j                  t                     }
|j                  |j                  d   |
       | j#                  |t              }| j%                  ||
       y)	z{
        An errback on the deferred returned by
        L{client.Resolver.queryTCP} may trigger another TCP query.
        )r   iE'  r  r   c                 P    | j                  t               j                        S rA   )trapr   rm  )eqrU   s    r0   reissuezOResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailure.<locals>.reissue  s!    FF)*$$Q''r2   ra   r   r   N)r   r  r   rd   r   r   rm  
addErrbackre   rf   rn  rp  r   r   r   ro  assertNoResultrq  rX   )r)   r|   r   r  r  r   r`  r+   rr  ry  rz  fr  rU   s               @@r0   0test_reentrantTCPQueryErrbackOnConnectionFailurez>ResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailure  sr   
  --/??,@+A7SIIm$ a 	( 	
WW//0!4W//0!44;4F4Fq4I1dGWk __356&&w'9'9!'<bA 	W//0!4W//0!4A __356&&w'9'9!'<bA   $:;ar2   c                 :   t        j                         }t        j                  dg|      }|j	                  t        j                  d            }|j                  d   \  }}}}}|j                  }	| j                  t        |	      d        G d dt              }
|j                  |j                  d   t        j                   |
                    | j!                  ||
       | j#                  |j                  |	       | j                  t        |	      d       y)	z
        When the TCP connection attempt fails, the
        L{client.Resolver.pending} list is emptied in place. It is not
        replaced with a new empty list.
        ri  r  r   r   ra   c                       e Zd Zy)JResolverTests.test_pendingEmptiedInPlaceOnError.<locals>.SentinelExceptionNr   r6   r2   r0   rl  r  '  r   r2   rl  N)r   r  r   rd   rm  r   r   rn  pendingre   rf   r   ro  rp  r   r   rq  rX   )r)   r|   rU   r   r  r   r`  r+   rr  
prePendingrl  s              r0   !test_pendingEmptiedInPlaceOnErrorz/ResolverTests.test_pendingEmptiedInPlaceOnError  s      --/??,?+@'Rcii674;4F4Fq4I1dGWk%%
Z!,		 	 	&&q!7??3D3F#G	
 	Q 12h&&
3Z!,r2   N) r3   r4   r5   r=   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r'  r,  r7  rD  rP  rV  r^  rg  rs  r{  r  r  r6   r2   r0   r   r      s    (07C+$/. D#J*6*0
6
.	/1,
*-&+&(,10=2=4B>93*.)V-r2   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)ClientTestsc                 F    t               t        _        d| _        d| _        y)z:
        Replace the resolver with a FakeResolver
           example.comr   N)r   r   theResolverhostnamehostnameForGetHostByNamer;   s    r0   setUpzClientTests.setUp4  s     *^&(<%r2   c                     dt         _        y)zp
        By setting the resolver to None, it will be recreated next time a name
        lookup is done.
        N)r   r  r;   s    r0   tearDownzClientTests.tearDown<  s    
 "r2   c                     |\  }}}|d   }| j                  |j                  j                  | j                         | j                  |j                  |       y)zT
        Verify that the result is the same query type as what is expected.
        r   N)re   r!   r  r"   )r)   r-   r*   r   r.   r/   rK   s          r0   checkResultzClientTests.checkResultC  sK     *1&J))4==9e,r2   c                 (    | j                  |d       y)zR
        Test that the getHostByName query returns the 127.0.0.1 address.
        r   Nr   r)   rK   s     r0   checkGetHostByNamezClientTests.checkGetHostByNameL  s     	-r2   c                 z    t        j                  | j                        }|j                  | j                         |S )zM
        do a getHostByName of a value that should return 127.0.0.1.
        )r   getHostByNamer  r   r  r)   r   s     r0   test_getHostByNamezClientTests.test_getHostByNameR  s1       !>!>?	d--.r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S )z
        Do a lookup and test that the resolver will issue the correct type of
        query type. We do this by checking that FakeResolver returns a result
        record with the same query type as what we issued.
        )r   lookupAddressr  r   r  r   r&   r  s     r0   test_lookupAddresszClientTests.test_lookupAddressZ  s5       /	d&&.r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S z+
        See L{test_lookupAddress}
        )r   lookupIPV6Addressr  r   r  r   AAAAr  s     r0   test_lookupIPV6Addressz"ClientTests.test_lookupIPV6Addressd  s5     $$T]]3	d&&1r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupAddress6r  r   r  r   r   r  s     r0   test_lookupAddress6zClientTests.test_lookupAddress6l  s5     !!$--0	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupNameserversr  r   r  r   NSr  s     r0   test_lookupNameserversz"ClientTests.test_lookupNameserverst  s5     $$T]]3	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupCanonicalNamer  r   r  r   CNAMEr  s     r0   test_lookupCanonicalNamez$ClientTests.test_lookupCanonicalName|  s5     &&t}}5	d&&		2r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupAuthorityr  r   r  r   SOAr  s     r0   test_lookupAuthorityz ClientTests.test_lookupAuthority  s5     ""4==1	d&&0r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupMailBoxr  r   r  r   MBr  s     r0   test_lookupMailBoxzClientTests.test_lookupMailBox  s5       /	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupMailGroupr  r   r  r   MGr  s     r0   test_lookupMailGroupz ClientTests.test_lookupMailGroup  s5     ""4==1	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupMailRenamer  r   r  r   MRr  s     r0   test_lookupMailRenamez!ClientTests.test_lookupMailRename  s5     ##DMM2	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   
lookupNullr  r   r  r   NULLr  s     r0   test_lookupNullzClientTests.test_lookupNull  5     dmm,	d&&1r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupWellKnownServicesr  r   r  r   WKSr  s     r0   test_lookupWellKnownServicesz(ClientTests.test_lookupWellKnownServices  s5     **4==9	d&&0r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupPointerr  r   r  r   PTRr  s     r0   test_lookupPointerzClientTests.test_lookupPointer  5       /	d&&0r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupHostInfor  r   r  r   HINFOr  s     r0   test_lookupHostInfozClientTests.test_lookupHostInfo  s5     !!$--0	d&&		2r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupMailboxInfor  r   r  r   MINFOr  s     r0   test_lookupMailboxInfoz"ClientTests.test_lookupMailboxInfo  5     $$T]]3	d&&		2r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupMailExchanger  r   r  r   MXr  s     r0   test_lookupMailExchangez#ClientTests.test_lookupMailExchange  s5     %%dmm4	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   
lookupTextr  r   r  r   TXTr  s     r0   test_lookupTextzClientTests.test_lookupText  s5     dmm,	d&&0r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupSenderPolicyr  r   r  r   SPFr  s     r0   test_lookupSenderPolicyz#ClientTests.test_lookupSenderPolicy  s5     %%dmm4	d&&0r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupResponsibilityr  r   r  r   RPr  s     r0   test_lookupResponsibilityz%ClientTests.test_lookupResponsibility  s5     ''6	d&&/r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupAFSDatabaser  r   r  r   AFSDBr  s     r0   test_lookupAFSDatabasez"ClientTests.test_lookupAFSDatabase  r  r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupServicer  r   r  r   SRVr  s     r0   test_lookupServicezClientTests.test_lookupService  r  r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   
lookupZoner  r   r  r   AXFRr  s     r0   test_lookupZonezClientTests.test_lookupZone  r  r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupAllRecordsr  r   r  r   ALL_RECORDSr  s     r0   test_lookupAllRecordsz!ClientTests.test_lookupAllRecords  s5     ##DMM2	d&&8r2   c                     t        j                  | j                        }|j                  | j                  t
        j                         |S r  )r   lookupNamingAuthorityPointerr  r   r  r   NAPTRr  s     r0   !test_lookupNamingAuthorityPointerz-ClientTests.test_lookupNamingAuthorityPointer  s5     //>	d&&		2r2   c                     t        j                  | j                  t         j                        }t	        j
                  |      }|j                  | j                  t         j                         |S )a  
        L{client.query} accepts a L{dns.Query} instance and dispatches
        it to L{client.theResolver}.C{query}, which in turn dispatches
        to an appropriate C{lookup*} method of L{client.theResolver},
        based on the L{dns.Query} type.
        )r   r   r  r&   r   rL   r   r  )r)   r  r   s      r0   
test_queryzClientTests.test_query  sF     IIdmmSUU+LLO	d&&.r2   N) r3   r4   r5   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r6   r2   r0   r  r  3  s    ="-.
r2   r  c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)FilterAnswersTestsz|
    Test L{twisted.names.client.Resolver.filterAnswers}'s handling of various
    error conditions it might encounter.
    c                 <    t        j                  dg      | _        y )N)z0.0.0.0r   r   )r   rd   rU   r;   s    r0   r  zFilterAnswersTests.setUp'  s     0@Ar2   c                      t        j                  d      j                  d        fd}| j                  _         j                  j                        }|j                   j                  dgdgdgf       |S )zf
        Test that a truncated message results in an equivalent request made via
        TCP.
        T)truncr  c                     j                  | j                         t        j                         }dg|_        dg|_        dg|_        t        j                  |      S )Nr   r.   r/   )	re   rC   r   r   r   r.   r/   r   r(   )rC   r   mr)   s     r0   rm  z:FilterAnswersTests.test_truncatedMessage.<locals>.queryTCP4  sO    Waii0{{}H (zH"-H#/.H==**r2   r   r.   r/   )r   r   addQueryrU   rm  filterAnswersr   re   )r)   rm  r   r  s   `  @r0   test_truncatedMessagez(FilterAnswersTests.test_truncatedMessage,  sl    
 KKd#	

>"	+ "*MM''*	d&&(k]\N(STr2   c                     t        j                  |      }| j                  j                  |      }|j	                  |       y )N)rCode)r   r   rU   r  r~  )r)   rcoder6  r  r4  s        r0   
_rcodeTestzFilterAnswersTests._rcodeTestA  s/    KKe$mm))!,r2   c                 ^    | j                  t        j                  t        j                        S )z
        Test that a message with a result code of C{EFORMAT} results in a
        failure wrapped around L{DNSFormatError}.
        )r  r   EFORMATr   DNSFormatErrorr;   s    r0   test_formatErrorz#FilterAnswersTests.test_formatErrorF  s    
 s{{E,@,@AAr2   c                 ^    | j                  t        j                  t        j                        S )zP
        Like L{test_formatError} but for C{ESERVER}/L{DNSServerError}.
        )r  r   ESERVERr   DNSServerErrorr;   s    r0   test_serverErrorz#FilterAnswersTests.test_serverErrorM  s     s{{E,@,@AAr2   c                 ^    | j                  t        j                  t        j                        S )zL
        Like L{test_formatError} but for C{ENAME}/L{DNSNameError}.
        )r  r   ENAMEr   DNSNameErrorr;   s    r0   test_nameErrorz!FilterAnswersTests.test_nameErrorS  s     syy%*<*<==r2   c                 ^    | j                  t        j                  t        j                        S )zX
        Like L{test_formatError} but for C{ENOTIMP}/L{DNSNotImplementedError}.
        )r  r   ENOTIMPr   DNSNotImplementedErrorr;   s    r0   test_notImplementedErrorz+FilterAnswersTests.test_notImplementedErrorY  s     s{{E,H,HIIr2   c                 ^    | j                  t        j                  t        j                        S )zW
        Like L{test_formatError} but for C{EREFUSED}/L{DNSQueryRefusedError}.
        )r  r   EREFUSEDr   DNSQueryRefusedErrorr;   s    r0   test_refusedErrorz$FilterAnswersTests.test_refusedError_  s     s||U-G-GHHr2   c                 d    | j                  t        j                  dz   t        j                        S )zm
        Like L{test_formatError} but for an unrecognized error code and
        L{DNSUnknownError}.
        ra   )r  r   r  r   DNSUnknownErrorr;   s    r0   test_refusedErrorUnknownz+FilterAnswersTests.test_refusedErrorUnknowne  s$    
 s||a/1F1FGGr2   N)r3   r4   r5   r=   r  r  r  r  r  r  r  r   r#  r6   r2   r0   r   r   !  s:    
B
*
BB>JIHr2   r   c                        e Zd Zd ZddZd Zy)FakeDNSDatagramProtocolc                 0    g | _         t               | _        y rA   rB   r;   s    r0   rE   z FakeDNSDatagramProtocol.__init__n  rF   r2   Nc                     | j                   j                  ||||f       t        j                  t	        j
                  |            S rA   )rC   rI   r   rC  r   r   )r)   r   rC   r+   rJ   s        r0   rL   zFakeDNSDatagramProtocol.queryr  s7    Wgw;<zz%44W=>>r2   c                      y rA   r6   )r)   rJ   s     r0   removeResendz$FakeDNSDatagramProtocol.removeResendv  s    r2   rM   )r3   r4   r5   rE   rL   r)  r6   r2   r0   r%  r%  m  s    $?r2   r%  c                   *    e Zd ZdZg dZd Zd Zd Zy)RetryLogicTestszE
    Tests for query retrying implemented by L{client.Resolver}.
    )z1.2.3.4z4.3.2.1za.b.c.dzz.y.x.wc                 "   | j                   D cg c]  }|df }}t        j                  d|      }t               fd|_        |j                  d      j                  | j                        j                  | j                        S c c}w )a  
        When timeouts occur waiting for responses to queries, the next
        configured server is issued the query.  When the query has been issued
        to all configured servers, the timeout is increased and the process
        begins again at the beginning.
        r   N)rx   r   c                       S rA   r6   )r  s   r0   r   z8RetryLogicTests.test_roundRobinBackoff.<locals>.<lambda>  s    u r2   r   )
testServersr   rd   r%  r   r  r   _cbRoundRobinBackoffr  _ebRoundRobinBackoff)r)   xaddrsrj   r  s       @r0   test_roundRobinBackoffz&RetryLogicTests.test_roundRobinBackoff  s{     #'"2"23Q!R33OO47'),OO./[223Z1159	
	 4s   Bc                 &    | j                  d       y )Nz/Lookup address succeeded, should have timed out)rC  r  s     r0   r/  z$RetryLogicTests._cbRoundRobinBackoff  s    		CDr2   c                     |j                   t        j                         dD ]  }|j                  d t	        | j
                         }|j                  d t	        | j
                        = |j                          t        | j
                        }|j                          t        ||      D ]0  \  \  }}}}	}
| j                  ||
df       | j                  ||       2  | j                  |j                         y )N)ra   r      -   r   )r~  r   TimeoutErrorrC   rf   r.  sortlistzipre   rO  )r)   r   	fakeProtottriesexpectedaddrrL   r+   rJ   expectedAddrs              r0   r0  z$RetryLogicTests._ebRoundRobinBackoff  s    U''(
   
	-A%%&=D,<,<(=>E!!"9C(8(8$9"9:JJLD,,-HMMO<?x<P -8*ugrL  b'9:  !,-
	- 	**+r2   N)r3   r4   r5   r=   r.  r3  r/  r0  r6   r2   r0   r+  r+  {  s     ?K
"E,r2   r+  c                       e Zd ZdZd Zy)ThreadedResolverTestsz/
    Tests for L{client.ThreadedResolver}.
    c                    t        j                          | j                  | j                  g      }| j	                  |d   d   d       | j	                  |d   d   t
               | j	                  t        |      d       y)z
        L{client.ThreadedResolver} is deprecated.  Instantiating it emits a
        deprecation warning pointing at the code that does the instantiation.
        )offendingFunctionsr   messagezztwisted.names.client.ThreadedResolver is deprecated since Twisted 9.0, use twisted.internet.base.ThreadedResolver instead.categoryra   N)r   ThreadedResolverflushWarningstest_deprecatedre   DeprecationWarningrf   )r)   warningss     r0   rJ  z%ThreadedResolverTests.test_deprecated  s{    
 	!%%$:N:N9O%PQK	"	
 	!Z02DEX*r2   N)r3   r4   r5   r=   rJ  r6   r2   r0   rC  rC    s    +r2   rC  )6r=   r2  zope.interface.verifyr   r   twisted.internetr   twisted.internet.errorr   r   twisted.internet.interfacesr   twisted.internet.taskr	   #twisted.internet.test.modulehelpersr
   twisted.namesr   r   r   r   r   twisted.names.commonr   twisted.names.errorr   twisted.names.testr   twisted.names.test.test_hostsr   twisted.pythonr   twisted.python.filepathr   twisted.python.runtimer   twisted.testr   twisted.trialr   	isWindowsr\   r   r8   r?   TestCaserP   r_   r   r  r   r%  r+  rC  r6   r2   r0   <module>r_     s  
  ; " L 1 ' @ : : - 4 ( ; " , + & "xKNK?< ?0! ! .x(( 4o&(++-> o&dC	-H%% C	-Lk(## k\IH** IHX -,h'' -,`+H-- +r2   