
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me
                 @   s*   d dl mZ d dlmZ G dd dZdS )    )StringIO)chop_commentc               @   sD   e 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S )	HostsConfc             C   s   || _ d | _d S )N)_text	_contents)selftext r	   /usr/lib/python3.6/hosts.py__init__   s    zHostsConf.__init__c             C   s   | j d kr| j| j| _ d S )N)r   _parser   )r   r	   r	   r
   parse   s    
zHostsConf.parsec             C   sZ   | j   g }xH| jD ]>\}}|dkr|\}}t|r|d |kr|j|dd   qW |S )Noptionr      )r   r   lenappend)r   ipZoptions	line_type
componentspieces_tailr	   r	   r
   	get_entry   s    zHostsConf.get_entryc             C   s|   | j   g }xd| jD ]Z\}}|dkr6|j||f qq|\}}t|rT|d |krTqt|r|j|t|f qW || _d S )Nr   r   )r   r   r   r   list)r   r   Z	n_entriesr   r   r   r   r	   r	   r
   del_entries"   s    zHostsConf.del_entriesc             G   s,   | j   | jjd||gt| dff d S )Nr    )r   r   r   r   )r   r   Zcanonical_hostnamealiasesr	   r	   r
   	add_entry1   s    zHostsConf.add_entryc             C   s|   g }xr|j  D ]f}t|j s0|jd|gf qt|j d\}}t|s\|jd|gf q|jd|jd |gf qW |S )Nblank#all_commentr   )
splitlinesr   stripr   r   split)r   contentsZentrieslineheadtailr	   r	   r
   r   7   s    zHostsConf._parsec             C   s   | j   t }x| jD ]z\}}|dkr:|jd|d   q|dkrV|jd|d   q|dkr|\}}dd |D }dj|}|jd	||f  qW |j S )
Nr   z%s
r   r   r   c             S   s   g | ]}t |qS r	   )str).0pr	   r	   r
   
<listcomp>N   s    z%HostsConf.__str__.<locals>.<listcomp>	z%s%s
)r   r   r   writejoingetvalue)r   r#   r   r   r   r&   r	   r	   r
   __str__D   s    
zHostsConf.__str__N)
__name__
__module____qualname__r   r   r   r   r   r   r/   r	   r	   r	   r
   r      s   
r   N)ior   Zcloudinit.distros.parsersr   r   r	   r	   r	   r
   <module>   s   