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/__pycache__/hosts.cpython-38.pyc
U

��W[��@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZd
d�Zdd
�ZGdd�dej�ZdS)z
hosts(5) support.
�)�division�absolute_import)�nativeString)�dns)�failure)�FilePath)�defer)�isIPAddress)�commoncCs�g}z|����}Wn|YSX|��}|D]`}|�d�}|dkrT|d|�}|sZq2|��}|��dd�|dd�D�kr2|�t|d��q2|S)a�
    Search the given file, which is in hosts(5) standard format, for an address
    entry with a given name.

    @param hostsFile: The name of the hosts(5)-format file to search.
    @type hostsFile: L{FilePath}

    @param name: The name to search for.
    @type name: C{str}

    @return: L{None} if the name is not found in the file, otherwise a
        C{str} giving the address in the file associated with the name.
    �#���NcSsg|]}|���qS�)�lower)�.0�sr
r
�5/usr/lib/python3/dist-packages/twisted/names/hosts.py�
<listcomp>1sz$searchFileForAll.<locals>.<listcomp>�r)Z
getContent�
splitlinesr�find�split�appendr)Z	hostsFile�nameZresults�lines�line�idx�partsr
r
r�searchFileForAlls 

rcCstt|�|�}|r|dSdS)a
    Grep given file, which is in hosts(5) standard format, for an address
    entry with a given name.

    @param file: The name of the hosts(5)-format file to search.

    @param name: The name to search for.
    @type name: C{str}

    @return: L{None} if the name is not found in the file, otherwise a
        C{str} giving the address in the file associated with the name.
    rN)rr)�filerZ	addressesr
r
r�
searchFileFor7s
rc@sJeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
d�Zddd�Z	eZ
dS)�Resolverz9
    A resolver that services hosts(5) format files.
    �
/etc/hosts�cCstj�|�||_||_dS)N)r
�ResolverBase�__init__r�ttl)�selfrr%r
r
rr$OszResolver.__init__cs$t��fdd�tt�j���D��S)zv
        Return a tuple of L{dns.RRHeader} instances for all of the IPv4
        addresses in the hosts file.
        cs6g|].}t|�rt��tjtj�jt�|�j���qSr
)r	r�RRHeader�A�INr%ZRecord_A�rZaddr�rr&r
rrZs
��z&Resolver._aRecords.<locals>.<listcomp>��tuplerrr�r&rr
r+r�	_aRecordsUs�zResolver._aRecordscs$t��fdd�tt�j���D��S)zv
        Return a tuple of L{dns.RRHeader} instances for all of the IPv6
        addresses in the hosts file.
        cs6g|].}t|�st��tjtj�jt�|�j���qSr
)r	rr'ZAAAAr)r%ZRecord_AAAAr*r+r
rrgs
��z)Resolver._aaaaRecords.<locals>.<listcomp>r,r.r
r+r�_aaaaRecordsbs�zResolver._aaaaRecordscCs*|rt�|ddf�St�t�t�|���S)aF
        Generate a response for the given name containing the given result
        records, or a failure if there are no result records.

        @param name: The DNS name the response is for.
        @type name: C{str}

        @param records: A tuple of L{dns.RRHeader} instances giving the results
            that will go into the response.

        @return: A L{Deferred} which will fire with a three-tuple of result
            records, authority records, and additional records, or which will
            fail with L{dns.DomainError} if there are no result records.
        r
)rZsucceedZfailrZFailurerZDomainError)r&rZrecordsr
r
r�_respondoszResolver._respondNcCs|�||�|��S)zm
        Read any IPv4 addresses from C{self.file} and return them as L{Record_A}
        instances.
        )r1r/�r&rZtimeoutr
r
r�
lookupAddress�szResolver.lookupAddresscCs|�||�|��S)zp
        Read any IPv6 addresses from C{self.file} and return them as
        L{Record_AAAA} instances.
        )r1r0r2r
r
r�lookupIPV6Address�szResolver.lookupIPV6Address)r!r")N)N)�__name__�
__module__�__qualname__�__doc__r$r/r0r1r3r4ZlookupAllRecordsr
r
r
rr Ks





r N)r8Z
__future__rrZtwisted.python.compatrZ
twisted.namesrZtwisted.pythonrZtwisted.python.filepathrZtwisted.internetrZtwisted.internet.abstractr	r
rrr#r r
r
r
r�<module>s#