o
    ¯b±  ã                   @   sb   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 G dd„ dƒZ
eejƒG dd„ dejƒƒZd	S )
z´
Lookup a name using multiple resolvers.

Future Plans: This needs someway to specify which resolver answered
the query, or someway to specify (authority|ttl|cache behavior|more?)
é    )Úimplementer)ÚdeferÚ
interfaces)ÚcommonÚdnsÚerrorc                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFailureHandlerc                 C   s   || _ || _|| _d S ©N)ÚresolverÚqueryÚtimeout)Úselfr
   r   r   © r   ú7/usr/lib/python3/dist-packages/twisted/names/resolve.pyÚ__init__   s   
zFailureHandler.__init__c                 C   s"   |  tjtjt¡ |  | j| j¡S r	   )	Útrapr   ÚDomainErrorr   ÚTimeoutErrorÚNotImplementedErrorr
   r   r   )r   Úfailurer   r   r   Ú__call__   s   zFailureHandler.__call__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s    r   c                   @   s*   e Zd ZdZdd„ Zdd„ Zd	dd„ZdS )
ÚResolverChainz8
    Lookup an address using multiple L{IResolver}s
    c                 C   s   t j | ¡ || _dS )zi
        @type resolvers: L{list}
        @param resolvers: A L{list} of L{IResolver} providers.
        N)r   ÚResolverBaser   Ú	resolvers)r   r   r   r   r   r   %   s   
zResolverChain.__init__c                 C   s`   | j s
t t ¡ ¡S t |||¡}| j d  ||¡}| j dd… D ]}| t	|j||ƒ¡}q!|S )aN  
        Build a L{dns.Query} for the given parameters and dispatch it
        to each L{IResolver} in C{self.resolvers} until an answer or
        L{error.AuthoritativeDomainError} is returned.

        @type name: C{str}
        @param name: DNS name to resolve.

        @type type: C{int}
        @param type: DNS record type.

        @type cls: C{int}
        @param cls: DNS record class.

        @type timeout: Sequence of C{int}
        @param timeout: Number of seconds after which to reissue the query.
            When the last timeout expires, the query is considered failed.

        @rtype: L{Deferred}
        @return: A L{Deferred} which fires with a three-tuple of lists of
            L{twisted.names.dns.RRHeader} instances.  The first element of the
            tuple gives answers.  The second element of the tuple gives
            authorities.  The third element of the tuple gives additional
            information.  The L{Deferred} may instead fail with one of the
            exceptions defined in L{twisted.names.error} or with
            C{NotImplementedError}.
        r   é   N)
r   r   Úfailr   r   r   ÚQueryr   Ú
addErrbackr   )r   ÚnameÚclsÚtyper   ÚqÚdÚrr   r   r   Ú_lookup-   s   zResolverChain._lookupNc                 C   sR   | j s
t t ¡ ¡S | j d  ||¡}| j dd … D ]}| t|j||ƒ¡}q|S )Nr   r   )r   r   r   r   r   ÚlookupAllRecordsr    r   )r   r!   r   r%   r&   r   r   r   r(   Q   s   zResolverChain.lookupAllRecordsr	   )r   r   r   Ú__doc__r   r'   r(   r   r   r   r   r      s
    $r   N)r)   Úzope.interfacer   Útwisted.internetr   r   Útwisted.namesr   r   r   r   Ú	IResolverr   r   r   r   r   r   Ú<module>   s   