/usr/lib/python3/dist-packages/twisted/names/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/names/__pycache__/hosts.cpython-310.pyc (5083B)
o
b @ sz d Z ddlmZ ddlmZmZ ddlmZmZ ddl m
Z
ddlmZ ddl
mZ dd Zd
d ZG dd
d
ejZdS )z
hosts(5) support.
)defer)isIPAddress
isIPv6Address)commondns)failure)nativeString)FilePathc C s g }z| }W n ty | Y S w | }|D ]F}|d}|dkr-|d| }|s0q| }| dd |dd D v rbzt|d }W n tyT Y qw t|s]t |rb|
| q|S )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.
#Nc S s g | ]}| qS )lower).0sr r 5/usr/lib/python3/dist-packages/twisted/names/hosts.py
/ s z$searchFileForAll.. r )
getContent
splitlines
BaseExceptionr
findsplitr
ValueErrorr r append) hostsFilenameresultslineslineidxpartsmaybeIPr r r searchFileForAll s0
r" c C s t t| |}|r
|d S dS )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 addressesr r r
searchFileFor9 s r% c @ sJ e Zd ZdZdddZdd Zdd Zd
d Zdd
dZdddZ eZ
dS )Resolverz9
A resolver that services hosts(5) format files.
/etc/hosts c C s t j| || _|| _d S N)r ResolverBase__init__r# ttl)selfr# r, r r r r+ S s
zResolver.__init__c $ t fddttj D S )zv
Return a tuple of L{dns.RRHeader} instances for all of the IPv4
addresses in the hosts file.
c 3 : | ]}t |rt tjtjjt|jV qd S r) )r r RRHeaderAINr, Record_Ar addrr r- r r ] s
z%Resolver._aRecords..tupler" r r# r- r r r6 r _aRecordsX s zResolver._aRecordsc r. )zv
Return a tuple of L{dns.RRHeader} instances for all of the IPv6
addresses in the hosts file.
c 3 r/ r) )r r r0 AAAAr2 r, Record_AAAAr4 r6 r r r7 h s
z(Resolver._aaaaRecords..r8 r: r r6 r _aaaaRecordsc s zResolver._aaaaRecordsc C s* |r
t |ddfS t tt|S )aF
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 )r succeedfailr Failurer DomainError)r- r recordsr r r _respondp s zResolver._respondNc C t |}| || |S )zm
Read any IPv4 addresses from C{self.file} and return them as
L{Record_A} instances.
)r domainStringrD r; r- r timeoutr r r
lookupAddress
zResolver.lookupAddressc C rE )zp
Read any IPv6 addresses from C{self.file} and return them as
L{Record_AAAA} instances.
)r rF rD r> rG r r r lookupIPV6Address rJ zResolver.lookupIPV6Address)r' r( r) )__name__
__module____qualname____doc__r+ r; r> rD rI rK lookupAllRecordsr r r r r&