HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/names/test/__pycache__/test_hosts.cpython-38.pyc
U


W[c!�@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZddlmZmZmZGdd	�d	e�ZGd
d�dee�ZGdd
�d
ee�ZGdd�dee�ZdS)zC
Tests for the I{hosts(5)}-based resolver, L{twisted.names.hosts}.
�)�division�absolute_import)�TestCase)�FilePath��
gatherResults)�A�AAAA�IN�DomainError�RRHeader�Query�Record_A�Record_AAAA)�Resolver�
searchFileFor�searchFileForAllc@seZdZdd�ZdS)�GoodTempPathMixincCst|���d��S)Nzutf-8)rZmktemp�encode��self�r�?/usr/lib/python3/dist-packages/twisted/names/test/test_hosts.py�pathszGoodTempPathMixin.pathN)�__name__�
__module__�__qualname__rrrrrrsrc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SearchHostsFileTestsz�
    Tests for L{searchFileFor}, a helper which finds the first address for a
    particular hostname in a I{hosts(5)}-style file.
    cCs*|��}|�d�|�dt|jd��dS)zr
        If there is an IPv4 address for the hostname passed to L{searchFileFor},
        it is returned.
        �10.2.3.4 foo.example.com
z10.2.3.4�foo.example.comN�r�
setContent�assertEqualr�rZhostsrrr�test_findAddresss�
�z%SearchHostsFileTests.test_findAddresscCs(|��}|�d�|�t|jd��dS)z~
        If there is no address information for the hostname passed to
        L{searchFileFor}, L{None} is returned.
        rsbar.example.comN)rr!ZassertIsNonerr#rrr�test_notFoundAddress*s
�z)SearchHostsFileTests.test_notFoundAddresscCs*|��}|�d�|�dt|jd��dS)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
�::1rNr r#rrr�test_firstAddress5s
�z&SearchHostsFileTests.test_firstAddresscCsz|��}|�d�|�t|jd�d�|�t|jd�d�|�t|jd�d�|�t|jd�d�|�t|jd�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.
        sY127.0.1.1	helmut.example.org	helmut
# a comment
::1 localhost ip6-localhost ip6-loopback
shelmutz	127.0.1.1shelmut.example.orgs
ip6-localhostr&sip6-loopbacks	localhostNr r#rrr�test_searchFileForAliasesAs�
�z.SearchHostsFileTests.test_searchFileForAliasesN)rrr�__doc__r$r%r'r(rrrrrs
rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SearchHostsFileForAllTestsz�
    Tests for L{searchFileForAll}, a helper which finds all addresses for a
    particular hostname in a I{hosts(5)}-style file.
    cCs.|��}|�d�|�dddgt|d��dS)zt
        L{searchFileForAll} returns a list of all addresses associated with the
        name passed to it.
        sc127.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&sfoobar.example.comN�rr!r"rr#rrr�test_allAddressesYs��z,SearchHostsFileForAllTests.test_allAddressescCs*|��}|�d�|�dgt|d��dS)zL
        L{searchFileForAll} searches for names case-insensitively.
        s!127.0.0.1     foobar.EXAMPLE.com
r+sFOOBAR.example.comNr,r#rrr�test_caseInsensitivelyhs
�z1SearchHostsFileForAllTests.test_caseInsensitivelycCs|�gt|��d��dS)z�
        If there is an error reading the contents of the hosts file,
        L{searchFileForAll} returns an empty list.
        sexample.comN)r"rrrrrr�test_readErrorrs�z)SearchHostsFileForAllTests.test_readErrorN)rrrr)r-r.r/rrrrr*Ts
r*c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
HostsTestszJ
    Tests for the I{hosts(5)}-based L{twisted.names.hosts.Resolver}.
    cCs,|��}|�d�d|_t|j|j�|_dS)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
ih)rr!�ttlr�resolver)r�frrr�setUp�s

zHostsTests.setUpcCst�}|�d|j�dS)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)rr"�file)rr2rrr�test_defaultPath�szHostsTests.test_defaultPathcs$dddg}�fdd�|D�}t|�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)sEXAMPLE.EXAMPLETHINGr8)sMIXED�1.1.1.2cs&g|]\}}�j�|���j|��qSr)r2Z
getHostByName�addCallbackr")�.0�nZiprrr�
<listcomp>�s�z1HostsTests.test_getHostByName.<locals>.<listcomp>r)r�dataZdsrrr�test_getHostByName�s�
�zHostsTests.test_getHostByNamecs&�j�d�}�fdd�}|�|�|S)z
        L{hosts.Resolver.lookupAddress} returns a L{Deferred} which fires with A
        records from the hosts file.
        �multiplecsJ|\}}}��tdtt�jtd�j��tdtt�jtd�j��f|�dS)Nr@z1.1.1.3z1.1.1.4�r"rrr
r1r�ZresultsZanswersZ	authorityZ
additionalrrr�resolved�s

�
���z/HostsTests.test_lookupAddress.<locals>.resolved)r2�
lookupAddressr:�r�drCrrr�test_lookupAddress�s
zHostsTests.test_lookupAddresscs&�j�d�}�fdd�}|�|�|S)z�
        L{hosts.Resolver.lookupIPV6Address} returns a L{Deferred} which fires
        with AAAA records from the hosts file.
        �ip6-multiplecsJ|\}}}��tdtt�jtd�j��tdtt�jtd�j��f|�dS)NrHz::3z::4)r"rr	r
r1rrBrrrrC�s

�
���z3HostsTests.test_lookupIPV6Address.<locals>.resolved)r2�lookupIPV6Addressr:rErrr�test_lookupIPV6Address�s
z!HostsTests.test_lookupIPV6Addresscs&�j�d�}�fdd�}|�|�|S)z�
        L{hosts.Resolver.lookupAllRecords} returns a L{Deferred} which fires
        with A records from the hosts file.
        �mixedc
s2|\}}}��tdtt�jtd�j��f|�dS)NrKr9rArBrrrrC�s

��z2HostsTests.test_lookupAllRecords.<locals>.resolved)r2�lookupAllRecordsr:rErrr�test_lookupAllRecords�s
z HostsTests.test_lookupAllRecordscCs|�|j�d�t�S)Nr7)�
assertFailurer2ZlookupMailExchange�NotImplementedErrorrrrr�test_notImplemented�s�zHostsTests.test_notImplementedcs&�j�td��}|��fdd��|S)Nr7cs��|ddj��d�S)Nrr8)r"ZpayloadZ
dottedQuad)�xrrr�<lambda>�s�z'HostsTests.test_query.<locals>.<lambda>)r2Zqueryr
r:)rrFrrr�
test_query�szHostsTests.test_querycCs|�|j�d�t�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.
        �foueoa)rNr2rDrrrrr�test_lookupAddressNotFound�s�z%HostsTests.test_lookupAddressNotFoundcCs|�|j�d�t�S)zj
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupIPV6Address}.
        rT)rNr2rIrrrrr�test_lookupIPV6AddressNotFound�s�z)HostsTests.test_lookupIPV6AddressNotFoundcCs|�|j�d�t�S)zi
        Like L{test_lookupAddressNotFound}, but for
        L{hosts.Resolver.lookupAllRecords}.
        rT)rNr2rLrrrrr�test_lookupAllRecordsNotFound�s�z(HostsTests.test_lookupAllRecordsNotFoundN)rrrr)r4r6r?rGrJrMrPrSrUrVrWrrrrr0|s	
	r0N)r)Z
__future__rrZtwisted.trial.unittestrZtwisted.python.filepathrZtwisted.internet.deferrZtwisted.names.dnsrr	r
rrr
rrZtwisted.names.hostsrrr�objectrrr*r0rrrr�<module>s(;(