Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/names/__pycache__/root.cpython-37.pyc

B

:��]�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�argsrr�E/opt/alt/python37/lib64/python3.7/site-packages/twisted/names/root.py�messageReceivedsz _DummyController.messageReceivedN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@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�resolverFactoryrrrr+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)�.0Ziprrr�
<listcomp>Osz#Resolver._roots.<locals>.<listcomp>)r)r	rrr�_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�drrr�_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�Queryrr)r	�name�cls�typer"rrr�_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!rr"�queriesLeftr%rrrr+�szResolver._discoverAuthoritycs|jtjkr t��|j�|��Si�x"|jD]}��|jg��|�q,W�fdd�}t	�}�j}d}	x�|�
|�|	�||�j�j�}	|	dkr�|�jkr�Pn@��
t�t|��j�j�������}
�fdd�}|
�|�|
Sqf|	j�jkr�|j|j|jfS|	jj|k�rt�d��|	jj}qfWi}x0|jD]&}
|
jtjk�r(|
j��||
jj<�q(Wg}g}xR|jD]H}
|
jtjk�rb|
jjj}||k�r�|�||tjf�n
|�|��qbW|�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}x<��|g�D],}|j|kr|j|kr.|S|jtjkr|}qW|S)N)�getr.r/rZCNAME)r-r/r.Zcname�record)�recordsrr�findAnswerOrCName�s

z8Resolver._discoveredAuthority.<locals>.findAnswerOrCNameNcs |\}}}|�d��|||fS)Nr)�insert)�results�answers�	authority�
additional)�previousrr�
cbResolved�s
z1Resolver._discoveredAuthority.<locals>.cbResolvedzCycle in CNAME processingrcSs|\}}}|dj��S)Nr)�payload�
dottedQuad)r9r:r;r<rrr�
getOneAddresss
z4Resolver._discoveredAuthority.<locals>.getOneAddresscs���|tjfg��d�S)Nr')r+rr)�hint)r3r!r	r"rr�<lambda>sz/Resolver._discoveredAuthority.<locals>.<lambda>z/Stuck at response without answers or delegation)ZrCoderZOKrZexceptionForCoder:�
setdefaultr-�append�set�addr/r.r+r,�strrr r;r<r?rr1�Ar@ZNSrZ
lookupAddress)r	�responser!r"r3Zanswerr7�seenr-r5r%r>Z	addressesZrrrZtraps�nsrAr)r=r3r!r6r	r"rr2�sj






zResolver._discoveredAuthority)rNN)
r
rrrrrr&r0r+r2rrrrr!s	
 !rcs��fdd�}|S)Ncs�����fdd���S)Ncst|�����S)N)�getattr)r$)r
�kwr-rrrC�z6makePlaceholder.<locals>.placeholder.<locals>.<lambda>)r )r
rN)�deferredr-)r
rNr�placeholdersz$makePlaceholder.<locals>.placeholderr)rPr-rQr)rPr-r�makePlaceholdersrRc@s$eZdZdd�Zdd�Zdd�ZdS)�DeferredResolvercCsg|_|�|j�dS)N)�waitingr �gotRealResolver)r	ZresolverDeferredrrrrszDeferredResolver.__init__cCs2|j}|j|_|j|_x|D]}|�|�qWdS)N)rT�__dict__�	__class__�callback)r	�resolver�wr%rrrrU s

z DeferredResolver.gotRealResolvercCs>|�d�s|dkr2|j�t���t|jd|�St|��dS)N�lookup)�
getHostByNamer!���)�
startswithrTrErZDeferredrR�AttributeError)r	r-rrr�__getattr__'szDeferredResolver.__getattr__N)r
rrrrUr`rrrrrSsrSNcsPdd�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�irrrrCszbootstrap.<locals>.<listcomp>�
csg|]}��d|��qS)z%s.root-servers.net)r\)rr%)rYrrrDsT)Z
consumeErrorscstdd�|D��d�S)NcSsg|]}|dr|d�qS)rr'r)r�errrrIsz4bootstrap.<locals>.buildResolver.<locals>.<listcomp>)rr)r)�res)rrr�
buildResolverGsz bootstrap.<locals>.buildResolver)�rangerZDeferredListr rS)rYrZdomains�Lr%rhr)rYrr�	bootstrap/s
rk)N)rZtwisted.python.failurerZtwisted.internetrZ
twisted.namesrrrrrrrRrSrkrrrr�<module>su