File: //usr/lib/python3/dist-packages/twisted/names/__pycache__/hosts.cpython-38.pyc
U
��W[� � @ s� d Z ddlmZmZ ddlmZ ddlmZ ddlm Z ddl
mZ ddlm
Z
ddlmZ dd lmZ d
d� Zdd
� ZG dd� dej�ZdS )z
hosts(5) support.
� )�division�absolute_import)�nativeString)�dns)�failure)�FilePath)�defer)�isIPAddress)�commonc C s� g }z| � � �� }W n | Y S X |�� }|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.
� #���Nc S s g | ]}|� � �qS � )�lower)�.0�sr
r
�5/usr/lib/python3/dist-packages/twisted/names/hosts.py�
<listcomp>1 s z$searchFileForAll.<locals>.<listcomp>� r )Z
getContent�
splitlinesr �find�split�appendr )Z hostsFile�nameZresults�lines�line�idx�partsr
r
r �searchFileForAll s
r c C s t t| �|�}|r|d S dS )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.
r N)r r )�filer Z addressesr
r
r �
searchFileFor7 s
r c @ sJ e Zd ZdZddd�Zdd� Zdd � Zd
d� Zdd
d�Zddd�Z eZ
dS )�Resolverz9
A resolver that services hosts(5) format files.
�
/etc/hosts� c C s t j�| � || _|| _d S )N)r
�ResolverBase�__init__r �ttl)�selfr r% r
r
r r$ O s zResolver.__init__c s$ 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 s6 g | ].}t |�rt�� tjtj�jt�|�j���qS r
)r r �RRHeader�A�INr% ZRecord_A�r Zaddr�r r&