+
    üÐ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@   € ð —	‘	“ˆØ×Ñð:ô	
ð
 	×Ñ˜¤¨e¯j©jÐ: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­   € ð
 —	‘	“ˆØ×Ñð:ô	
ð
 	×Ñœ u§z¡z°9Ó=¸{ÔKØ×Ñœ u§z¡zÐ3HÓIÈ;ÔWØ×Ñœ u§z¡zÐ3CÓDÀeÔLØ×Ñœ u§z¡z°?ÓCÀUÔKØ×Ñœ u§z¡z°<Ó@À%Ö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_caseInsensitivelyÚ1SearchHostsFileForAllTests.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"   € ð
 	×Ñ˜Ô-¨d¯i©i«k¸>Ó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   € ð
 —	‘	“ˆØ×Ñðô	
ð 	×ÑØ˜%Ð Ü˜U HÓ-ö	
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ñ 3�tñ 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=   € Ø�I‰I‹KˆØ	�‰ðô	
ð" ˆŒÜ  §¡¨¯©Ó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ñ 0 Dñ 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   € ò
ˆñ ô
á‘�ð �M‰M×'Ñ'¨Ó*×6Ñ6°t×7GÑ7GÈÖ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ƒ   € ð
 �M‰M×'Ñ'¨Ó4ˆØ)-×)=Ñ)=¸aÓ)@Ñ&ˆ˜JØ×Ñä˜¤a¬¨T¯X©X´xÀ	È4Ï8É8Ó7TÓUÜ˜¤a¬¨T¯X©X´xÀ	È4Ï8É8Ó7TÓ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‹   € ð
 �M‰M×+Ñ+¨OÓ<ˆØ)-×)=Ñ)=¸aÓ)@Ñ&ˆ˜JØ×ÑäØ#¤T¬2¨t¯x©x¼ÀUÈDÏHÉHÓ9Uóô Ø#¤T¬2¨t¯x©x¼ÀUÈDÏHÉHÓ9Uóð	ð ö
	
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`   € ð
 �M‰M×*Ñ*¨8Ó4ˆØ)-×)=Ñ)=¸aÓ)@Ñ&ˆ˜JØ×ÑÜ�h¤¤2 t§x¡x´¸)ÀTÇXÁXÓ1NÓ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'   € ð
 	×ÑØ�M‰M×,Ñ,¨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   € Ø�M‰M×Ñ¤ jÓ 1Ó2ˆØ*.×*>Ñ*>¸qÓ*AÑ'‰ˆ˜ZØ×Ñ˜Ÿ™×2Ñ2Ó4°iÖ@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_   € ð �M‰M×'Ñ'¨Ó5ˆØ*.×*>Ñ*>¸qÓ*AÑ'‰ˆ˜ZØ×ÑÜ�\¤1¤b¨$¯(©(´H¸YÈÏÉÓ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_   € ð
 �M‰M×+Ñ+¨LÓ9ˆØ*.×*>Ñ*>¸qÓ*AÑ'‰ˆ˜ZØ×ÑÜ�\¤4¬¨T¯X©X´{À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
Ð!4Ð6Gô 6
ôr]
Ð$Ð&7ö ]
r   