§
    Ètºf(  ã                  ó  — d 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mZmZmZ ddlmZmZmZ ddlmZ ddlmZ  G d	„ d
e¦  «        Z G d„ d¦  «        Z G d„ dee¦  «        Z G d„ dee¦  «        Z G d„ dee¦  «        ZdS )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                  ó   — e Zd Zdd„ZdS )Ú_SupportsMktempÚreturnÚstrc                ó   — d S )N© ©Úselfs    ú\/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/names/test/test_hosts.pyÚmktempz_SupportsMktemp.mktemp   s   € Øˆó    N)r   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s(   € € € € € ðð ð ð ð ð r   r   c                  ó   — e Zd Zdd„ZdS )ÚGoodTempPathMixinr   r   r   úFilePath[bytes]c                ój   — t          |                      ¦   «                              d¦  «        ¦  «        S )Nzutf-8)r   r   Úencoder   s    r   ÚpathzGoodTempPathMixin.path!   s&   € Ý˜Ÿš™œ×,Ò,¨WÑ5Ô5Ñ6Ô6Ð6r   N)r   r   r   r#   )r   r   r    r&   r   r   r   r"   r"       s(   € € € € € ð7ð 7ð 7ð 7ð 7ð 7r   r"   c                  ó2   — e Zd ZdZd	d„Zd	d„Zd	d„Zd	d„ZdS )
ÚSearchHostsFileTestsz‡
    Tests for L{searchFileFor}, a helper which finds the first address for a
    particular hostname in a I{hosts(5)}-style file.
    r   ÚNonec                óª   — |                       ¦   «         }|                     d¦  «         |                      dt          |j         d¦  «        ¦  «         dS )zr
        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_findAddressz%SearchHostsFileTests.test_findAddress+   sO   € ð
 —	’	‘”ˆØ×ÒÐ6Ñ7Ô7Ð7Ø×Ò˜¥]°5´:Ð?QÑ%RÔ%RÑSÔSÐSÐSÐSr   c                ó¨   — |                       ¦   «         }|                     d¦  «         |                      t          |j         d¦  «        ¦  «         dS )z~
        If there is no address information for the hostname passed to
        L{searchFileFor}, L{None} is returned.
        r+   s   bar.example.comN)r&   r.   ÚassertIsNoner   r0   s     r   Útest_notFoundAddressz)SearchHostsFileTests.test_notFoundAddress4   sM   € ð
 —	’	‘”ˆØ×ÒÐ6Ñ7Ô7Ð7Ø×Ò�-¨¬
Ð4FÑGÔGÑHÔHÐHÐHÐHr   c                óª   — |                       ¦   «         }|                     d¦  «         |                      dt          |j         d¦  «        ¦  «         dS )zS
        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
ú::1r,   Nr-   r0   s     r   Útest_firstAddressz&SearchHostsFileTests.test_firstAddress=   sY   € ð —	’	‘”ˆØ×Òð:ñ	
ô 	
ð 	
ð
 	×Ò˜¥¨e¬jÐ:LÑ MÔ MÑNÔNÐNÐNÐNr   c                óò  — |                       ¦   «         }|                     d¦  «         |                      t          |j         d¦  «        d¦  «         |                      t          |j         d¦  «        d¦  «         |                      t          |j         d¦  «        d¦  «         |                      t          |j         d¦  «        d¦  «         |                      t          |j         d¦  «        d¦  «         d	S )
z�
        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-localhostr7   s   ip6-loopbacks	   localhostNr-   r0   s     r   Útest_searchFileForAliasesz.SearchHostsFileTests.test_searchFileForAliasesI   sâ   € ð
 —	’	‘”ˆØ×Òð:ñ	
ô 	
ð 	
ð
 	×Ò� u¤z°9Ñ=Ô=¸{ÑKÔKÐKØ×Ò� u¤zÐ3HÑIÔIÈ;ÑWÔWÐWØ×Ò� u¤zÐ3CÑDÔDÀeÑLÔLÐLØ×Ò� u¤z°?ÑCÔCÀUÑKÔKÐKØ×Ò� u¤z°<Ñ@Ô@À%ÑHÔHÐHÐHÐHr   N©r   r)   )r   r   r    Ú__doc__r2   r5   r8   r:   r   r   r   r(   r(   %   s€   € € € € € ðð ð
Tð Tð Tð TðIð Ið Ið Ið
Oð 
Oð 
Oð 
OðIð Ið Ið Ið Ið Ir   r(   c                  ó2   — e Zd ZdZd	d„Zd	d„Zd	d„Zd	d„ZdS )
ÚSearchHostsFileForAllTestsz†
    Tests for L{searchFileForAll}, a helper which finds all addresses for a
    particular hostname in a I{hosts(5)}-style file.
    r   r)   c                ó¤   — |                       ¦   «         }|                     d¦  «         |                      g d¢t          |d¦  «        ¦  «         dS )zt
        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.2r7   s   foobar.example.comN©r&   r.   r/   r   r0   s     r   Útest_allAddressesz,SearchHostsFileForAllTests.test_allAddressesa   si   € ð
 —	’	‘”ˆØ×Òð2ñ	
ô 	
ð 	
ð
 	×ÒØ-Ð-Ð-Ý˜UÐ$9Ñ:Ô:ñ	
ô 	
ð 	
ð 	
ð 	
r   c                ó¢   — |                       ¦   «         }|                     d¦  «         |                      dgt          |d¦  «        ¦  «         dS )zL
        L{searchFileForAll} searches for names case-insensitively.
        s!   127.0.0.1     foobar.EXAMPLE.com
r@   s   FOOBAR.example.comNrA   r0   s     r   Útest_caseInsensitivelyz1SearchHostsFileForAllTests.test_caseInsensitivelyq   sP   € ð —	’	‘”ˆØ×ÒÐ>Ñ?Ô?Ð?Ø×Ò˜+˜Õ(8¸Ð@UÑ(VÔ(VÑWÔWÐWÐWÐWr   c                ór   — |                       g t          |                      ¦   «         d¦  «        ¦  «         dS )z�
        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_readErrorz)SearchHostsFileForAllTests.test_readErrory   s3   € ð
 	×Ò˜Õ-¨d¯iªi©k¬k¸>ÑJÔJÑKÔKÐKÐKÐKr   c                ó¤   — |                       ¦   «         }|                     d¦  «         |                      ddgt          |d¦  «        ¦  «         dS )zw
        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 miserr@   r7   s   miserNrA   r0   s     r   Útest_malformedIPz+SearchHostsFileForAllTests.test_malformedIP€   sg   € ð
 —	’	‘”ˆØ×Òðñ	
ô 	
ð 	
ð 	×ÒØ˜%Ð Ý˜U HÑ-Ô-ñ	
ô 	
ð 	
ð 	
ð 	
r   Nr;   )r   r   r    r<   rB   rD   rF   rH   r   r   r   r>   r>   [   sv   € € € € € ðð ð

ð 
ð 
ð 
ð Xð Xð Xð XðLð Lð Lð Lð
ð 
ð 
ð 
ð 
ð 
r   r>   c                  óz   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd„Zdd	„Z	dd
„Z
dd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS )Ú
HostsTestszJ
    Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}.
    r   r)   c                ó¤   — |                       ¦   «         }|                     d¦  «         d| _        t          |j         | j        ¦  «        | _        d S )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&   r.   Úttlr   Úresolver)r   Úfs     r   ÚsetUpzHostsTests.setUp™   sL   € Ø�IŠI‰KŒKˆØ	�Šðñ	
ô 	
ð 	
ð" ˆŒÝ  ¤¨¬Ñ2Ô2ˆŒˆˆr   c                óX   — t          ¦   «         }|                      d|j        ¦  «         dS )z‘
        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   rM   s     r   Útest_defaultPathzHostsTests.test_defaultPath¯   s+   € õ
 ‘:”:ˆØ×Ò˜¨¬Ñ6Ô6Ð6Ð6Ð6r   c                óp   ‡ — g d¢}ˆ fd„|D ¦   «         }‰                       t          |¦  «        ¦  «         dS )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.EXAMPLETHINGrU   )s   MIXEDú1.1.1.2c                ó|   •— g | ]8\  }}‰j                              |¦  «                             ‰j        |¦  «        ‘Œ9S r   )rM   ÚgetHostByNameÚaddCallbackr/   )Ú.0ÚnÚipr   s      €r   ú
<listcomp>z1HostsTests.test_getHostByName.<locals>.<listcomp>Â   sP   ø€ ð 
ð 
ð 
á��2ð ŒM×'Ò'¨Ñ*Ô*×6Ò6°tÔ7GÈÑLÔLð
ð 
ð 
r   N)ÚsuccessResultOfr   )r   ÚdataÚdss   `  r   Útest_getHostByNamezHostsTests.test_getHostByName·   s`   ø€ ð
ð 
ð 
ˆð

ð 
ð 
ð 
àð
ñ 
ô 
ˆð 	×Ò�]¨2Ñ.Ô.Ñ/Ô/Ð/Ð/Ð/r   c                óh  — | j                              d¦  «        }|                      |¦  «        \  }}}|                      t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        f|¦  «         dS )z
        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©	rM   ÚlookupAddressr^   r/   r   r   r   rL   r   ©r   ÚdÚanswersÚ	authorityÚ
additionals        r   Útest_lookupAddresszHostsTests.test_lookupAddressÈ   s¡   € ð
 ŒM×'Ò'¨Ñ4Ô4ˆØ)-×)=Ò)=¸aÑ)@Ô)@Ñ&ˆ�˜JØ×Òå˜¥a­¨T¬XµxÀ	È4Ì8Ñ7TÔ7TÑUÔUÝ˜¥a­¨T¬XµxÀ	È4Ì8Ñ7TÔ7TÑUÔUðð ñ	
ô 	
ð 	
ð 	
ð 	
r   c                óh  — | j                              d¦  «        }|                      |¦  «        \  }}}|                      t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        f|¦  «         dS )z†
        L{hosts.Resolver.lookupIPV6Address} returns a L{Deferred} which fires
        with AAAA records from the hosts file.
        s   ip6-multiplez::3z::4N©	rM   ÚlookupIPV6Addressr^   r/   r   r   r   rL   r   re   s        r   Útest_lookupIPV6Addressz!HostsTests.test_lookupIPV6Address×   s­   € ð
 ŒM×+Ò+¨OÑ<Ô<ˆØ)-×)=Ò)=¸aÑ)@Ô)@Ñ&ˆ�˜JØ×ÒåØ#¥T­2¨t¬x½ÀUÈDÌHÑ9UÔ9Uñô õ Ø#¥T­2¨t¬x½ÀUÈDÌHÑ9UÔ9Uñô ð	ð ñ
	
ô 
	
ð 
	
ð 
	
ð 
	
r   c                ó   — | j                              d¦  «        }|                      |¦  «        \  }}}|                      t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        f|¦  «         dS )z‚
        L{hosts.Resolver.lookupAllRecords} returns a L{Deferred} which fires
        with A records from the hosts file.
        s   mixedrV   N)	rM   ÚlookupAllRecordsr^   r/   r   r   r   rL   r   re   s        r   Útest_lookupAllRecordsz HostsTests.test_lookupAllRecordsê   s|   € ð
 ŒM×*Ò*¨8Ñ4Ô4ˆØ)-×)=Ò)=¸aÑ)@Ô)@Ñ&ˆ�˜JØ×ÒÝ�h¥¥2 t¤xµ¸)ÀTÄXÑ1NÔ1NÑOÔOÐQØñ	
ô 	
ð 	
ð 	
ð 	
r   c                ól   — |                       | j                             d¦  «        t          ¦  «         dS )z|
        L{hosts.Resolver} fails with L{NotImplementedError} for L{IResolver}
        methods it doesn't implement.
        rT   N)ÚfailureResultOfrM   ÚlookupMailExchangeÚNotImplementedErrorr   s    r   Útest_notImplementedzHostsTests.test_notImplementedö   s<   € ð
 	×ÒØŒM×,Ò,¨ZÑ8Ô8Õ:Mñ	
ô 	
ð 	
ð 	
ð 	
r   c                óä   — | j                              t          d¦  «        ¦  «        }|                      |¦  «        \  \  }}}|                      |j                             ¦   «         d¦  «         d S )NrT   rU   )rM   Úqueryr
   r^   r/   ÚpayloadÚ
dottedQuad©r   rf   Úanswerrh   ri   s        r   Ú
test_queryzHostsTests.test_queryÿ   se   € ØŒM×Ò¥ jÑ 1Ô 1Ñ2Ô2ˆØ*.×*>Ò*>¸qÑ*AÔ*AÑ'‰ˆ�)˜ZØ×Ò˜œ×2Ò2Ñ4Ô4°iÑ@Ô@Ð@Ð@Ð@r   c                ól   — |                       | j                             d¦  «        t          ¦  «         dS )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)rs   rM   rd   r	   r   s    r   Útest_lookupAddressNotFoundz%HostsTests.test_lookupAddressNotFound  s0   € ð 	×Ò˜Tœ]×8Ò8¸ÑCÔCÅ[ÑQÔQÐQÐQÐQr   c                ól   — |                       | j                             d¦  «        t          ¦  «         dS )zj
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupIPV6Address}.
        r   N)rs   rM   rm   r	   r   s    r   Útest_lookupIPV6AddressNotFoundz)HostsTests.test_lookupIPV6AddressNotFound  s0   € ð
 	×Ò˜Tœ]×<Ò<¸YÑGÔGÍÑUÔUÐUÐUÐUr   c                ól   — |                       | j                             d¦  «        t          ¦  «         dS )zi
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupAllRecords}.
        r   N)rs   rM   rp   r	   r   s    r   Útest_lookupAllRecordsNotFoundz(HostsTests.test_lookupAllRecordsNotFound  s0   € ð
 	×Ò˜Tœ]×;Ò;¸IÑFÔFÍÑTÔTÐTÐTÐTr   c                ó  — | j                              d¦  «        }|                      |¦  «        \  \  }}}|                      t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        |¦  «         dS )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.5Nrc   r{   s        r   Útest_lookupMalformedzHostsTests.test_lookupMalformed  s{   € ð ŒM×'Ò'¨Ñ5Ô5ˆØ*.×*>Ò*>¸qÑ*AÔ*AÑ'‰ˆ�)˜ZØ×ÒÝ�\¥1¥b¨$¬(µH¸YÈÌÑ4QÔ4QÑRÔRØñ	
ô 	
ð 	
ð 	
ð 	
r   c                ó  — | j                              d¦  «        }|                      |¦  «        \  \  }}}|                      t	          dt
          t          | j        t          d| j        ¦  «        ¦  «        |¦  «         dS )zk
        Like L{test_lookupAddressMalformed}, but for
        L{hosts.Resolver.lookupIPV6Address}.
        r†   z::5Nrl   r{   s        r   Útest_lookupIPV6Malformedz#HostsTests.test_lookupIPV6Malformed'  s{   € ð
 ŒM×+Ò+¨LÑ9Ô9ˆØ*.×*>Ò*>¸qÑ*AÔ*AÑ'‰ˆ�)˜ZØ×ÒÝ�\¥4­¨T¬Xµ{À5È$Ì(Ñ7SÔ7SÑTÔTØñ	
ô 	
ð 	
ð 	
ð 	
r   Nr;   )r   r   r    r<   rO   rR   ra   rj   rn   rq   rv   r}   r€   r‚   r„   r‡   r‰   r   r   r   rJ   rJ   ”   s2  € € € € € ðð ð3ð 3ð 3ð 3ð,7ð 7ð 7ð 7ð0ð 0ð 0ð 0ð"
ð 
ð 
ð 
ð
ð 
ð 
ð 
ð&

ð 

ð 

ð 

ð
ð 
ð 
ð 
ðAð Að Að Að
Rð Rð Rð RðVð Vð Vð VðUð Uð Uð Uð
ð 
ð 
ð 
ð

ð 

ð 

ð 

ð 

ð 

r   rJ   N)r<   Ú
__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(   r>   rJ   r   r   r   ú<module>r‘      sê  ððð ð #Ð "Ð "Ð "Ð "Ð "à &Ð &Ð &Ð &Ð &Ð &à 0Ð 0Ð 0Ð 0Ð 0Ð 0ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð JÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6ðð ð ð ð �hñ ô ð ð
7ð 7ð 7ð 7ð 7ñ 7ô 7ð 7ð
3Ið 3Ið 3Ið 3Ið 3IÐ.Ð0Añ 3Iô 3Ið 3Iðl6
ð 6
ð 6
ð 6
ð 6
Ð!4Ð6Gñ 6
ô 6
ð 6
ðr]
ð ]
ð ]
ð ]
ð ]
Ð$Ð&7ñ ]
ô ]
ð ]
ð ]
ð ]
r   