Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/hosts.cpython-37.pyc

B

��d^*�@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}y|����}Wn
|S|��}xh|D]`}|�d�}|dkrP|d|�}|sVq.|��}|��dd�|dd�D�kr.|�t|d��q.W|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{bytes}

    @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
�F/opt/alt/python37/lib64/python3.7/site-packages/twisted/names/hosts.py�
<listcomp>1sz$searchFileForAll.<locals>.<listcomp>�r)Z
getContent�
splitlinesr�find�split�appendr)Z	hostsFile�name�results�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.
    @type file: C{str} or C{bytes}

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

    @return: L{None} if the name is not found in the file, otherwise a
        C{str} giving the first address in the file associated with
        the name.
    rN)rr)�filerZ	addressesr
r
r�
searchFileFor7sr c@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%Qs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)r�addr)rr'r
rr]sz&Resolver._aRecords.<locals>.<listcomp>)�tuplerrr)r'rr
)rr'r�	_aRecordsWs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_AAAA)rr+)rr'r
rrjsz)Resolver._aaaaRecords.<locals>.<listcomp>)r,rrr)r'rr
)rr'r�_aaaaRecordsds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'r�recordsr
r
r�_respondqszResolver._respondNcCst�|�}|�||�|��S)zm
        Read any IPv4 addresses from C{self.file} and return them as
        L{Record_A} instances.
        )r�domainStringr0r-)r'r�timeoutr
r
r�
lookupAddress�s
zResolver.lookupAddresscCst�|�}|�||�|��S)zp
        Read any IPv6 addresses from C{self.file} and return them as
        L{Record_AAAA} instances.
        )rr1r0r.)r'rr2r
r
r�lookupIPV6Address�s
zResolver.lookupIPV6Address)r"r#)N)N)�__name__�
__module__�__qualname__�__doc__r%r-r.r0r3r4ZlookupAllRecordsr
r
r
rr!Ms



	
r!N)r8�
__future__rrZtwisted.python.compatrZ
twisted.namesrZtwisted.pythonrZtwisted.python.filepathrZtwisted.internetrZtwisted.internet.abstractr	r
rr r$r!r
r
r
r�<module>s#