+
    Dfj
(                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
HtHtHtHtHt ^ RIHtHtHt ^ RIHt ^ RIHt  ! R R	]4      t ! R
 R4      t ! R R]]4      t ! R R]]4      t ! R R]]4      tR# )zC
Tests for the I{hosts(5)}-based resolver, L{twisted.names.hosts}.
)annotations)Protocol)gatherResults)AAAAINADomainErrorQueryRecord_ARecord_AAAARRHeader)ResolversearchFileForsearchFileForAll)FilePath)SynchronousTestCasec                  "    ] tR t^tR R ltRtR# )_SupportsMktempc                   V ^8  d   QhRR/# )   returnstr )formats   "?/usr/lib/python3/dist-packages/twisted/names/test/test_hosts.py__annotate___SupportsMktemp.__annotate__   s           c                	    R # )Nr   selfs   &r   mktemp_SupportsMktemp.mktemp   s    r   r   N)__name__
__module____qualname____firstlineno__r!   __static_attributes__r   r   r   r   r      s     r   r   c                  "    ] tR t^ tR R ltRtR# )GoodTempPathMixinc                    V ^8  d   QhRRRR/# )r   r    r   r   zFilePath[bytes]r   )r   s   "r   r   GoodTempPathMixin.__annotate__!   s     7 7? 7 7r   c                	R    \        V P                  4       P                  R 4      4      # )zutf-8)r   r!   encoder   s   &r   pathGoodTempPathMixin.path!   s    ,,W566r   r   N)r#   r$   r%   r&   r.   r'   r   r   r   r)   r)       s    7 7r   r)   c                  J    ] tR t^%tRtR R ltR R ltR R ltR R	 ltR
t	R# )SearchHostsFileTestsz{
Tests for L{searchFileFor}, a helper which finds the first address for a
particular hostname in a I{hosts(5)}-style file.
c                   V ^8  d   QhRR/# r   r   Noner   )r   s   "r   r   !SearchHostsFileTests.__annotate__+   s     T T$ Tr   c                    V P                  4       pVP                  R4       V P                  R\        VP                   R4      4       R# )zZ
If there is an IPv4 address for the hostname passed to L{searchFileFor},
it is returned.
   10.2.3.4 foo.example.com
z10.2.3.4   foo.example.comNr.   
setContentassertEqualr   r    hostss   & r   test_findAddress%SearchHostsFileTests.test_findAddress+   s:    
 		67]5::?Q%RSr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   r5   4   s     I Id Ir   c                    V P                  4       pVP                  R4       V P                  \        VP                   R4      4       R# )zf
If there is no address information for the hostname passed to
L{searchFileFor}, L{None} is returned.
r7   s   bar.example.comN)r.   r:   assertIsNoner   r<   s   & r   test_notFoundAddress)SearchHostsFileTests.test_notFoundAddress4   s8    
 		67-

4FGHr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   r5   =   s     
O 
O4 
Or   c                    V P                  4       pVP                  R4       V P                  R\        VP                   R4      4       R# )zC
The first address associated with the given hostname is returned.
sV   ::1 foo.example.com
10.1.2.3 foo.example.com
fe80::21b:fcff:feee:5a1d foo.example.com
::1r8   Nr9   r<   s   & r   test_firstAddress&SearchHostsFileTests.test_firstAddress=   s@     		:	

 	ejj:L MNr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   r5   I   s     I I4 Ir   c                   V P                  4       pVP                  R4       V P                  \        VP                   R4      R4       V P                  \        VP                   R4      R4       V P                  \        VP                   R4      R4       V P                  \        VP                   R4      R4       V P                  \        VP                   R4      R4       R	# )
zx
For a host with a canonical name and one or more aliases,
L{searchFileFor} can find an address given any of the names.
sY   127.0.1.1	helmut.example.org	helmut
# a comment
::1 localhost ip6-localhost ip6-loopback
s   helmutz	127.0.1.1s   helmut.example.orgs   ip6-localhostrG   s   ip6-loopbacks	   localhostNr9   r<   s   & r   test_searchFileForAliases.SearchHostsFileTests.test_searchFileForAliasesI   s    
 		:	

 	uzz9={Kuzz3HI;Wuzz3CDeLuzz?CUKuzz<@%Hr   r   N)
r#   r$   r%   r&   __doc__r>   rC   rH   rL   r'   r   r   r   r1   r1   %   s%    
TI
OI Ir   r1   c                  J    ] tR t^[tRtR R ltR R ltR R ltR R	 ltR
t	R# )SearchHostsFileForAllTestszz
Tests for L{searchFileForAll}, a helper which finds all addresses for a
particular hostname in a I{hosts(5)}-style file.
c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   'SearchHostsFileForAllTests.__annotate__a   s     
 
4 
r   c                    V P                  4       pVP                  R4       V P                  . RO\        VR4      4       R# )z\
L{searchFileForAll} returns a list of all addresses associated with the
name passed to it.
sc   127.0.0.1     foobar.example.com
127.0.0.2     foobar.example.com
::1           foobar.example.com
s   foobar.example.comN)	127.0.0.1z	127.0.0.2rG   r.   r:   r;   r   r<   s   & r   test_allAddresses,SearchHostsFileForAllTests.test_allAddressesa   s@    
 		2	

 	-U$9:	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rR   q   s     X X Xr   c                    V P                  4       pVP                  R4       V P                  R.\        VR4      4       R# )z<
L{searchFileForAll} searches for names case-insensitively.
s!   127.0.0.1     foobar.EXAMPLE.com
rT   s   FOOBAR.example.comNrU   r<   s   & r   test_caseInsensitively1SearchHostsFileForAllTests.test_caseInsensitivelyq   s9     		>?+(8@U(VWr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rR   y   s     L L Lr   c                Z    V P                  . \        V P                  4       R4      4       R# )zi
If there is an error reading the contents of the hosts file,
L{searchFileForAll} returns an empty list.
s   example.comN)r;   r   r.   r   s   &r   test_readError)SearchHostsFileForAllTests.test_readErrory   s"    
 	-diik>JKr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rR      s     
 
$ 
r   c                    V P                  4       pVP                  R4       V P                  RR.\        VR4      4       R# )z_
L{searchFileForAll} ignores any malformed IP addresses associated with
the name passed to it.
s[   127.0.0.1	miser.example.org	miser
not-an-ip	miser
not-ascii	 miser
# miser
miser
::1 miserrT   rG   s   miserNrU   r<   s   & r   test_malformedIP+SearchHostsFileForAllTests.test_malformedIP   sD    
 			
 	% UH-	
r   r   N)
r#   r$   r%   r&   rN   rV   rZ   r^   rb   r'   r   r   r   rP   rP   [   s"    

 XL
 
r   rP   c                      ] tR t^tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )
HostsTestszB
Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}.
c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   HostsTests.__annotate__   s     3 3t 3r   c                	    V P                  4       pVP                  R 4       RV n        \        VP                   V P                  4      V n        R# )s  
1.1.1.1    EXAMPLE EXAMPLE.EXAMPLETHING
::2        mixed
1.1.1.2    MIXED
::1        ip6thingy
1.1.1.3    multiple
1.1.1.4    multiple
::3        ip6-multiple
::4        ip6-multiple
not-an-ip  malformed
malformed
# malformed
1.1.1.5    malformed
::5        malformed
ih  N)r.   r:   ttlr   resolver)r    fs   & r   setUpHostsTests.setUp   s=    IIK		
"  2r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     7 7$ 7r   c                R    \        4       pV P                  RVP                  4       R# )zy
The default hosts file used by L{Resolver} is I{/etc/hosts} if no value
is given for the C{file} initializer parameter.
s
   /etc/hostsN)r   r;   file)r    rj   s   & r   test_defaultPathHostsTests.test_defaultPath   s    
 :6r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     0 0D 0r   c                    . ROpV UUu. uF:  w  r#V P                   P                  V4      P                  V P                  V4      NK<  	  pppV P	                  \        V4      4       R# u uppi )z
L{hosts.Resolver.getHostByName} returns a L{Deferred} which fires with a
string giving the address of the queried name as found in the resolver's
hosts file.
N))   EXAMPLE1.1.1.1)s   EXAMPLE.EXAMPLETHINGrv   )s   MIXED1.1.1.2)rj   getHostByNameaddCallbackr;   successResultOfr   )r    datanipdss   &    r   test_getHostByNameHostsTests.test_getHostByName   si    
 
 MM''*66t7G7GL 	 
 	]2./	
s   A A)c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     
 
D 
r   c                X   V P                   P                  R4      pV P                  V4      w  r#pV P                  \	        R\
        \        V P                  \        RV P                  4      4      \	        R\
        \        V P                  \        RV P                  4      4      3V4       R# )zg
L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with A
records from the hosts file.
s   multiplez1.1.1.3z1.1.1.4N	rj   lookupAddressrz   r;   r   r   r   ri   r
   r    danswers	authority
additionals   &    r   test_lookupAddressHostsTests.test_lookupAddress   s    
 MM''4)-)=)=a)@&JaTXXx	4887TUaTXXx	4887TU 	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     
 
 
r   c                X   V P                   P                  R4      pV P                  V4      w  r#pV P                  \	        R\
        \        V P                  \        RV P                  4      4      \	        R\
        \        V P                  \        RV P                  4      4      3V4       R# )zn
L{hosts.Resolver.lookupIPV6Address} returns a L{Deferred} which fires
with AAAA records from the hosts file.
s   ip6-multiplez::3z::4N	rj   lookupIPV6Addressrz   r;   r   r   r   ri   r   r   s   &    r   test_lookupIPV6Address!HostsTests.test_lookupIPV6Address   s    
 MM++O<)-)=)=a)@&J#T2txxUDHH9U #T2txxUDHH9U	 
	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     

 

t 

r   c                    V P                   P                  R4      pV P                  V4      w  r#pV P                  \	        R\
        \        V P                  \        RV P                  4      4      3V4       R# )zj
L{hosts.Resolver.lookupAllRecords} returns a L{Deferred} which fires
with A records from the hosts file.
s   mixedrw   N)	rj   lookupAllRecordsrz   r;   r   r   r   ri   r
   r   s   &    r   test_lookupAllRecords HostsTests.test_lookupAllRecords   s`    
 MM**84)-)=)=a)@&Jh2txx)TXX1NOQ	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     
 
T 
r   c                d    V P                  V P                  P                  R4      \        4       R# )zd
L{hosts.Resolver} fails with L{NotImplementedError} for L{IResolver}
methods it doesn't implement.
ru   N)failureResultOfrj   lookupMailExchangeNotImplementedErrorr   s   &r   test_notImplementedHostsTests.test_notImplemented   s'    
 	MM,,Z8:M	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg      s     A AD Ar   c                	    V P                   P                  \        R 4      4      pV P                  V4      w  w  r#pV P	                  VP
                  P                  4       R4       R# )ru   rv   N)rj   queryr	   rz   r;   payload
dottedQuadr    r   answerr   r   s   &    r   
test_queryHostsTests.test_query   sO    MMj 12*.*>*>q*A'Z224i@r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg     s     R RD Rr   c                d    V P                  V P                  P                  R4      \        4       R# )z
L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with
L{dns.DomainError} if the name passed in has no addresses in the hosts
file.
   foueoaN)r   rj   r   r   r   s   &r   test_lookupAddressNotFound%HostsTests.test_lookupAddressNotFound  s#     	T]]88C[Qr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg     s     V V Vr   c                d    V P                  V P                  P                  R4      \        4       R# )zR
Like L{test_lookupAddressNotFound}, but for
L{hosts.Resolver.lookupIPV6Address}.
r   N)r   rj   r   r   r   s   &r   test_lookupIPV6AddressNotFound)HostsTests.test_lookupIPV6AddressNotFound  s#    
 	T]]<<YGUr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg     s     U Ut Ur   c                d    V P                  V P                  P                  R4      \        4       R# )zQ
Like L{test_lookupAddressNotFound}, but for
L{hosts.Resolver.lookupAllRecords}.
r   N)r   rj   r   r   r   s   &r   test_lookupAllRecordsNotFound(HostsTests.test_lookupAllRecordsNotFound  s#    
 	T]];;IFTr   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg     s     
 
d 
r   c                    V P                   P                  R4      pV P                  V4      w  w  r#pV P                  \	        R\
        \        V P                  \        RV P                  4      4      V4       R# )z
L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with
the valid addresses from the hosts file, ignoring any entries that
aren't valid IP addresses.
	   malformedz1.1.1.5Nr   r   s   &    r   test_lookupMalformedHostsTests.test_lookupMalformed  s_     MM''5*.*>*>q*A'Z\1b$((HY4QR	
r   c                   V ^8  d   QhRR/# r3   r   )r   s   "r   r   rg   '  s     

 

$ 

r   c                    V P                   P                  R4      pV P                  V4      w  w  r#pV P                  \	        R\
        \        V P                  \        RV P                  4      4      V4       R# )zS
Like L{test_lookupAddressMalformed}, but for
L{hosts.Resolver.lookupIPV6Address}.
r   z::5Nr   r   s   &    r   test_lookupIPV6Malformed#HostsTests.test_lookupIPV6Malformed'  s_    
 MM++L9*.*>*>q*A'Z\4TXX{5$((7ST	
r   )rj   ri   N)r#   r$   r%   r&   rN   rl   rq   r   r   r   r   r   r   r   r   r   r   r   r'   r   r   r   re   re      sQ    3,70"

&


A
RVU


 

r   re   N)rN   
__future__r   typingr   twisted.internet.deferr   twisted.names.dnsr   r   r   r   r	   r
   r   r   twisted.names.hostsr   r   r   twisted.python.filepathr   twisted.trial.unittestr   r   r)   r1   rP   re   r   r   r   <module>r      s    #  0	 	 	 J I , 6h 
7 7
3I.0A 3Il6
!46G 6
r]
$&7 ]
r   