a
    sd_H'                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZ ejjZejjZG dd dejjZdadd Zdd	 Zejjejjd
dddddfddZdd Zejjd
ddfddZdS )zAsynchronous DNS stub resolver.    N)NXDOMAINNoAnswerNotAbsolute	NoRootSOAc                	   @   s@   e Zd Zejjejjdddddddf	ddZdd Z	d	d
 Z
dS )ResolverFNTr   c              
      s<  t j| ||||||	}|
s&t j }
t }| \}}|durF|S d}|s.| \}}}}|rr|
|I dH  | 	||}zVt j
|r|rt|||||||
dI dH }qt||||||d|
dI dH }ntW nB ty } z(|d|\}}W Y d}~qJW Y d}~n
d}~0 0 ||d\}}|durJ|S qJq.dS )a  Query nameservers asynchronously to find the answer to the question.

        The *qname*, *rdtype*, and *rdclass* parameters may be objects
        of the appropriate type, or strings that can be converted into objects
        of the appropriate type.

        *qname*, a ``dns.name.Name`` or ``str``, the query name.

        *rdtype*, an ``int`` or ``str``,  the query type.

        *rdclass*, an ``int`` or ``str``,  the query class.

        *tcp*, a ``bool``.  If ``True``, use TCP to make the query.

        *source*, a ``str`` or ``None``.  If not ``None``, bind to this IP
        address when making queries.

        *raise_on_no_answer*, a ``bool``.  If ``True``, raise
        ``dns.resolver.NoAnswer`` if there's no answer to the question.

        *source_port*, an ``int``, the port from which to send the message.

        *lifetime*, a ``float``, how many seconds a query should run
         before timing out.

        *search*, a ``bool`` or ``None``, determines whether the
        search list configured in the system's resolver configuration
        are used for relative names, and whether the resolver's domain
        may be added to relative names.  The default is ``None``,
        which causes the value of the resolver's
        ``use_search_by_default`` attribute to be used.

        *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
        the default, then dnspython will use the default backend.

        Raises ``dns.resolver.NXDOMAIN`` if the query name does not exist.

        Raises ``dns.resolver.YXDOMAIN`` if the query name is too long after
        DNAME substitution.

        Raises ``dns.resolver.NoAnswer`` if *raise_on_no_answer* is
        ``True`` and the query name exists but has no RRset of the
        desired type and class.

        Raises ``dns.resolver.NoNameservers`` if no non-broken
        nameservers are available to answer the question.

        Returns a ``dns.resolver.Answer`` instance.

        NFbackendT)Zraise_on_truncationr   )dnsresolverZ_ResolutionZasyncbackendZget_default_backendtimeZnext_requestZnext_nameserversleepZ_compute_timeoutZinetZ
is_address_tcp_udpNotImplementedError	ExceptionZquery_result)selfqnamerdtyperdclasstcpsourceraise_on_no_answersource_portZlifetimesearchr   Z
resolutionstartZrequestanswerZdoneZ
nameserverZportZbackoffZtimeoutZresponseex_ r   3/usr/lib/python3/dist-packages/dns/asyncresolver.pyresolve'   sH    8
"zResolver.resolvec                    s   t d S )N)r   )r   argskwargsr   r   r   query   s    zResolver.queryc                    s4   | j tj|g|R tjjtjjd|I dH S )a  Use an asynchronous resolver to run a reverse query for PTR
        records.

        This utilizes the resolve() method to perform a PTR lookup on the
        specified IP address.

        *ipaddr*, a ``str``, the IPv4 or IPv6 address you want to get
        the PTR record for.

        All other arguments that can be passed to the resolve() function
        except for rdtype and rdclass are also supported by this
        function.

        )r   r   N)r    r	   ZreversenameZfrom_address	rdatatypeZPTR
rdataclassIN)r   ipaddrr!   r"   r   r   r   resolve_address   s    zResolver.resolve_address)__name__
__module____qualname__r	   r$   Ar%   r&   r    r#   r(   r   r   r   r   r   %   s   
gr   c                   C   s   t du rt  t S )zDGet the default asynchronous resolver, initializing it if necessary.N)default_resolverreset_default_resolverr   r   r   r   get_default_resolver   s    r/   c                   C   s
   t  adS )zRe-initialize default asynchronous resolver.

    Note that the resolver configuration (i.e. /etc/resolv.conf on UNIX
    systems) will be re-read immediately.
    N)r   r-   r   r   r   r   r.      s    r.   FTc	           	         s"   t  | ||||||||	I dH S )a  Query nameservers asynchronously to find the answer to the question.

    This is a convenience function that uses the default resolver
    object to make the query.

    See ``dns.asyncresolver.Resolver.resolve`` for more information on the
    parameters.
    N)r/   r    )	r   r   r   r   r   r   r   r   r   r   r   r   r       s    r    c                    s    t  j| g|R i |I dH S )zUse a resolver to run a reverse query for PTR records.

    See ``dns.asyncresolver.Resolver.resolve_address`` for more
    information on the parameters.
    N)r/   r(   )r'   r!   r"   r   r   r   r(      s    r(   c              	      s   t | trtj| tjj} |du r*t }|  s:t| z4|j	| tj
j|||dI dH }|jj| krl| W S W n ttfy   Y n0 z|  } W q: tjjy   tY q:0 q:dS )a  Find the name of the zone which contains the specified name.

    *name*, an absolute ``dns.name.Name`` or ``str``, the query name.

    *rdclass*, an ``int``, the query class.

    *tcp*, a ``bool``.  If ``True``, use TCP to make the query.

    *resolver*, a ``dns.asyncresolver.Resolver`` or ``None``, the
    resolver to use.  If ``None``, the default resolver is used.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    Raises ``dns.resolver.NoRootSOA`` if there is no SOA RR at the DNS
    root.  (This is only likely to happen if you're using non-default
    root servers in your network and they are misconfigured.)

    Returns a ``dns.name.Name``.
    Nr   )
isinstancestrr	   nameZ	from_textrootr/   Zis_absoluter   r    r$   ZSOAZrrsetr   r   parentZNoParentr   )r2   r   r   r
   r   r   r   r   r   zone_for_name   s$    

r5   )__doc__r   Zdns.asyncbackendr	   Zdns.asyncqueryZdns.exceptionZ	dns.queryZdns.resolverr   r   r   r   Z
asyncqueryZudpr   r   r   r
   r   r-   r/   r.   r$   r,   r%   r&   r    r(   r5   r   r   r   r   <module>   s,    

