
    tf                        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#j(                    sdZ)ndZ) G d de          Z* G d d          Z+ G d d          Z, G d de'j-                  Z. G d de'j-        e          Z/ G d de'j-                  Z0 G d  d!e'j-                  Z1 G d" d#e'j-                  Z2 G d$ d%          Z3 G d& d'e'j-                  Z4 G d( d)e'j-                  Z5dS )*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dS )FakeResolverc           
          |dk    r8t          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	            ]/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/names/test/test_client.py_lookupzFakeResolver._lookup$   s     '''U[bAAA  BB 4e"EE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dS )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| _         d S )NT)disconnectedr)   s    r0   stopListeningzStubPort.stopListeningF   s     r2   N)r3   r4   r5   __doc__r:   r<   r6   r2   r0   r8   r8   ;   s4          L! ! ! ! !r2   r8   c                        e Zd ZdZd ZddZdS )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                 :    g | _         t                      | _        d S Nqueriesr8   	transportr;   s    r0   __init__z StubDNSDatagramProtocol.__init__S       !r2   
   Nc                 j    t          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   s7    
 !!WgwFCDDDr2   rG   N)r3   r4   r5   r=   rE   rM   r6   r2   r0   r?   r?   J   sA         $ $ $     r2   r?   c                   "    e Zd ZdZeZd Zd ZdS )GetResolverTestsz*
    Tests for L{client.getResolver}.
    c                     t          t                                5  t          j                    }ddd           n# 1 swxY w Y   |                     t          t          |                     dS )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   s     egg&& 	, 	,)++H	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,Y99:::::   <A A c                     t          t                                5  t          j                    }t          j                    }ddd           n# 1 swxY w Y   |                     ||           dS )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   s    
 egg&& 	% 	%"$$A"$$A	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	as   'AAAN)r3   r4   r5   r=   windowsSkipskiprV   r\   r6   r2   r0   rP   rP   a   sC          D; ; ;    r2   rP   c                   R    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dS )CreateResolverTestsz-
    Tests for L{client.createResolver}.
    c                     d |j         D             }|                     dt          |                     |                     |d         j        |           d S )Nc                 F    g | ]}t          |t          j                  |S r6   )
isinstancer   Resolver.0rs     r0   
<listcomp>z2CreateResolverTests._hostsTest.<locals>.<listcomp>   s)    NNNQ
1en0M0MNqNNNr2      r   )	resolversassertEquallenfiler)   rU   filenameress       r0   
_hostsTestzCreateResolverTests._hostsTest   sV    NN(,NNNCHH%%%Qh/////r2   c                     t          t                                5  t          j                    }ddd           n# 1 swxY w Y   |                     |d           dS )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   createResolverrq   rT   s     r0   test_defaultHostsz%CreateResolverTests.test_defaultHosts   s     egg&& 	/ 	/,..H	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/-00000rW   c                     t          t                                5  t          j        d          }ddd           n# 1 swxY w Y   |                     |d           dS )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   Nrs   rT   s     r0   test_overrideHostsz&CreateResolverTests.test_overrideHosts   s     egg&& 	@ 	@,;???H	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@+.....   >AAc                     d |j         D             }|                     dt          |                     |                     |d         j        |           dS )z|
        Verify that C{resolver} has a L{client.Resolver} with a configuration
        filename set to C{filename}.
        c                 F    g | ]}t          |t          j                  |S r6   rc   r   rd   re   s     r0   rh   z7CreateResolverTests._resolvConfTest.<locals>.<listcomp>   )    OOOQ
1fo0N0NOqOOOr2   ri   r   N)rj   rk   rl   resolvrn   s       r0   _resolvConfTestz#CreateResolverTests._resolvConfTest   sY    
 PO(,OOOCHH%%%Q11111r2   c                 @   t                      }t          |          5  t          j                    }ddd           n# 1 swxY w Y   d |j        D             }|                     dt          |                     |                     ||d         j                   dS )z
        The L{client.Resolver} included in the L{resolve.ResolverChain} returned
        by L{client.createResolver} uses the global reactor.
        Nc                 F    g | ]}t          |t          j                  |S r6   r|   re   s     r0   rh   z4CreateResolverTests.test_reactor.<locals>.<listcomp>   r}   r2   ri   r   )	r	   r
   r   rt   rj   rk   rl   rY   _reactor)r)   reactorrU   rp   s       r0   test_reactorz CreateResolverTests.test_reactor   s    
 ''g&& 	/ 	/,..H	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/OO(,OOOCHH%%%gs1v/////s   >AAc                     t          t                                5  t          j                    }ddd           n# 1 swxY w Y   |                     |d           dS )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   rt   r   rT   s     r0   test_defaultResolvConfz*CreateResolverTests.test_defaultResolvConf   s     egg&& 	/ 	/,..H	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/X':;;;;;rW   c                     t          t                                5  t          j        d          }ddd           n# 1 swxY w Y   |                     |d           dS )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.
        rw   
resolvconfNr   rT   s     r0   test_overrideResolvConfz+CreateResolverTests.test_overrideResolvConf   s     egg&& 	E 	E,DDDH	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	EX{33333ry   c                    |                                  }|                    d           t          t                                5  t	          j        |j                   }ddd           n# 1 swxY w Y   d |j        D             }|                     dt          |                     |                     g |d         j	                   |                     dg|d         j
                   dS )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   Nc                 F    g | ]}t          |t          j                  |S r6   r|   re   s     r0   rh   z;CreateResolverTests.test_defaultServers.<locals>.<listcomp>   r}   r2   ri   r   z	127.1.2.35   path
setContentr
   r	   r   rt   rj   rk   rl   servers
dynServersr)   r   rU   rp   s       r0   test_defaultServersz'CreateResolverTests.test_defaultServers   s(   
 YY[[
7888egg&& 	I 	I,
HHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	IOO(,OOOCHH%%%SV^,,,+,c!f.?@@@@@s   A,,A03A0c                    |                                  }|                    d           t          t                                5  t	          j        dg|j                   }ddd           n# 1 swxY w Y   d |j        D             }|                     dt          |                     |                     dg|d         j	                   |                     dg|d         j
                   dS )	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   Nc                 F    g | ]}t          |t          j                  |S r6   r|   re   s     r0   rh   z<CreateResolverTests.test_overrideServers.<locals>.<listcomp>   r}   r2   ri   r   r   r   r   s       r0   test_overrideServersz(CreateResolverTests.test_overrideServers   s*   
 YY[[
7888egg&& 	 	,*+
  H	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 PO(,OOOCHH%%%+,c!fn===+,c!f.?@@@@@s   A..A25A2c                     t          t                                5  t          j                    }ddd           n# 1 swxY w Y   d |j        D             }|                     dt          |                     dS )zy
        L{client.createResolver} returns a L{resolve.ResolverChain} including a
        L{cache.CacheResolver}.
        Nc                 F    g | ]}t          |t          j                  |S r6   )rc   r   CacheResolverre   s     r0   rh   z2CreateResolverTests.test_cache.<locals>.<listcomp>   s*    SSSQ
1e>Q0R0RSqSSSr2   ri   )r
   r	   r   rt   rj   rk   rl   )r)   rU   rp   s      r0   
test_cachezCreateResolverTests.test_cache   s    
 egg&& 	/ 	/,..H	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/SS(,SSSCHH%%%%%rW   N)r3   r4   r5   r=   r]   r^   rq   ru   rx   r   r   r   r   r   r   r   r6   r2   r0   r`   r`   {   s          D0 0 0
1 1 1/ / /2 2 2
0 
0 
0< < <4 4 4A A AA 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dS )ResolverTestsz'
    Tests for L{client.Resolver}.
    c                 :    t          t          t                     dS )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                 D    t          t          t          j                   dS )z;
        L{client.Resolver} provides L{IResolver}.
        N)r   r   r   rd   r;   s    r0   $test_clientResolverProvidesIResolverz2ResolverTests.test_clientResolverProvidesIResolver   s     	Iv/////r2   c                 P    |                      t          t          j                   dS )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"    
 	*fo66666r2   c                     t          j        |                                 t                                }|                     dg|j                   dS )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.
        r~   r   r   r   N)r   rd   mktempr	   rk   r   rT   s     r0   test_missingConfigurationz'ResolverTests.test_missingConfiguration  sG     ?$++--III+,h.ABBBBBr2   c                    t          |                                           }|                    d           G fddt          j                  } |ddgdt                                 |                     j                   d	S )
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dS )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   r~   r   N)r   r   openr   rd   r	   rS   closed)r)   handler   r   s      @r0   test_closesResolvConfz#ResolverTests.test_closesResolvConf  s     $++--(([[d[++
	" 	" 	" 	" 	" 	" 	"6? 	" 	" 	" 	"B'0BEGG	
 	
 	
 	
 	
)*****r2   c                     t          j        dg          }|                    dg           |                     d|j                   dS )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   parseConfigrk   domainrT   s     r0   test_domainEmptyArgumentz&ResolverTests.test_domainEmptyArgument!  sN    
 ?,=+>???k]+++ho.....r2   c                     t          j        dg          }|                    dg           |                     g |j                   dS )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   rk   searchrT   s     r0   test_searchEmptyArgumentz&ResolverTests.test_searchEmptyArgument*  sN    
 ?,=+>???k]+++X_-----r2   c                 "   t                      ddg}ddg}t          j        |          }||_        fd|_        t                      }|                    d          }|                    | j        |           |                     t          j
                  d           |                     j
        d	         d	         |d	                    j
        d	         d
                             t          d	                     |                     t          j
                  d           |                     j
        d         d	         |d                    j
        d         d
                             t          d                     |                     t          j
                  d           |                     j
        d         d	         |d	                    j
        d         d
                             t          d                     |                     t          j
                  d           |                     j
        d         d	         |d                    j
        d         d
                             |           |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   Nri   r            )r?   r   rd   r   _connectedProtocolobjectqueryUDPaddCallbackrk   rl   rC   rY   errbackr   callback)r)   r   r   rU   expectedResultqueryResultr   s         @r0   test_datagramQueryServerOrderz+ResolverTests.test_datagramQueryServerOrder3  sA    +,,,!;/
?7333(&@&@&@&@#''-- 0.AAAX-..222h&q)!,gaj999B''(<Q(?(?@@@X-..222h&q)!,gaj999B''(<Q(?(?@@@X-..222h&q)!,jm<<<B''(<Q(?(?@@@X-..222h&q)!,jm<<<B((888r2   c                    	
 t                      
t          j        dg          }
fd|_        
j        }t          j        dt
          j        t
          j                  }|	                    |          } 
                    t          |          d           |	                    |          } 
                    t          |          d           t                      	t          j                    }|j                            	           |                                d                             |           t%          j        ||g          }	 fd}|                    |           |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.comri   r   c                 z    | \  }}                     |gg g f                                |gg g f           d S rA   rk   )	responsesfirstResponsesecondResponseanswerr)   s      r0   
cbFinishedz>ResolverTests.test_singleConcurrentRequest.<locals>.cbFinishedr  sQ    ,5)M>]fXr2,>???^vhB-?@@@@@r2   )r?   r   rd   r   rC   r   Queryr&   INrM   rk   rl   r   MessageanswersrJ   popr   r   gatherResultsr   )r)   rU   rC   rM   firstResultsecondResultresponsedr   r   r   s   `        @@r0   test_singleConcurrentRequestz*ResolverTests.test_singleConcurrentRequestU  sU    +,,?,?+@AAA&6&6&6&6#"	,ceSV<<nnU++Wq)))  ~~e,,Wq))) ;=='''b""8,,,l ;<<	A 	A 	A 	A 	A 	A
 	
j!!!r2   c                 |   t                      t          j        dg          }fd|_        j        }t          j        dt
          j                  }|                    |           | 	                    t          |          d           t          j        dt
          j                  }|                    |           | 	                    t          |          d           t          j        dt
          j                  }|                    |           | 	                    t          |          d           d	S )
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   ri      bar.example.comr   r   N)r?   r   rd   r   rC   r   r   r&   rM   rk   rl   A6)r)   rU   rC   
firstQuerysecondQuery
thirdQueryr   s         @r0   test_multipleConcurrentRequestsz-ResolverTests.test_multipleConcurrentRequestsz  s   
 +,,?,?+@AAA&6&6&6&6#" Y13599
z"""Wq))) i 2CE::{###Wq))) Y136::
z"""Wq)))))r2   c                    t                      t          j        dg          }fd|_        j        }t          j        dt
          j                  }|                    |           | 	                    t          |          d           |                                d                             t          j                               |                    |           | 	                    t          |          d           dS )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   ri   r   N)r?   r   rd   r   rC   r   r   r&   rM   rk   rl   r   r   r   )r)   rU   rC   rM   r   s       @r0   test_multipleSequentialRequestsz-ResolverTests.test_multipleSequentialRequests  s     +,,?,?+@AAA&6&6&6&6#"	,ce44 	uWq))) 	b""3;==111 	uWq)))))r2   c                 0   t                      t          j        dg          }fd|_        j        }t          j        dt
          j                  }|                    |          }|                    |          } G d dt                    }|
                                d                             t          j         |                                 t          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dS )GResolverTests.test_multipleConcurrentFailure.<locals>.ExpectedExceptionNr3   r4   r5   r6   r2   r0   ExpectedExceptionr             Dr2   r   r   )r?   r   rd   r   rC   r   r   r&   rM   	Exceptionr   r   r   Failurer   r   assertFailure)r)   rU   rC   rM   r   r   r   r   s          @r0   test_multipleConcurrentFailurez,ResolverTests.test_multipleConcurrentFailure  s    +,,?,?+@AAA&6&6&6&6#"	,ce44nnU++~~e,,	 	 	 	 		 	 	 	 	b!!'/2C2C2E2E"F"FGGG""";0ABB""<1BCC
 
 	
r2   c                    t          j        dg          }|                                }|                                }|                     |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AA0022
1133Z1222[2333 ((**/1F1N1N1P1P1U	
 	
 	
 "#J$8$FGG#K$9$GHH
 
 	
r2   c                     t          j                    }t          j        |                                 |          }|                                }|                     |j        |           dS )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   rY   r   )r)   r   rU   protos       r0   )test_resolverUsesOnlyParameterizedReactorz7ResolverTests.test_resolverUsesOnlyParameterizedReactor  s[     )++?$++--III++--eng.....r2   c                 `   t          j        dg          }g  G fdd          }||_        |                    t	          j        d                     |                    t	          j        d                     |                     t          t                              d           dS )	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dS ):ResolverTests.test_differentProtocol.<locals>.FakeProtocolc                 ,    t                      | _        d S rA   r8   rD   r;   s    r0   rE   zCResolverTests.test_differentProtocol.<locals>.FakeProtocol.__init__      !)r2   rG   Nc                 x                         |            t          j        t          j                              S rA   )rJ   r   r(   r   r   )r)   r   rM   r+   rK   	protocolss        r0   rM   z@ResolverTests.test_differentProtocol.<locals>.FakeProtocol.query  s-      &&&}S[]]333r2   rN   r3   r4   r5   rE   rM   )r  s   r0   FakeProtocolr    sB        , , ,4 4 4 4 4 4 4 4r2   r  r   r   r   N)	r   rd   r   rM   r   r   rk   rl   set)r)   rU   r  r  s      @r0   test_differentProtocolz$ResolverTests.test_differentProtocol  s     ?,?+@AAA		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 '3#sy!344555sy!344555S^^,,a00000r2   c                 B   t          j                    }t          j        dg|          }|                    t          j        d                     |j                                        \  \  }}|	                                j
        }|                     d|           dS )z<
        If the resolver is ipv6, open a ipv6 port.
        r   r   r   r   z::N)r   r  r   rd   rM   r   r   udpPortsitemsr  hostrk   )r)   fakerU   r  rD   r   s         r0   test_ipv6ResolverzResolverTests.test_ipv6Resolver   s    
 &((?K=$GGGsy!344555#}2244	%%%'',	y)))))r2   c                     g  G fdd          }t          j        dg          } |            |_        |                                 |                     t          t                              d           dS )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dS )6ResolverTests.test_disallowedPort.<locals>.FakeReactorc                 z                         |           t                    dk    rt          d |d           d S )Nri   )rJ   rl   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   rk   rl   r  r)   r/  rU   r+  s      @r0   test_disallowedPortz!ResolverTests.test_disallowedPort  s    
 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> ?,?+@AAA'KMM##%%%SZZ!,,,,,r2   c                     g  G fdd          }t          j        dg          } |            |_        |                     t          |j                   |                     t                    d           dS )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dS )@ResolverTests.test_disallowedPortRepeatedly.<locals>.FakeReactorc                 P                         |           t          d |d           rA   )rJ   r   r(  s       r0   r,  zJResolverTests.test_disallowedPortRepeatedly.<locals>.FakeReactor.listenUDP'  s'    T"""'dD999r2   Nr-  r.  s   r0   r/  r4  &  s.        : : : : : : :r2   r/  r   r   i  N)r   rd   r   r   r   r   rk   rl   r0  s      @r0   test_disallowedPortRepeatedlyz+ResolverTests.test_disallowedPortRepeatedly  s    
 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:
 ?,?+@AAA'KMM+X-HIIIUT*****r2   c                 N   g  G fdd          }t          j        dg          } |            |_        |                     t          |j                  }|                     |j        j        t          j	                   |                     t                    d           dS )zf
        If the process is out of files, L{Resolver._connectedProtocol}
        will give up.
        c                       e Zd Z fdZdS )5ResolverTests.test_runOutOfFiles.<locals>.FakeReactorc                                          |           t          t          j        d          }t	          d ||          )NzOut of files :()rJ   OSErrorerrnoEMFILEr   )r)   r  r)  r*  errr+  s        r0   r,  z?ResolverTests.test_runOutOfFiles.<locals>.FakeReactor.listenUDP:  s9    T"""el,=>>'dC888r2   Nr-  r.  s   r0   r/  r9  9  s.        9 9 9 9 9 9 9r2   r/  r   r   ri   N)r   rd   r   r   r   r   rk   socketErrorr<  r=  rl   )r)   r/  rU   excr+  s       @r0   test_runOutOfFilesz ResolverTests.test_runOutOfFiles2  s    
 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 ?,?+@AAA'KMM 183NO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          }||_
        |                    t          j        d                     |                     t          t                              d           dS )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dS )FResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocolc                 ,    t                      | _        d S rA   r  r;   s    r0   rE   zOResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocol.__init__U  r  r2   rG   Nc                 X                         |                                d          S Nr   rJ   r   r)   r   rM   r+   rK   r  r-   s        r0   rM   zLResolverTests.test_differentProtocolAfterTimeout.<locals>.FakeProtocol.queryX  '      &&&{{1~~%r2   rN   r  r  r-   s   r0   r  rD  T  G        , , ,& & & & & & & & &r2   r  r   r   )r   rd   r   failr   r  r   r(   r   r   r   rM   r   rk   rl   r  )r)   rU   r  r  r-   s      @@r0   "test_differentProtocolAfterTimeoutz0ResolverTests.test_differentProtocolAfterTimeoutH  s    
 ?,?+@AAA	Jw';D'A'ABBCCM#+--((

	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& '3#sy!344555S^^,,a00000r2   c                    t          j        dg          }g t          j                     G fdd          }||_        |                    t          j        d                     |                     d         j	        j
                                       t          j                               |                     d         j	        j
                   dS )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dS )9ResolverTests.test_protocolShutDown.<locals>.FakeProtocolc                 ,    t                      | _        d S rA   r  r;   s    r0   rE   zBResolverTests.test_protocolShutDown.<locals>.FakeProtocol.__init__k  r  r2   rG   Nc                 2                         |            S rA   rJ   r)   r   rM   r+   rK   r  rL   s        r0   rM   z?ResolverTests.test_protocolShutDown.<locals>.FakeProtocol.queryn        &&&r2   rN   r  r  rL   s   r0   r  rQ  j  G        , , ,        r2   r  r   r   N)r   rd   r   rI   r   rM   r   r   assertFalserD   r:   r   r   rS   )r)   rU   r  r  rL   s      @@r0   test_protocolShutDownz#ResolverTests.test_protocolShutDown`  s     ?,?+@AAA	!!	 	 	 	 	 	 	 	 	 	 	 '3#sy!3445551/<===&&&	!.;<<<<<r2   c                 &   t          j        dg          }g t          j                    }t          j        t          j        t          d                              |g G fdd          }||_        |	                    t          j        d                     |                     d         j        j                   |                    t          j                               |                     d         j        j                   dS )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dS )EResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocolc                 ,    t                      | _        d S rA   r  r;   s    r0   rE   zNResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocol.__init__  r  r2   rG   Nc                 X                         |                                d          S rG  rH  rI  s        r0   rM   zKResolverTests.test_protocolShutDownAfterTimeout.<locals>.FakeProtocol.query  rJ  r2   rN   r  rK  s   r0   r  r]    rL  r2   r  r   ri   )r   rd   r   rI   rM  r   r  r   r   rM   r   r   rY  rD   r:   r   r   rS   )r)   rU   rL   r  r  r-   s       @@r0   !test_protocolShutDownAfterTimeoutz/ResolverTests.test_protocolShutDownAfterTimeouty  s    ?,?+@AAA	!!:go.B4.H.HIIJJFS	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& '3#sy!3445551/<===&&&	!.;<<<<<r2   c                     G d dt                     }t          j        dg          }g t          j                     G fdd          }||_        |                    t          j        d                    }| 	                    d         j
        j                                       t          j         |                                 |                     d         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dS )JResolverTests.test_protocolShutDownAfterFailure.<locals>.ExpectedExceptionNr   r6   r2   r0   r   rc    r   r2   r   r   r   c                   $    e Zd Zd Zd fd	ZdS )EResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocolc                 ,    t                      | _        d S rA   r  r;   s    r0   rE   zNResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocol.__init__  r  r2   rG   Nc                 2                         |            S rA   rT  rU  s        r0   rM   zKResolverTests.test_protocolShutDownAfterFailure.<locals>.FakeProtocol.query  rV  r2   rN   r  rW  s   r0   r  re    rX  r2   r  r   r   )r   r   rd   r   rI   r   rM   r   r   rY  rD   r:   r   r   r  rS   r  )r)   r   rU   r  r   r  rL   s        @@r0   !test_protocolShutDownAfterFailurez/ResolverTests.test_protocolShutDownAfterFailure  s,   	 	 	 	 		 	 	 	 ?,?+@AAA	!!	 	 	 	 	 	 	 	 	 	 	 '3#nnSY/A%B%BCC1/<===w'8'8':':;;<<<	!.;<<<!!+/@AAAr2   c                 &   t          j        dg          }|j                            d          }|                    d           |                     ||j                   |                    d           |                     ||j                   dS )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  s    
 ?,?+@AAA#11$77%%%h 4555 	%%%8#788888r2   c                    t          j                    }t          j        dg|          }|                    t          j        d                    }|j        d         \  }}}}} G d dt                    }	|	                    |j
        d         t          j         |	                                 |                     ||	           dS )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dS )VResolverTests.test_singleTCPQueryErrbackOnConnectionFailure.<locals>.SentinelExceptionNr   r6   r2   r0   SentinelExceptionru    r   r2   rv  N)r   r  r   rd   queryTCPr   r   
tcpClientsr   clientConnectionFailed
connectorsr   r  failureResultOf)
r)   r   rU   r   r!  r  rj  r+   bindAddressrv  s
             r0   -test_singleTCPQueryErrbackOnConnectionFailurez;ResolverTests.test_singleTCPQueryErrbackOnConnectionFailure  s      -//?,?+@'RRRci66774;4Fq4I1dGWk	 	 	 	 		 	 	 	 	&&q!7?3D3D3F3F#G#G	
 	
 	
 	Q 122222r2   c                 <   t          j                    }t          j        dg|          }|                    t          j        d                    }|                    t          j        d                    }|j        d         \  }}}}}	 G d dt                    }
|	                    |j
        d         t          j         |
                                 |                     ||
          }|                     ||
          }|                     ||           dS )	z
        All pending L{resolver.queryTCP} C{deferred}s will C{errback}
        with the same C{Failure} if the connection attempt fails.
        rs  r  r   zexample.netr   c                       e Zd ZdS )XResolverTests.test_multipleTCPQueryErrbackOnConnectionFailure.<locals>.SentinelExceptionNr   r6   r2   r0   rv  r    r   r2   rv  N)r   r  r   rd   rw  r   r   rx  r   ry  rz  r   r  r{  rY   )r)   r   rU   d1d2r!  r  rj  r+   r|  rv  f1f2s                r0   /test_multipleTCPQueryErrbackOnConnectionFailurez=ResolverTests.test_multipleTCPQueryErrbackOnConnectionFailure  s)   
  -//?,?+@'RRRsy7788sy77884;4Fq4I1dGWk	 	 	 	 		 	 	 	 	&&q!7?3D3D3F3F#G#G	
 	
 	
 !!"&788!!"&788b"r2   c                    t          j                    }t          j        dg|          t	          j        d                                        }fd}|                    |           |                     t          |j
                  d           |                     t          |j                  d           |j
        d         \  }}}}}t          j        t                                }	|                    |j        d         |	           |                     t          |j
                  d           |                     t          |j                  d           |                     |           t          j        t                                }
|                    |j        d         |
           |                     |t                    }|                     ||
           dS )	z{
        An errback on the deferred returned by
        L{client.Resolver.queryTCP} may trigger another TCP query.
        )r   iE'  r  r   c                 b    |                      t                                                   S rA   )trapr   rw  )eqrU   s    r0   reissuezOResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailure.<locals>.reissue  s*    FF)***$$Q'''r2   ri   r   r   N)r   r  r   rd   r   r   rw  
addErrbackrk   rl   rx  rz  r   r  r   ry  assertNoResultr{  rY   )r)   r   r   r  r!  r  rj  r+   r|  r  r  fr  rU   s               @@r0   0test_reentrantTCPQueryErrbackOnConnectionFailurez>ResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailure  s   
  -//?,@+A7SSSIm$$ a  	( 	( 	( 	( 	( 	( 	
WW/00!444W/00!4444;4Fq4I1dGWk _35566&&w'9!'<bAAA 	W/00!444W/00!444A _35566&&w'9!'<bAAA   $:;;ar2   c                 f   t          j                    }t          j        dg|          }|                    t          j        d                    }|j        d         \  }}}}}|j        }	| 	                    t          |	          d            G d dt                    }
|                    |j        d         t          j         |
                                 |                     ||
           |                     |j        |	           | 	                    t          |	          d           dS )	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.
        rs  r  r   r   ri   c                       e Zd ZdS )JResolverTests.test_pendingEmptiedInPlaceOnError.<locals>.SentinelExceptionNr   r6   r2   r0   rv  r  '  r   r2   rv  N)r   r  r   rd   rw  r   r   rx  pendingrk   rl   r   ry  rz  r   r  r{  rY   )r)   r   rU   r   r!  r  rj  r+   r|  
prePendingrv  s              r0   !test_pendingEmptiedInPlaceOnErrorz/ResolverTests.test_pendingEmptiedInPlaceOnError  s:     -//?,?+@'RRRci66774;4Fq4I1dGWk%
Z!,,,	 	 	 	 		 	 	 	 	&&q!7?3D3D3F3F#G#G	
 	
 	
 	Q 1222h&
333Z!,,,,,r2   N) r3   r4   r5   r=   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#  r1  r6  rA  rN  rZ  r`  rh  rq  r}  r  r  r  r6   r2   r0   r   r      s        ( ( (0 0 07 7 7C C C+ + +$/ / /. . .     D# # #J* * *6* * *0
 
 
6
 
 
.	/ 	/ 	/1 1 1,
* 
* 
*- - -&+ + +&( ( (,1 1 10= = =2= = =4B B B>9 9 93 3 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dS )ClientTestsc                 R    t                      t          _        d| _        d| _        dS )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           _        dS )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        |           dS )zT
        Verify that the result is the same query type as what is expected.
        r   N)rk   r!   r  r"   )r)   r-   r*   r   r.   r/   rL   s          r0   checkResultzClientTests.checkResultC  sT     *1&J)4=999e,,,,,r2   c                 2    |                      |d           dS )zR
        Test that the getHostByName query returns the 127.0.0.1 address.
        r   Nr   r)   rL   s     r0   checkGetHostByNamezClientTests.checkGetHostByNameL  s      	-----r2   c                 l    t          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        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  s4      //	d&...r2   c                     t          j        | j                  }|                    | j        t
          j                   |S z+
        See L{test_lookupAddress}
        )r   lookupIPV6Addressr  r   r  r   AAAAr  s     r0   test_lookupIPV6Addressz"ClientTests.test_lookupIPV6Addressd  s4     $T]33	d&111r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupAddress6r  r   r  r   r   r  s     r0   test_lookupAddress6zClientTests.test_lookupAddress6l  s4     !$-00	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupNameserversr  r   r  r   NSr  s     r0   test_lookupNameserversz"ClientTests.test_lookupNameserverst  s4     $T]33	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupCanonicalNamer  r   r  r   CNAMEr  s     r0   test_lookupCanonicalNamez$ClientTests.test_lookupCanonicalName|  s4     &t}55	d&	222r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupAuthorityr  r   r  r   SOAr  s     r0   test_lookupAuthorityz ClientTests.test_lookupAuthority  s4     "4=11	d&000r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupMailBoxr  r   r  r   MBr  s     r0   test_lookupMailBoxzClientTests.test_lookupMailBox  s4      //	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupMailGroupr  r   r  r   MGr  s     r0   test_lookupMailGroupz ClientTests.test_lookupMailGroup  s4     "4=11	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupMailRenamer  r   r  r   MRr  s     r0   test_lookupMailRenamez!ClientTests.test_lookupMailRename  s4     #DM22	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   
lookupNullr  r   r  r   NULLr  s     r0   test_lookupNullzClientTests.test_lookupNull  4     dm,,	d&111r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupWellKnownServicesr  r   r  r   WKSr  s     r0   test_lookupWellKnownServicesz(ClientTests.test_lookupWellKnownServices  s4     *4=99	d&000r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupPointerr  r   r  r   PTRr  s     r0   test_lookupPointerzClientTests.test_lookupPointer  4      //	d&000r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupHostInfor  r   r  r   HINFOr  s     r0   test_lookupHostInfozClientTests.test_lookupHostInfo  s4     !$-00	d&	222r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupMailboxInfor  r   r  r   MINFOr  s     r0   test_lookupMailboxInfoz"ClientTests.test_lookupMailboxInfo  4     $T]33	d&	222r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupMailExchanger  r   r  r   MXr  s     r0   test_lookupMailExchangez#ClientTests.test_lookupMailExchange  s4     %dm44	d&///r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   
lookupTextr  r   r  r   TXTr  s     r0   test_lookupTextzClientTests.test_lookupText  s4     dm,,	d&000r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupSenderPolicyr  r   r  r   SPFr  s     r0   test_lookupSenderPolicyz#ClientTests.test_lookupSenderPolicy  s4     %dm44	d&000r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupResponsibilityr  r   r  r   RPr  s     r0   test_lookupResponsibilityz%ClientTests.test_lookupResponsibility  s4     '66	d&///r2   c                     t          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        t
          j                   |S r  )r   lookupServicer  r   r  r   SRVr  s     r0   test_lookupServicezClientTests.test_lookupService  r  r2   c                     t          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        t
          j                   |S r  )r   lookupAllRecordsr  r   r  r   ALL_RECORDSr  s     r0   test_lookupAllRecordsz!ClientTests.test_lookupAllRecords  s4     #DM22	d&888r2   c                     t          j        | j                  }|                    | j        t
          j                   |S r  )r   lookupNamingAuthorityPointerr  r   r  r   NAPTRr  s     r0   !test_lookupNamingAuthorityPointerz-ClientTests.test_lookupNamingAuthorityPointer  s4     />>	d&	222r2   c                     t          j        | j        t           j                  }t	          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   rM   r   r  )r)   r  r   s      r0   
test_queryzClientTests.test_query  sD     IdmSU++LOO	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                   H    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S )FilterAnswersTestsz|
    Test L{twisted.names.client.Resolver.filterAnswers}'s handling of various
    error conditions it might encounter.
    c                 <    t          j        dg          | _        d S )N)z0.0.0.0r   r   )r   rd   rU   r;   s    r0   r  zFilterAnswersTests.setUp'  s     0@AAAr2   c                      t          j        d                              d            fd}| 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                   t          j                    }dg|_        dg|_        dg|_        t          j        |          S )Nr   r.   r/   )	rk   rC   r   r   r   r.   r/   r   r(   )rC   r   mr)   s     r0   rw  z:FilterAnswersTests.test_truncatedMessage.<locals>.queryTCP4  sT    Wai000{}}H (zH"-H#/.H=***r2   r   r.   r/   )r   r   addQueryrU   rw  filterAnswersr   rk   )r)   rw  r   r  s   `  @r0   test_truncatedMessagez(FilterAnswersTests.test_truncatedMessage,  s    
 Kd###	

>"""	+ 	+ 	+ 	+ 	+ 	+ "*M''**	d&(k]\N(STTTr2   c                     t          j        |          }| j                            |          }|                    |           d S )N)rCode)r   r   rU   r  r  )r)   rcoder@  r  r>  s        r0   
_rcodeTestzFilterAnswersTests._rcodeTestA  s<    Ke$$$m))!,,r2   c                 V    |                      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AAr2   c                 V    |                      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AAr2   c                 V    |                      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     sy%*<===r2   c                 V    |                      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IIIr2   c                 V    |                      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HHHr2   c                 \    |                      t          j        dz   t          j                  S )zm
        Like L{test_formatError} but for an unrecognized error code and
        L{DNSUnknownError}.
        ri   )r  r   r(  r   DNSUnknownErrorr;   s    r0   test_refusedErrorUnknownz+FilterAnswersTests.test_refusedErrorUnknowne  s"    
 s|a/1FG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
  *  
B B BB B B> > >J J JI I IH H H H Hr2   r
  c                   "    e Zd Zd ZddZd ZdS )FakeDNSDatagramProtocolc                 :    g | _         t                      | _        d S rA   rB   r;   s    r0   rE   z FakeDNSDatagramProtocol.__init__n  rF   r2   rG   Nc                     | j                             ||||f           t          j        t	          j        |                    S rA   )rC   rJ   r   rM  r   r   )r)   r   rC   r+   rK   s        r0   rM   zFakeDNSDatagramProtocol.queryr  s<    Wgw;<<<z%4W==>>>r2   c                     d S rA   r6   )r)   rK   s     r0   removeResendz$FakeDNSDatagramProtocol.removeResendv  s    r2   rN   )r3   r4   r5   rE   rM   r3  r6   r2   r0   r/  r/  m  sF        $ $ $? ? ? ?    r2   r/  c                   ,    e Zd ZdZg dZd Zd Zd ZdS )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                    d | j         D             }t          j        d|          }t                      fd|_        |                    d                              | j                                      | j	                  S )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.
        c                     g | ]}|d fS )r   r6   )rf   xs     r0   rh   z:RetryLogicTests.test_roundRobinBackoff.<locals>.<listcomp>  s    333Q!R333r2   N)r~   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)   addrsrg   r  s      @r0   test_roundRobinBackoffz&RetryLogicTests.test_roundRobinBackoff  s     43$"2333O4777')),}}}OO.//[233Z1599	
r2   c                 0    |                      d           d S )Nz/Lookup address succeeded, should have timed out)rM  r  s     r0   r;  z$RetryLogicTests._cbRoundRobinBackoff  s    		CDDDDDr2   c                     |j         t          j                   dD ]}|j        d t	          | j                           }|j        d t	          | j                  = |                                 t          | j                  }|                                 t          ||          D ]8\  \  }}}}	}
| 	                    ||
df           | 	                    ||           9| 
                    |j                   d S )N)ri   r      -   r   )r  r   TimeoutErrorrC   rl   r:  sortlistziprk   rY  )r)   r   	fakeProtottriesexpectedaddrrM   r+   rK   expectedAddrs              r0   r<  z$RetryLogicTests._ebRoundRobinBackoff  s   U'(((
   
	- 
	-A%&=D,<(=(=&=>E!"9C(8$9$9"9:JJLLLD,--HMMOOO<?x<P<P - -8*ugrL  b'9:::  !,,,,- 	*+++++r2   N)r3   r4   r5   r=   r:  r>  r;  r<  r6   r2   r0   r5  r5  {  s[          ?>>K
 
 
"E E E, , , , ,r2   r5  c                       e Zd ZdZd ZdS )ThreadedResolverTestsz/
    Tests for L{client.ThreadedResolver}.
    c                 <   t          j                     |                     | j        g          }|                     |d         d         d           |                     |d         d         t
                     |                     t          |          d           dS )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.categoryri   N)r   ThreadedResolverflushWarningstest_deprecatedrk   DeprecationWarningrl   )r)   warningss     r0   rU  z%ThreadedResolverTests.test_deprecated  s    
 	!!!%%$:N9O%PPQK	"	
 	
 	
 	!Z02DEEEX*****r2   N)r3   r4   r5   r=   rU  r6   r2   r0   rN  rN    s-         + + + + +r2   rN  )6r=   r<  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/  r5  rN  r6   r2   r0   <module>rj     s   
  ; ; ; ; ; ; ; ; " " " " " " L L L L L L L L 1 1 1 1 1 1 ' ' ' ' ' ' @ @ @ @ @ @ : : : : : : : : : : : : : : - - - - - - 4 4 4 4 4 4 ( ( ( ( ( ( ; ; ; ; ; ; " " " " " " , , , , , , + + + + + + & & & & & & " " " " " "x OKKNK? ? ? ? ?< ? ? ?0! ! ! ! ! ! ! !       .    x(   4o& o& o& o& o&(+-> o& o& o&dC	- C	- C	- C	- C	-H% C	- C	- C	-Lk k k k k(# k k k\IH IH IH IH IH* IH IH IHX       -, -, -, -, -,h' -, -, -,`+ + + + +H- + + + + +r2   