
    i                     v    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e          ZdS )	z*
Private support for parsing /etc/hosts.

    )absolute_importdivisionprint_functionN)is_ipv4_addr)is_ipv6_addr)	iteritemsc                   X    e Zd ZdZ ej        dej                  ZddZd Z	d Z
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                     i | _         i | _        i | _        i | _        |Bt          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   s     E/usr/local/lib/python3.11/dist-packages/gevent/resolver/_hostsfile.py__init__zHostsFile.__init__4   s~    =w'!!$D**>@ @
z    c                    t          | j        d          5 }|                                }d d d            n# 1 swxY w Y   t          |t                    s|                    d          n|}| j                            |          S )Nrbignore)errors)openr   read
isinstancestrdecodeLINES_REfindall)r   fpfdataudatas       r   
_readlineszHostsFile._readlinesD   s     $*d## 	rGGIIE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 6@s5K5KVH---QV}$$U+++s   7;;c                    	 t          j        | j                  j        }|| j        k    }n?# t
          $ r2 ddlm}   |            j        | gt          j
                    R   d}Y nw xY w|sd S i }i }i }i }|                                 D ]}|                                }	t          |	          dk     r+|	                    d          }
t          |
          r|}n)t!          |
          r|
                    d          rw|}n{|	                    d                                          }|
||<   |	D ] }|                                }|
||<   |||<   !||u r9d                    t)          |
                    d                              dz   }n|
dz   }||vr|||<   || _        || _        || _        || _        || _        d S )	Nr   )get_hubF   fe80.z.in-addr.arpaz
.ip6.arpa.)r   statr   st_mtimer   OSErrorgeventr,   handle_errorsysexc_infor*   splitlenpopr   r   
startswithlowerjoinreversedr   r   r   r   )r   	load_time
needs_loadr,   r   r   r   r   linepartsipipmapcnamealiasptrs                  r   loadzHostsFile.loadS   s   	
++4I"T_4JJ 	 	 	&&&&&&"GGII"49#,..9999JJJ	
  	FOO%% 	% 	%DJJLLE5zzA~~1BB b!! ==(( IIaLL&&((EE%L ' '!e!& {{hhx6677/I<''!!$#s   ), 9A('A(c              #      K   |                                   t          | j                  D ]\  }}||fV  t          | j                  D ]\  }}||fV  d S N)rG   r   r   r   )r   r   addrs      r   iter_all_host_addr_pairsz"HostsFile.iter_all_host_addr_pairs   s}      		#DG,, 	 	JD$*#DG,, 	 	JD$*	 	r   rI   )__name__
__module____qualname____doc__recompileVERBOSEr%   r   r*   rG   rK    r   r   r
   r
   '   s          rz  
 H    , , ,7 7 7r    r   r
   )rO   
__future__r   r   r   r5   r   rP   gevent.resolver._addressesr   r   gevent._compatr   objectr
   rS   r   r   <module>rX      s   .  A @ @ @ @ @ @ @ @ @ 



 				 				 3 3 3 3 3 3 3 3 3 3 3 3 $ $ $ $ $ $j j j j j j j j j jr   