HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/names/__pycache__/root.cpython-38.pyc
U


W[�0�@stdZddlmZddlmZddlmZmZmZGdd�d�Z	Gdd�dej
�Zd	d
�ZGdd�d�Z
ddd�Zd
S)z�
Resolver implementation for querying successive authoritative servers to
lookup a record, starting from the root nameservers.

@author: Jp Calderone

todo::
    robustify it
    documentation
�)�Failure)�defer)�dns�common�errorc@seZdZdZdd�ZdS)�_DummyControllerz�
    A do-nothing DNS controller.  This is useful when all messages received
    will be responses to previously issued queries.  Anything else received
    will be ignored.
    cGsdS�N�)�self�argsr	r	�4/usr/lib/python3/dist-packages/twisted/names/root.py�messageReceivedsz _DummyController.messageReceivedN)�__name__�
__module__�__qualname__�__doc__r
r	r	r	rrsrc@sBeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�Resolverao
    L{Resolver} implements recursive lookup starting from a specified list of
    root servers.

    @ivar hints: See C{hints} parameter of L{__init__}
    @ivar _maximumQueries: See C{maximumQueries} parameter of L{__init__}
    @ivar _reactor: See C{reactor} parameter of L{__init__}
    @ivar _resolverFactory: See C{resolverFactory} parameter of L{__init__}
    �
NcCs<tj�|�||_||_||_|dkr2ddlm}||_dS)a�
        @param hints: A L{list} of L{str} giving the dotted quad
            representation of IP addresses of root servers at which to
            begin resolving names.
        @type hints: L{list} of L{str}

        @param maximumQueries: An optional L{int} giving the maximum
             number of queries which will be attempted to resolve a
             single name.
        @type maximumQueries: L{int}

        @param reactor: An optional L{IReactorTime} and L{IReactorUDP}
             provider to use to bind UDP ports and manage timeouts.
        @type reactor: L{IReactorTime} and L{IReactorUDP} provider

        @param resolverFactory: An optional callable which accepts C{reactor}
             and C{servers} arguments and returns an instance that provides a
             C{queryUDP} method. Defaults to L{twisted.names.client.Resolver}.
        @type resolverFactory: callable
        Nr�r)	r�ResolverBase�__init__�hints�_maximumQueries�_reactorZtwisted.names.clientr�_resolverFactory)r
rZmaximumQueries�reactor�resolverFactoryr	r	rr+szResolver.__init__cCsdd�|jD�S)z�
        Return a list of two-tuples representing the addresses of the root
        servers, as defined by C{self.hints}.
        cSsg|]}|tjf�qSr	)r�PORT)�.0Zipr	r	r�
<listcomp>Osz#Resolver._roots.<locals>.<listcomp>)r)r
r	r	r�_rootsJszResolver._rootscCs2|j||jd�}|�|g|�}|r.|�|j�|S)a�
        Issue one query and return a L{Deferred} which fires with its response.

        @param query: The query to issue.
        @type query: L{dns.Query}

        @param servers: The servers which might have an answer for this
            query.
        @type servers: L{list} of L{tuple} of L{str} and L{int}

        @param timeout: A timeout on how long to wait for the response.
        @type timeout: L{tuple} of L{int}

        @param filter: A flag indicating whether to filter the results.  If
            C{True}, the returned L{Deferred} will fire with a three-tuple of
            lists of L{twisted.names.dns.RRHeader} (like the return value of
            the I{lookup*} methods of L{IResolver}.  IF C{False}, the result
            will be a L{Message} instance.
        @type filter: L{bool}

        @return: A L{Deferred} which fires with the response or a timeout
            error.
        @rtype: L{Deferred}
        )�serversr)rrZqueryUDP�addCallbackZ
filterAnswers)r
�queryr!�timeout�filter�r�dr	r	r�_queryRs
zResolver._querycCs,|dkrd}|�t�|||�|��||j�S)z�
        Implement name lookup by recursively discovering the authoritative
        server for the name and then asking it, starting at one of the servers
        in C{self.hints}.
        N)����-)�_discoverAuthorityr�Queryr r)r
�name�cls�typer$r	r	r�_lookuprs�zResolver._lookupcCs@|dkrtt�d��S|�|||d�}|�|j|||d�|S)a#
        Issue a query to a server and follow a delegation if necessary.

        @param query: The query to issue.
        @type query: L{dns.Query}

        @param servers: The servers which might have an answer for this
            query.
        @type servers: L{list} of L{tuple} of L{str} and L{int}

        @param timeout: A C{tuple} of C{int} giving the timeout to use for this
            query.

        @param queriesLeft: A C{int} giving the number of queries which may
            yet be attempted to answer this query before the attempt will be
            abandoned.

        @return: A L{Deferred} which fires with a three-tuple of lists of
            L{twisted.names.dns.RRHeader} giving the response, or with a
            L{Failure} if there is a timeout or response error.
        rz"Query limit reached without resultFr))rr�
ResolverErrorr(r"�_discoveredAuthority)r
r#r!r$�queriesLeftr'r	r	rr-�s��zResolver._discoverAuthoritycs|jtjkr t��|j�|��Si�|jD]}��|jg��|�q*�fdd�}t	�}�j}d}	|�
|�|	�||�j�j�}	|	dkr�|�jkr��qn@��
t�t|��j�j�������}
�fdd�}|
�|�|
Sq`|	j�jkr�|j|j|jfS|	jj|k�rt�d��|	jj}q`i}|jD]&}
|
jtjk�r |
j��||
jj<�q g}g}|jD]H}
|
jtjk�rV|
jjj}||k�r�|�||tjf�n
|�|��qV|�r���
�|���S|�r���|d��}
dd	�}|
�|�|
�����fd
d��|
Stt�d��SdS)
as
        Interpret the response to a query, checking for error codes and
        following delegations if necessary.

        @param response: The L{Message} received in response to issuing C{query}.
        @type response: L{Message}

        @param query: The L{dns.Query} which was issued.
        @type query: L{dns.Query}.

        @param timeout: The timeout to use if another query is indicated by
            this response.
        @type timeout: L{tuple} of L{int}

        @param queriesLeft: A C{int} giving the number of queries which may
            yet be attempted to answer this query before the attempt will be
            abandoned.

        @return: A L{Failure} indicating a response error, a three-tuple of
            lists of L{twisted.names.dns.RRHeader} giving the response to
            C{query} or a L{Deferred} which will fire with one of those.
        csFd}��|g�D]0}|j|kr|j|kr0|S|jtjkr|}q|Sr)�getr0r1rZCNAME)r/r1r0Zcname�record)�recordsr	r�findAnswerOrCName�s

z8Resolver._discoveredAuthority.<locals>.findAnswerOrCNameNcs |\}}}|�d��|||fS�Nr)�insert�Zresults�answers�	authority�
additional)�previousr	r�
cbResolved�s
z1Resolver._discoveredAuthority.<locals>.cbResolvedzCycle in CNAME processingrcSs|\}}}|dj��Sr:)�payload�
dottedQuadr<r	r	r�
getOneAddresss
z4Resolver._discoveredAuthority.<locals>.getOneAddresscs���|tjfg��d�S)Nr))r-rr)Zhint)r5r#r
r$r	r�<lambda>s

�z/Resolver._discoveredAuthority.<locals>.<lambda>z/Stuck at response without answers or delegation)ZrCoderZOKrZexceptionForCoder=�
setdefaultr/�append�set�addr1r0r-r.�strr r"r>r?rBrr3�ArCZNSrZ
lookupAddress)r
Zresponser#r$r5Zanswerr9�seenr/r7r'rAZ	addressesZrrrZtraps�nsrDr	)r@r5r#r8r
r$rr4�s|


�
�





�
��zResolver._discoveredAuthority)rNN)
rrrrrr r(r2r-r4r	r	r	rr!s	�
 !rcs��fdd�}|S)Ncs�����fdd���S)Ncst|�����Sr)�getattr)r&)r�kwr/r	rrE�z6makePlaceholder.<locals>.placeholder.<locals>.<lambda>)r"�rrO��deferredr/rQr�placeholdersz$makePlaceholder.<locals>.placeholderr	)rSr/rTr	rRr�makePlaceholdersrUc@s$eZdZdd�Zdd�Zdd�ZdS)�DeferredResolvercCsg|_|�|j�dSr)�waitingr"�gotRealResolver)r
ZresolverDeferredr	r	rrszDeferredResolver.__init__cCs.|j}|j|_|j|_|D]}|�|�qdSr)rW�__dict__�	__class__�callback)r
�resolver�wr'r	r	rrX s
z DeferredResolver.gotRealResolvercCs>|�d�s|dkr2|j�t���t|jd|�St|��dS)N�lookup)�
getHostByNamer#���)�
startswithrWrGrZDeferredrU�AttributeError)r
r/r	r	r�__getattr__'szDeferredResolver.__getattr__N)rrrrrXrcr	r	r	rrVsrVNcsPdd�td�D�}�fdd�|D�}tj|dd�}�fdd�}|�|�t|�S)	a�
    Lookup the root nameserver addresses using the given resolver

    Return a Resolver which will eventually become a C{root.Resolver}
    instance that has references to all the root servers that we were able
    to look up.

    @param resolver: The resolver instance which will be used to
        lookup the root nameserver addresses.
    @type resolver: L{twisted.internet.interfaces.IResolverSimple}

    @param resolverFactory: An optional callable which returns a
        resolver instance. It will passed as the C{resolverFactory}
        argument to L{Resolver.__init__}.
    @type resolverFactory: callable

    @return: A L{DeferredResolver} which will be dynamically replaced
        with L{Resolver} when the root nameservers have been looked up.
    cSsg|]}ttd�|��qS)�a)�chr�ord)r�ir	r	rrCszbootstrap.<locals>.<listcomp>�
csg|]}��d|��qS)z%s.root-servers.net)r_)rr')r\r	rrDsT)Z
consumeErrorscstdd�|D��d�S)NcSsg|]}|dr|d�qS)rr)r	)r�er	r	rrIsz4bootstrap.<locals>.buildResolver.<locals>.<listcomp>)rrr)�res)rr	r�
buildResolverGs�z bootstrap.<locals>.buildResolver)�rangerZDeferredListr"rV)r\rZdomains�Lr'rkr	)r\rr�	bootstrap/s
rn)N)rZtwisted.python.failurerZtwisted.internetrZ
twisted.namesrrrrrrrUrVrnr	r	r	r�<module>su