ó
    Ö›‘h(  ã                  óò   • S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	J
r
JrJrJrJrJr  SSKJrJrJr  SSKJr  SSKJr   " S	 S
\5      r " S S5      r " S S\\5      r " S S\\5      r " S S\\5      rg)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                  ó   • \ rS rSrSS jrSrg)Ú_SupportsMktempé   c                ó   • g )N© ©Úselfs    ÚaC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/names/test/test_hosts.pyÚmktempÚ_SupportsMktemp.mktemp   s   € Øó    r   N)ÚreturnÚstr)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   Ú__static_attributes__r   r   r   r   r      s   † ÷r   r   c                  ó   • \ rS rSrSS jrSrg)ÚGoodTempPathMixiné    c                óR   • [        U R                  5       R                  S5      5      $ )Nzutf-8)r   r   Úencoder   s    r   ÚpathÚGoodTempPathMixin.path!   s   € Ü˜Ÿ™›×,Ñ,¨WÓ5Ó6Ð6r   r   N)r   r   r   zFilePath[bytes])r    r!   r"   r#   r*   r$   r   r   r   r&   r&       s   † ÷7r   r&   c                  ó@   • \ rS rSrSrS	S jrS	S jrS	S jrS	S jrSr	g)
ÚSearchHostsFileTestsé%   z{
Tests for L{searchFileFor}, a helper which finds the first address for a
particular hostname in a I{hosts(5)}-style file.
c                ó’   • U R                  5       nUR                  S5        U R                  S[        UR                   S5      5        g)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                ó�   • U R                  5       nUR                  S5        U R                  [        UR                   S5      5        g)zf
If there is no address information for the hostname passed to
L{searchFileFor}, L{None} is returned.
r0   s   bar.example.comN)r*   r3   ÚassertIsNoner   r5   s     r   Útest_notFoundAddressÚ)SearchHostsFileTests.test_notFoundAddress4   s8   € ð
 —	‘	“ˆØ×ÑÐ6Ô7Ø×Ñœ-¨¯
©
Ð4FÓGÕHr   c                ó’   • U R                  5       nUR                  S5        U R                  S[        UR                   S5      5        g)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
ú::1r1   Nr2   r5   s     r   Útest_firstAddressÚ&SearchHostsFileTests.test_firstAddress=   s@   € ð —	‘	“ˆØ×Ñð:ô	
ð
 	×Ñ˜¤¨e¯j©jÐ:LÓ MÕNr   c                óÂ  • U R                  5       nUR                  S5        U R                  [        UR                   S5      S5        U R                  [        UR                   S5      S5        U R                  [        UR                   S5      S5        U R                  [        UR                   S5      S5        U R                  [        UR                   S5      S5        g	)
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-localhostr>   s   ip6-loopbacks	   localhostNr2   r5   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   ÚNone)
r    r!   r"   r#   Ú__doc__r7   r;   r?   rB   r$   r   r   r   r-   r-   %   s   † ñô
TôIô
O÷Ir   r-   c                  ó@   • \ rS rSrSrS	S jrS	S jrS	S jrS	S jrSr	g)
ÚSearchHostsFileForAllTestsé[   zz
Tests for L{searchFileForAll}, a helper which finds all addresses for a
particular hostname in a I{hosts(5)}-style file.
c                ó‚   • U R                  5       nUR                  S5        U R                  / SQ[        US5      5        g)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
)ú	127.0.0.1z	127.0.0.2r>   s   foobar.example.comN©r*   r3   r4   r   r5   s     r   Útest_allAddressesÚ,SearchHostsFileForAllTests.test_allAddressesa   s@   € ð
 —	‘	“ˆØ×Ñð2ô	
ð
 	×ÑÚ-Ü˜UÐ$9Ó:õ	
r   c                ó€   • U R                  5       nUR                  S5        U R                  S/[        US5      5        g)z<
L{searchFileForAll} searches for names case-insensitively.
s!   127.0.0.1     foobar.EXAMPLE.com
rK   s   FOOBAR.example.comNrL   r5   s     r   Útest_caseInsensitivelyÚ1SearchHostsFileForAllTests.test_caseInsensitivelyq   s9   € ð —	‘	“ˆØ×ÑÐ>Ô?Ø×Ñ˜+˜Ô(8¸Ð@UÓ(VÕWr   c                óX   • U R                  / [        U R                  5       S5      5        g)zi
If there is an error reading the contents of the hosts file,
L{searchFileForAll} returns an empty list.
s   example.comN)r4   r   r*   r   s    r   Útest_readErrorÚ)SearchHostsFileForAllTests.test_readErrory   s"   € ð
 	×Ñ˜Ô-¨d¯i©i«k¸>ÓJÕKr   c                ó‚   • U R                  5       nUR                  S5        U R                  SS/[        US5      5        g)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 miserrK   r>   s   miserNrL   r5   s     r   Útest_malformedIPÚ+SearchHostsFileForAllTests.test_malformedIP€   sD   € ð
 —	‘	“ˆØ×Ñðô	
ð 	×ÑØ˜%Ð Ü˜U HÓ-õ	
r   r   NrD   )
r    r!   r"   r#   rF   rM   rP   rS   rV   r$   r   r   r   rH   rH   [   s   † ñô

ô XôL÷
r   rH   c                  óš   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSrg)Ú
HostsTestsé”   zB
Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}.
c                óž   • U R                  5       nUR                  S5        SU l        [        UR                   U R                  5      U l        g )Ns  
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  )r*   r3   Úttlr   Úresolver)r   Úfs     r   ÚsetUpÚHostsTests.setUp™   s=   € Ø�I‰I‹KˆØ	�‰ðô	
ð" ˆŒÜ  §¡¨¯©Ó2ˆ�r   c                óP   • [        5       nU R                  SUR                  5        g)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   r4   Úfile)r   r]   s     r   Útest_defaultPathÚHostsTests.test_defaultPath¯   s   € ô
 “:ˆØ×Ñ˜¨¯©Õ6r   c                óÞ   • / SQnU VVs/ s H:  u  p#U R                   R                  U5      R                  U R                  U5      PM<     nnnU R	                  [        U5      5        gs  snnf )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.
))ó   EXAMPLEú1.1.1.1)s   EXAMPLE.EXAMPLETHINGrg   )s   MIXEDú1.1.1.2N)r]   ÚgetHostByNameÚaddCallbackr4   Ú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  • U R                   R                  S5      nU R                  U5      u  p#nU R                  [	        S[
        [        U R                  [        SU R                  5      5      [	        S[
        [        U R                  [        SU R                  5      5      4U5        g)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©	r]   ÚlookupAddressrk   r4   r   r   r   r\   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  • U R                   R                  S5      nU R                  U5      u  p#nU R                  [	        S[
        [        U R                  [        SU R                  5      5      [	        S[
        [        U R                  [        SU R                  5      5      4U5        g)zn
L{hosts.Resolver.lookupIPV6Address} returns a L{Deferred} which fires
with AAAA records from the hosts file.
s   ip6-multiplez::3z::4N©	r]   ÚlookupIPV6Addressrk   r4   r   r   r   r\   r   ru   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                óî   • U R                   R                  S5      nU R                  U5      u  p#nU R                  [	        S[
        [        U R                  [        SU R                  5      5      4U5        g)zj
L{hosts.Resolver.lookupAllRecords} returns a L{Deferred} which fires
with A records from the hosts file.
s   mixedrh   N)	r]   ÚlookupAllRecordsrk   r4   r   r   r   r\   r   ru   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                ób   • U R                  U R                  R                  S5      [        5        g)zd
L{hosts.Resolver} fails with L{NotImplementedError} for L{IResolver}
methods it doesn't implement.
rf   N)ÚfailureResultOfr]   ÚlookupMailExchangeÚNotImplementedErrorr   s    r   Útest_notImplementedÚHostsTests.test_notImplementedö   s'   € ð
 	×ÑØ�M‰M×,Ñ,¨ZÓ8Ô:Mõ	
r   c                óÌ   • U R                   R                  [        S5      5      nU R                  U5      u  u  p#nU R	                  UR
                  R                  5       S5        g )Nrf   rg   )r]   Úqueryr
   rk   r4   ÚpayloadÚ
dottedQuad©r   rv   Úanswerrx   ry   s        r   Ú
test_queryÚHostsTests.test_queryÿ   sO   € Ø�M‰M×Ñ¤ jÓ 1Ó2ˆØ*.×*>Ñ*>¸qÓ*AÑ'‰ˆ˜ZØ×Ñ˜Ÿ™×2Ñ2Ó4°iÕ@r   c                ób   • U R                  U R                  R                  S5      [        5        g)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†   r]   rt   r	   r   s    r   Útest_lookupAddressNotFoundÚ%HostsTests.test_lookupAddressNotFound  s#   € ð 	×Ñ˜TŸ]™]×8Ñ8¸ÓCÄ[ÕQr   c                ób   • U R                  U R                  R                  S5      [        5        g)zR
Like L{test_lookupAddressNotFound}, but for
L{hosts.Resolver.lookupIPV6Address}.
r”   N)r†   r]   r~   r	   r   s    r   Útest_lookupIPV6AddressNotFoundÚ)HostsTests.test_lookupIPV6AddressNotFound  s#   € ð
 	×Ñ˜TŸ]™]×<Ñ<¸YÓGÌÕUr   c                ób   • U R                  U R                  R                  S5      [        5        g)zQ
Like L{test_lookupAddressNotFound}, but for
L{hosts.Resolver.lookupAllRecords}.
r”   N)r†   r]   r‚   r	   r   s    r   Útest_lookupAllRecordsNotFoundÚ(HostsTests.test_lookupAllRecordsNotFound  s#   € ð
 	×Ñ˜TŸ]™]×;Ñ;¸IÓFÌÕTr   c                óð   • U R                   R                  S5      nU R                  U5      u  u  p#nU R                  [	        S[
        [        U R                  [        SU R                  5      5      U5        g)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.5Nrs   r�   s        r   Útest_lookupMalformedÚHostsTests.test_lookupMalformed  s_   € ð �M‰M×'Ñ'¨Ó5ˆØ*.×*>Ñ*>¸qÓ*AÑ'‰ˆ˜ZØ×ÑÜ�\¤1¤b¨$¯(©(´H¸YÈÏÉÓ4QÓRØõ	
r   c                óð   • U R                   R                  S5      nU R                  U5      u  u  p#nU R                  [	        S[
        [        U R                  [        SU R                  5      5      U5        g)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   )r]   r\   NrD   )r    r!   r"   r#   rF   r_   rc   rp   rz   r   rƒ   r‰   r‘   r•   r˜   r›   rŸ   r¢   r$   r   r   r   rY   rY   ”   sL   † ñô3ô,7ô0ô"
ô
ô&

ô
ôAô
RôVôUô
÷

r   rY   N)rF   Ú
__future__r   Útyping_extensionsr   Ú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&   r-   rH   rY   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   