
    <|h                     n    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y)	z*
Private support for parsing /etc/hosts.

    )absolute_importdivisionprint_functionN)is_ipv4_addr)is_ipv6_addr)	iteritemsc                   d    e Zd ZdZ ej
                  dej                        ZddZd Z	d Z
d Zy)		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 | _        |Ht        j
                  dk(  rd}n2t        j
                  dk(  rt        j                  j                  d      }|| _        | j                  sJ d| _	        y )Nposixz
/etc/hostsntz'%SystemRoot%\system32\drivers\etc\hostsr   )
v4v6aliasesreverseosnamepath
expandvarsfname
_last_load)selfr   s     Y/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/resolver/_hostsfile.py__init__zHostsFile.__init__4   sq    =ww'!$D**>@
zzz    c                     t        | j                  d      5 }|j                         }d d d        t        t              s|j                  d      n|}| j                  j                  |      S # 1 sw Y   HxY w)Nrbignore)errors)openr   read
isinstancestrdecodeLINES_REfindall)r   fpfdataudatas       r   
_readlineszHostsFile._readlinesD   sh     $**d# 	rGGIE	
 6@s5KH-QV}}$$U++	 	s   A//A8c                 H   	 t        j                  | j                        j                  }|| j                  kD  }|sy i }i }i }i }| j                         D ]  }|j                         }	t        |	      dk  r"|	j                  d      }
t        |
      r|}n!t!        |
      r|
j#                  d      r^|}nb|	j                  d      j%                         }|
||<   |	D ]  }|j%                         }|
||<   |||<    ||u r-dj'                  t)        |
j                  d                  dz   }n|
dz   }||vs|||<    | _        || _        || _        || _        || _        y # t
        $ r6 ddlm}   |       j                  | gt        j                           d}Y fw xY w)	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   	

+44I"T__4J OO% 	%DJJLE5zA~1BBb!==(IIaL&&(EE%L '!e!&' {hhx67/I<''!$7	%: $]  	&"GI""49#,,.9J	s   8E" ";F! F!c              #      K   | j                          t        | j                        D ]  \  }}||f  t        | j                        D ]  \  }}||f  y wN)rG   r   r   r   )r   r   addrs      r   iter_all_host_addr_pairsz"HostsFile.iter_all_host_addr_pairs   s[     		#DGG, 	JD$*	#DGG, 	JD$*	s   AArI   )__name__
__module____qualname____doc__recompileVERBOSEr%   r   r*   rG   rK    r   r   r
   r
   '   s<     rzz  
H ,7rr   r
   )rO   
__future__r   r   r   r5   r   rP   gevent.resolver._addressesr   r   gevent._compatr   objectr
   rS   r   r   <module>rX      s3   . A @ 
 	 	 3 3 $j jr   