o
    e                     @   sh   d Z ddlmZmZmZ ddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ G dd deZdS )	z*
Private support for parsing /etc/hosts.

    )absolute_importdivisionprint_functionN)is_ipv4_addr)is_ipv6_addr)	iteritemsc                   @   s@   e Zd ZdZedejZdddZdd Z	dd	 Z
d
d ZdS )	HostsFilezD
    A class to read the contents of a hosts file (/etc/hosts).
    z
        \s*  # Leading space
        ([^\r\n#]+?)  # The actual match, non-greedy so as not to include trailing space
        \s*  # Trailing space
        (?:[#][^\r\n]+)?  # Comments
        (?:$|[\r\n]+)  # EOF or newline
    Nc                 C   s`   i | _ i | _i | _i | _|d u r#tjdkrd}ntjdkr#tjd}|| _| js+J d| _	d S )Nposixz
/etc/hostsntz'%SystemRoot%\system32\drivers\etc\hostsr   )
v4v6aliasesreverseosnamepath
expandvarsfname
_last_load)selfr    r   JD:\Projects\ConvertPro\env\Lib\site-packages\gevent/resolver/_hostsfile.py__init__4   s   



zHostsFile.__init__c                 C   sZ   t | jd}| }W d    n1 sw   Y  t|ts%|jddn|}| j|S )Nrbignore)errors)openr   read
isinstancestrdecodeLINES_REfindall)r   fpfdataZudatar   r   r   
_readlinesD   s
   
zHostsFile._readlinesc                 C   s\  zt | jj}|| jk}W n ty+   ddlm} | j| gt	
 R   d}Y nw |s0d S i }i }i }i }|  D ]`}| }	t|	dk rIq<|	d}
t|
rU|}nt|
rb|
dr_q<|}nq<|	d }|
||< |	D ]}| }|
||< |||< qp||u rdt|
dd }n|
d }||vr|||< q<|| _|| _|| _|| _|| _d S )	Nr   )get_hubF   Zfe80.z.in-addr.arpaz
.ip6.arpa.)r   statr   st_mtimer   OSErrorZgeventr&   handle_errorsysexc_infor%   splitlenpopr   r   
startswithlowerjoinreversedr   r   r   r   )r   Z	load_timeZ
needs_loadr&   r   r   r   r   linepartsipZipmapcnamealiasptrr   r   r   loadS   sV   



zHostsFile.loadc                 c   sJ    |    t| jD ]	\}}||fV  q
t| jD ]	\}}||fV  qd S N)r<   r   r   r   )r   r   addrr   r   r   iter_all_host_addr_pairs   s   z"HostsFile.iter_all_host_addr_pairsr=   )__name__
__module____qualname____doc__recompileVERBOSEr!   r   r%   r<   r?   r   r   r   r   r   '   s    
9r   )rC   
__future__r   r   r   r-   r   rD   Zgevent.resolver._addressesr   r   Zgevent._compatr   objectr   r   r   r   r   <module>   s   