ϪfdZddlmZddlmZmZddlmZmZddl m Z ddl m Z ddl mZdZd ZGd d ej"Zy ) z hosts(5) support. )defer) isIPAddress isIPv6Address)commondns)failure) nativeString)FilePathcg} |jj}|j}|D]}|j d}|dk7r|d|}|s!|j }|j|ddDcgc]}|jc}vsc t |d}t|s t|s|j||S#t$r|cYSwxYwcc}w#t$rYwxYw)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. #Nr) getContent splitlines BaseExceptionlowerfindsplitr ValueErrorrrappend) hostsFilenameresultslineslineidxpartssmaybeIPs 5/usr/lib/python3/dist-packages/twisted/names/hosts.pysearchFileForAllr!sG$$&113 ::eZdZdZd dZdZdZdZd dZd dZ eZ y) Resolverz9 A resolver that services hosts(5) format files. c^tjj|||_||_yN)r ResolverBase__init__r#ttl)selfr#r-s r r,zResolver.__init__Ss$$$T* r&cjtfdttjDS)zv Return a tuple of L{dns.RRHeader} instances for all of the IPv4 addresses in the hosts file. c 3K|]l}t|r_tjtjtjj tj |j nywr*)rrRRHeaderAINr-Record_A.0addrrr.s r z%Resolver._aRecords..]sM 4  LLsuucffdhh T4888T U A2A5tupler!r r#r.rs``r _aRecordszResolver._aRecordsXs/  ($))).hsR T" LLchh#//$2Q  r9r:r<s``r _aaaaRecordszResolver._aaaaRecordscs1  )$))) =='2r!23 3zz'//#//$*?@AAr&Ncntj|}|j||j|S)zm Read any IPv4 addresses from C{self.file} and return them as L{Record_A} instances. )r domainStringrJr=r.rtimeouts r lookupAddresszResolver.lookupAddresss. %}}T4>>$#788r&cntj|}|j||j|S)zp Read any IPv6 addresses from C{self.file} and return them as L{Record_AAAA} instances. )rrLrJrBrMs r lookupIPV6AddresszResolver.lookupIPV6Addresss0 %}}T4#4#4T#:;;r&)s /etc/hostsir*) __name__ __module__ __qualname____doc__r,r=rBrJrOrQlookupAllRecordsrDr&r r(r(Ns.    B&9<%r&r(N)rUtwisted.internetrtwisted.internet.abstractrr twisted.namesrrtwisted.pythonrtwisted.python.compatr twisted.python.filepathr r!r%r+r(rDr&r r]s=  #@%".,$N*I%v""I%r&