
    h                         S r SSKJr  SSKJrJr  SSKJrJr  SSK	J
r
  SSKJr  SSKJr  S rS	 r " S
 S\R"                  5      rg)z
hosts(5) support.
    )defer)isIPAddressisIPv6Address)commondns)failure)nativeString)FilePathc                 &   / n U R                  5       R                  5       nUR                  5       nU H  nUR	                  S5      nUS:w  a  USU nU(       d  M(  UR                  5       nUR                  5       USS  Vs/ s H  owR                  5       PM     sn;   d  Mo   [        US   5      n[        U5      (       d  [        U5      (       d  M  UR                  U5        M     U$ ! [         a    Us $ f = fs  snf ! [         a     M  f = f)a  
Search the given file, which is in hosts(5) standard format, for addresses
associated 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{bytes}

@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.
   #N   r   )
getContent
splitlinesBaseExceptionlowerfindsplitr	   
ValueErrorr   r   append)		hostsFilenameresultslineslineidxpartssmaybeIPs	            Z/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/names/hosts.pysearchFileForAllr!      s     G$$&113 ::<Diio"9:D

::<uQRy9y!GGIy99&uQx0 7##}W'='=w'  N'   :  s)   C+ C=$D+C:9C:
DDc                 F    [        [        U 5      U5      nU(       a  US   $ g)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.
@type file: C{str} or C{bytes}

@param name: The name to search for.
@type name: C{bytes}

@return: L{None} if the name is not found in the file, otherwise a
    C{str} giving the first address in the file associated with
    the name.
r   N)r!   r
   )filer   	addressess      r    searchFileForr%   9   s$     !$6I|    c                   L    \ rS rSrSrSS jrS rS rS rSS jr	SS	 jr
\	rS
rg)ResolverN   z1
A resolver that services hosts(5) format files.
c                 Z    [         R                  R                  U 5        Xl        X l        g N)r   ResolverBase__init__r#   ttl)selfr#   r.   s      r    r-   Resolver.__init__S   s     $$T*	r&   c                 l   ^ ^ [        UU 4S j[        [        T R                  5      T5       5       5      $ )z^
Return a tuple of L{dns.RRHeader} instances for all of the IPv4
addresses in the hosts file.
c              3     >#    U  Hv  n[        U5      (       d  M  [        R                  " T[        R                  [        R                  TR
                  [        R                  " UTR
                  5      5      v   Mx     g 7fr+   )r   r   RRHeaderAINr.   Record_A.0addrr   r/   s     r    	<genexpr>%Resolver._aRecords.<locals>.<genexpr>]   sR      
C4  VCLLsuucffdhhT4888TUUC   BA&Btupler!   r
   r#   r/   r   s   ``r    	_aRecordsResolver._aRecordsX   s/    
  
($)))<dC
 
 	
r&   c                 l   ^ ^ [        UU 4S j[        [        T R                  5      T5       5       5      $ )z^
Return a tuple of L{dns.RRHeader} instances for all of the IPv6
addresses in the hosts file.
c              3     >#    U  Hv  n[        U5      (       d  M  [        R                  " T[        R                  [        R                  TR
                  [        R                  " UTR
                  5      5      v   Mx     g 7fr+   )r   r   r3   AAAAr5   r.   Record_AAAAr7   s     r    r:   (Resolver._aaaaRecords.<locals>.<genexpr>h   s\      
 DT"	CLLchh#//$2Q  Dr<   r=   r?   s   ``r    _aaaaRecordsResolver._aaaaRecordsc   s1    
  
 )$)))<dC	
 
 	
r&   c                     U(       a  [         R                  " USS45      $ [         R                  " [        R                  " [
        R                  " U5      5      5      $ )a  
Generate a response for the given name containing the given result
records, or a failure if there are no result records.

@param name: The DNS name the response is for.
@type name: C{str}

@param records: A tuple of L{dns.RRHeader} instances giving the results
    that will go into the response.

@return: A L{Deferred} which will fire with a three-tuple of result
    records, authority records, and additional records, or which will
    fail with L{dns.DomainError} if there are no result records.
 )r   succeedfailr   Failurer   DomainError)r/   r   recordss      r    _respondResolver._respondp   s>     =='2r!233zz'//#//$*?@AAr&   Nc                 n    [         R                  " U5      nU R                  XR                  U5      5      $ )zU
Read any IPv4 addresses from C{self.file} and return them as
L{Record_A} instances.
)r   domainStringrP   r@   r/   r   timeouts      r    lookupAddressResolver.lookupAddress   s,    
 %}}T>>$#788r&   c                 n    [         R                  " U5      nU R                  XR                  U5      5      $ )zX
Read any IPv6 addresses from C{self.file} and return them as
L{Record_AAAA} instances.
)r   rS   rP   rG   rT   s      r    lookupIPV6AddressResolver.lookupIPV6Address   s.    
 %}}T#4#4T#:;;r&   )r#   r.   )s
   /etc/hostsi  r+   )__name__
__module____qualname____firstlineno____doc__r-   r@   rG   rP   rV   rY   lookupAllRecords__static_attributes__rJ   r&   r    r(   r(   N   s.    
	

B&9< %r&   r(   N)r_   twisted.internetr   twisted.internet.abstractr   r   twisted.namesr   r   twisted.pythonr   twisted.python.compatr	   twisted.python.filepathr
   r!   r%   r,   r(   rJ   r&   r    <module>rh      s=   

 # @ % " . ,$N*I%v"" I%r&   