U
    
W[!  ã                   @   sr   d Z ddlmZm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?)
é    )ÚdivisionÚabsolute_import)Úimplementer)ÚdeferÚ
interfaces)ÚdnsÚcommonÚ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   )	Ztrapr   ÚDomainErrorr   ÚTimeoutErrorÚNotImplementedErrorr   r   r   )r   Z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||ƒ¡}qB|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   ZQueryr   Ú
addErrbackr
   )r   ÚnameÚclsÚtyper   ÚqÚdÚrr   r   r   Ú_lookup0   s    ÿzResolverChain._lookupNc                 C   sR   | j st t ¡ ¡S | j d  ||¡}| j dd … D ]}| t|j||ƒ¡}q4|S )Nr   r   )r   r   r   r	   r   ÚlookupAllRecordsr   r
   )r   r    r   r$   r%   r   r   r   r'   W   s    ÿzResolverChain.lookupAllRecords)N)r   r   r   Ú__doc__r   r&   r'   r   r   r   r   r   "   s   	'r   N)r(   Z
__future__r   r   Zzope.interfacer   Ztwisted.internetr   r   Ztwisted.namesr   r   r	   r
   Z	IResolverr   r   r   r   r   r   Ú<module>   s   