HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/dns/__pycache__/resolver.cpython-37.pyc
B

��f���@s�UdZddlmZmZmZmZmZmZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZej dkr�ddl!ZGdd�dej"j#�Z$Gdd	�d	ej"j#�Z%eee&e'e(ee)e&feej*j+fZ,ee,ee&d
�dd�Z-Gd
d�dej"j.�Z/e/Z.Gdd�dej"j#�Z0Gdd�dej"j#�Z1Gdd�dej"j#�Z2Gdd�dej"j#�Z3Gdd�dej"j#�Z4Gdd�dej"j#�Z5Gdd�d�Z6Gdd�d�Z7Gdd �d �Z8eej9j:ej;j<ej=j>fZ?Gd!d"�d"e8�Z@Gd#d$�d$�ZAGd%d&�d&e8�ZBGd'd(�d(�ZCGd)d*�d*�ZDGd+d,�d,eD�ZEdaFeeEeGd-<eEd.�d/d0�ZHd1d2�ZIej;jJej=jKd3dd4dddfeej9j:e&feej;j<e&feej=j>e&fe'ee&e'e(eeLee'e6d5�
d6d7�ZMej;jJej=jKd3dd4ddfeej9j:e&feej;j<e&feej=j>e&fe'ee&e'e(eeLe6d8�	d9d:�ZNe&eee6d;�d<d=�ZOeej9j:e&fej9j:d>�d?d@�ZPej=jKd3ddfeej9j:e&fej=j>e'eeEeeLej9j:dA�dBdC�ZQejRejSgejTejUgiZVdaWejXZYejZZ[ej\Z]ej^Z_ej`ZaejbZcddejddddfdDdE�ZedUdFdG�ZfdVdHdI�ZgdJdK�ZhdLdM�ZidNdO�ZjdWeeEddP�dQdR�Zkdd.�dSdT�ZldS)XzDNS stub resolver.�)�Any�Dict�List�Optional�Tuple�Union)�urlparseN�win32csneZdZdZddhZdZ�fdd�Zddd�Z�fd	d
�Ze	dd��Z
d
d�Zdd�Zdd�Z
dd�Z�ZS)�NXDOMAINz"The DNS query name does not exist.�qnames�	responsesNcst�j||�dS)N)�super�__init__)�self�args�kwargs)�	__class__��=/opt/alt/python37/lib/python3.7/site-packages/dns/resolver.pyr<szNXDOMAIN.__init__cCs\t|tttf�std��t|�dkr,td��|dkr:i}nt|t�sLtd��t||d�}|S)Nz#qnames must be a list, tuple or setrz(qnames must contain at least one elementz(responses must be a dict(qname=response))rr)�
isinstance�list�tuple�set�AttributeError�len�dict)rrrrrrr�
_check_kwargs?s
zNXDOMAIN._check_kwargscsPd|jkrt���S|jd}t|�dkr0d}nd}d�tt|��}d�||�S)Nr�zNone of DNS query names existz!The DNS query name does not existz, z{}: {})rr
�__str__r�join�map�str�format)rr�msg)rrrrKs


zNXDOMAIN.__str__c	Cspd|jkrtd��xN|jdD]@}|jd|}y|��}||krF|SWqtk
r\YqXqW|jddS)z%Return the unresolved canonical name.rzparametrized exception requiredrr)r�	TypeError�canonical_name�	Exception)r�qname�response�cnamerrrr%Vs

zNXDOMAIN.canonical_namecCs|t|j�dg��}t|j�di��}|j�di�}x<|j�dg�D]*}||krX|�|�||krB||||<qBWt||d�S)z3Augment by results from another NXDOMAIN exception.rr)rr)rr�getr�appendr
)rZe_nxZqnames0Z
responses0Z
responses1Zqname1rrr�__add__gs
zNXDOMAIN.__add__cCs
|jdS)zXAll of the names that were tried.

        Returns a list of ``dns.name.Name``.
        r)r)rrrrrsszNXDOMAIN.qnamescCs
|jdS)z�A map from queried names to their NXDOMAIN responses.

        Returns a dict mapping a ``dns.name.Name`` to a
        ``dns.message.Message``.
        r)r)rrrrrzszNXDOMAIN.responsescCs|jd|S)zTThe response for query *qname*.

        Returns a ``dns.message.Message``.
        r)r)rr'rrrr(�szNXDOMAIN.response)N)�__name__�
__module__�__qualname__�__doc__�supp_kwargs�fmtrrr�propertyr%r,rrr(�
__classcell__rr)rrr
2s
r
c@seZdZdZdS)�YXDOMAINz8The DNS query name is too long after DNAME substitution.N)r-r.r/r0rrrrr5�sr5)�errors�returnc
CsDg}x:|D]2}|�d�|d|dr(dnd|d|d��q
W|S)z3Turn a resolution errors trace into a list of text.z Server {} {} port {} answered {}rrZTCPZUDP��)r+r")r6Ztexts�errrrr�_errors_to_text�s
*r;csHeZdZdZdZdedd�ZddhZ�fdd�Z�fd	d
�Z�Z	S)�LifetimeTimeoutz The resolution lifetime expired.z(%s after {timeout:.3f} seconds: {errors}N����timeoutr6cst�j||�dS)N)r
r)rrr)rrrr�szLifetimeTimeout.__init__cs&t|d�}t�j|dd�|�d�S)Nr6r>z; )r>r6)r;r
�_fmt_kwargsr)rr�srv_msgs)rrrr?�szLifetimeTimeout._fmt_kwargs)
r-r.r/r0r#r2r1rr?r4rr)rrr<�sr<cs>eZdZdZdZdhZ�fdd�Z�fdd�Zdd	�Z�Z	S)
�NoAnswerz<The DNS response does not contain an answer to the question.zDThe DNS response does not contain an answer to the question: {query}r(cst�j||�dS)N)r
r)rrr)rrrr�szNoAnswer.__init__cst�j|djd�S)Nr()�query)r
r?�question)rr)rrrr?�szNoAnswer._fmt_kwargscCs
|jdS)Nr()r)rrrrr(�szNoAnswer.response)
r-r.r/r0r2r1rr?r(r4rr)rrrA�srAcsHeZdZdZdZdedd�ZddhZ�fdd	�Z�fd
d�Z�Z	S)�
NoNameserversz�All nameservers failed to answer the query.

    errors: list of servers and respective errors
    The type of errors is
    [(server IP address, any object convertible to string)].
    Non-empty errors list will add explanatory message ()
    z+All nameservers failed to answer the query.z%s {query}: {errors}Nr=�requestr6cst�j||�dS)N)r
r)rrr)rrrr�szNoNameservers.__init__cs(t|d�}t�j|djd�|�d�S)Nr6rEz; )rBr6)r;r
r?rCr)rrr@)rrrr?�szNoNameservers._fmt_kwargs)
r-r.r/r0r#r2r1rr?r4rr)rrrD�srDc@seZdZdZdS)�NotAbsolutezEAn absolute domain name is required but a relative name was provided.N)r-r.r/r0rrrrrF�srFc@seZdZdZdS)�	NoRootSOAzBThere is no SOA RR at the DNS root name. This should never happen!N)r-r.r/r0rrrrrG�srGc@seZdZdZdS)�
NoMetaqueriesz DNS metaqueries are not allowed.N)r-r.r/r0rrrrrH�srHc@seZdZdZdS)�NoResolverConfigurationzEResolver configuration could not be read or specified no nameservers.N)r-r.r/r0rrrrrI�srIc@sjeZdZdZdejjejjej	j
ejje
ee
ed�dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�ZdS)�Answera&DNS stub resolver answer.

    Instances of this class bundle up the result of a successful DNS
    resolution.

    For convenience, the answer object implements much of the sequence
    protocol, forwarding to its ``rrset`` attribute.  E.g.
    ``for a in answer`` is equivalent to ``for a in answer.rrset``.
    ``answer[i]`` is equivalent to ``answer.rrset[i]``, and
    ``answer[i:j]`` is equivalent to ``answer.rrset[i:j]``.

    Note that CNAMEs or DNAMEs in the response may mean that answer
    RRset's name might not be the query name.
    N)r'�rdtype�rdclassr(�
nameserver�portcCsX||_||_||_||_||_||_|��|_|jj|_|jj	|_
t��|jj|_
dS)N)r'rKrLr(rMrNZresolve_chainingZchaining_resultr%�answer�rrset�timeZminimum_ttl�
expiration)rr'rKrLr(rMrNrrrrs	


zAnswer.__init__cCs\|dkr|jjS|dkr |jjS|dkr0|jjS|dkr@|jjS|dkrP|jjSt|��dS)N�name�ttl�coversrLrK)rPrSrTrUrLrKr)r�attrrrr�__getattr__szAnswer.__getattr__cCs|jrt|j�pdS)Nr)rPr)rrrr�__len__'szAnswer.__len__cCs|jrt|j�ptt��S)N)rP�iterr)rrrr�__iter__*szAnswer.__iter__cCs|jdkrt�|j|S)N)rP�
IndexError)r�irrr�__getitem__-s
zAnswer.__getitem__cCs|jdkrt�|j|=dS)N)rPr[)rr\rrr�__delitem__2s
zAnswer.__delitem__)NN)r-r.r/r0�dnsrS�Name�	rdatatype�	RdataType�
rdataclass�
RdataClass�message�QueryMessagerr!�intrrWrXrZr]r^rrrrrJ�s2rJc@s0eZdZdZddd�Zdd�Zdd�dd	�Zd
S)�CacheStatisticszCache StatisticsrcCs||_||_dS)N)�hits�misses)rrirjrrrr;szCacheStatistics.__init__cCsd|_d|_dS)Nr)rirj)rrrr�reset?szCacheStatistics.reset)r7cCst|j|j�S)N)rhrirj)rrrr�cloneCszCacheStatistics.cloneN)rr)r-r.r/r0rrkrlrrrrrh8s
rhc@sLeZdZdd�Zdd�dd�Zed�dd�Zed�d	d
�Zed�dd�Z	dS)
�	CacheBasecCst��|_t�|_dS)N)�	threading�Lock�lockrh�
statistics)rrrrrHs
zCacheBase.__init__N)r7c	Cs |j�|j��WdQRXdS)zReset all statistics to zero.N)rprqrk)rrrr�reset_statisticsLszCacheBase.reset_statisticsc	Cs|j�
|jjSQRXdS)z How many hits has the cache had?N)rprqri)rrrrriQszCacheBase.hitsc	Cs|j�
|jjSQRXdS)z"How many misses has the cache had?N)rprqrj)rrrrrjVszCacheBase.missesc	Cs|j�|j��SQRXdS)z�Return a consistent snapshot of all the statistics.

        If running with multiple threads, it's better to take a
        snapshot than to call statistics methods such as hits() and
        misses() individually.
        N)rprqrl)rrrr�get_statistics_snapshot[sz!CacheBase.get_statistics_snapshot)
r-r.r/rrrrgrirjrhrsrrrrrmGs
rmcsreZdZdZded��fdd�
Zdd�dd	�Zeee	d
�dd�Z
ee	dd
�dd�Zdeedd
�dd�Z�Z
S)�Cachez$Simple thread-safe DNS answer cache.��r@)�cleaning_intervalcs*t���i|_||_t��|j|_dS)zf*cleaning_interval*, a ``float`` is the number of seconds between
        periodic cleanings.
        N)r
r�datarvrQ�
next_cleaning)rrv)rrrrls
zCache.__init__N)r7cCspt��}|j|krlg}x*|j��D]\}}|j|kr"|�|�q"Wx|D]}|j|=qHWt��}||j|_dS)z&Clean the cache if it's time to do so.N)rQrxrw�itemsrRr+rv)r�nowZkeys_to_delete�k�vrrr�_maybe_cleanvs


zCache._maybe_clean)�keyr7c	Csd|j�T|��|j�|�}|dks2|jt��krF|jjd7_dS|jjd7_|SQRXdS)aKGet the answer associated with *key*.

        Returns None if no answer is cached for the key.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.

        Returns a ``dns.resolver.Answer`` or ``None``.
        Nr)	rpr}rwr*rRrQrqrjri)rr~r|rrrr*�sz	Cache.get)r~�valuer7c	Cs(|j�|��||j|<WdQRXdS)aAssociate key and value in the cache.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.

        *value*, a ``dns.resolver.Answer``, the answer.
        N)rpr}rw)rr~rrrr�put�s	z	Cache.putc	CsH|j�8|dk	r$||jkr:|j|=ni|_t��|j|_WdQRXdS)a2Flush the cache.

        If *key* is not ``None``, only that item is flushed.  Otherwise the entire cache
        is flushed.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.
        N)rprwrQrvrx)rr~rrr�flush�s


zCache.flush)ru)N)r-r.r/r0�floatrr}�CacheKeyrrJr*r�r�r4rr)rrrtis

rtc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LRUCacheNodezLRUCache node.cCs"||_||_d|_||_||_dS)Nr)r~rri�prev�next)rr~rrrrr�s
zLRUCacheNode.__init__cCs ||_|j|_||j_||_dS)N)r�r�)r�noderrr�
link_after�szLRUCacheNode.link_aftercCs|j|j_|j|j_dS)N)r�r�)rrrr�unlink�s
zLRUCacheNode.unlinkN)r-r.r/r0rr�r�rrrrr��sr�cs�eZdZdZded��fdd�
Zedd�dd	�Zeee	d
�dd�Z
eed
�d
d�Zee	dd�dd�Zdeedd
�dd�Z
�ZS)�LRUCachea`Thread-safe, bounded, least-recently-used DNS answer cache.

    This cache is better than the simple cache (above) if you're
    running a web crawler or other process that does a lot of
    resolutions.  The LRUCache has a maximum number of nodes, and when
    it is full, the least-recently used node is removed to make space
    for a new one.
    順)�max_sizecs>t���i|_|�|�tdd�|_|j|j_|j|j_dS)zl*max_size*, an ``int``, is the maximum number of nodes to cache;
        it must be greater than 0.
        N)r
rrw�set_max_sizer��sentinelr�r�)rr�)rrrr�s


zLRUCache.__init__N)r�r7cCs|dkrd}||_dS)Nr)r�)rr�rrrr��szLRUCache.set_max_size)r~r7c	Cs�|j��|j�|�}|dkr0|jjd7_dS|��|jjt��krf|j|j	=|jjd7_dS|�
|j�|jjd7_|jd7_|jSQRXdS)aKGet the answer associated with *key*.

        Returns None if no answer is cached for the key.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.

        Returns a ``dns.resolver.Answer`` or ``None``.
        Nr)
rprwr*rqrjr�rrRrQr~r�r�ri)rr~r�rrrr*�s
zLRUCache.getc	CsD|j�4|j�|�}|dks,|jjt��kr0dS|jSWdQRXdS)zBReturn the number of cache hits associated with the specified key.Nr)rprwr*rrRrQri)rr~r�rrr�get_hits_for_keys
zLRUCache.get_hits_for_key)r~rr7c	Cs�|j�||j�|�}|dk	r.|��|j|j=x.t|j�|jkr\|jj}|��|j|j=q0Wt	||�}|�
|j�||j|<WdQRXdS)aAssociate key and value in the cache.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.

        *value*, a ``dns.resolver.Answer``, the answer.
        N)rprwr*r�r~rr�r�r�r�r�)rr~rr��gnoderrrr�
s	

zLRUCache.putc	Csv|j�f|dk	r8|j�|�}|dk	rh|��|j|j=n0|jj}x ||jkr`|j}|��|}qBWi|_WdQRXdS)a2Flush the cache.

        If *key* is not ``None``, only that item is flushed.  Otherwise the entire cache
        is flushed.

        *key*, a ``(dns.name.Name, dns.rdatatype.RdataType, dns.rdataclass.RdataClass)``
        tuple whose values are the query name, rdtype, and rdclass respectively.
        N)rprwr*r�r~r�r�)rr~r�r�r�rrrr�#s
zLRUCache.flush)r�)N)r-r.r/r0rgrr�r�rrJr*r�r�r�r4rr)rrr��s	r�c@s�eZdZdZdeejjefeej	j
efeejjefe
e
ee
d�dd�Zeeejjeefd�dd�Zeeee
efd�d	d
�Zeejjeeeeee
fd�dd
�ZdS)�_ResolutionaHelper class for dns.resolver.Resolver.resolve().

    All of the "business logic" of resolution is encapsulated in this
    class, allowing us to have multiple resolve() implementations
    using different I/O schemes without copying all of the
    complicated logic.

    This class is a "friend" to dns.resolver.Resolver and manipulates
    resolver data structures directly.
    �BaseResolver)�resolverr'rKrL�tcp�raise_on_no_answer�searchc
Cs�t|t�rtj�|d�}tjj�|�}tj�|�r6t	�tj
j�|�}	tj
�|	�rTt	�||_
|�||�|_|jdd�|_||_|	|_||_||_i|_tjj|_g|_g|_g|_d|_d|_d|_d|_d|_d|_ dS)NrFg)!rr!r_rS�	from_textrarb�makeZis_metatyperHrcrdZis_metaclassr��_get_qnames_to_try�
qnames_to_tryrrKrLr�r��nxdomain_responses�emptyr'�nameservers�current_nameserversr6rMrN�tcp_attempt�retry_with_tcprE�backoff)
rr�r'rKrLr�r�r�Z
the_rdtypeZthe_rdclassrrrrHs4


z_Resolution.__init__)r7cCs��x�t|j�dk�r�|j�d�|_|jjr�|jj�|j|j|jf�}|dk	rr|j	dkrj|j
rjt|jd��nd|fS|jj�|jt
jj|jf�}|dk	r�|j��t
jjkr�|j|j|j<qt
j�|j|j|j�}|jjdk	r�|j|jj|jj|jjd�|j|jj|jj|jj|jjd�|jjdk	�r0|jj|_|jjdd�|_|jj �rXt!�"|j�|jdd�|_#g|_$d|_%d|_&d|_'||_(d|_)|dfSWt|j*|jd��dS)	z�Get the next request to send, and check the cache.

        Returns a (request, answer) tuple.  At most one of request or
        answer will not be None.
        rN)r()�	algorithm)�optionsFg�������?)rr)+rr�popr'r��cacher*rKrLrPr�rAr(r_ra�ANY�rcoder
r�reZ
make_query�keyname�use_tsig�keyring�keyalgorithm�use_edns�edns�	ednsflags�payload�ednsoptions�flagsr��rotate�random�shuffler�r6rMr�r�rEr�r�)rrOrErrr�next_requestnsN


z_Resolution.next_requestcCs�|jr0|jdk	st�d|_d|_|j|jddfSd}|js�t|j�dkrXt|j	|j
d��|jdd�|_|j}t|jdd�|_|j�
d�|_|jj�|j|jj�|_|j|_|j|j|j|fS)NTFrg)rEr6r8)r�rM�AssertionErrorr�rNr�rr�rDrEr6r��minr�r��nameserver_portsr*r�)rr�rrr�next_nameserver�s"z_Resolution.next_nameserver)r(�exr7c
Cs�|jdk	st�|r�|dkst�|j�|j|j|j||f�t|tjj	�sft|t
�sft|t�sft|t�rv|j
�|j�n*t|tjj�r�|jr�|j
�|j�nd|_dS|dk	s�t�t|tjj�s�t�|��}|tjjk�r�y t|j|j|j||j|j�}WnNtk
�rF}z.|j�|j|j|j||f�|j
�|j�dSd}~XYnX|jj�rn|jj�|j|j|jf|�|jdk�r�|j�r�t|j d��|dfS|tjj!k�rHyt|jtj"j#tj$j%|�}WnNtk
�r}z.|j�|j|j|j||f�|j
�|j�dSd}~XYnX||j&|j<|jj�rD|jj�|jtj"j#|jf|�dS|tjj'k�r~t'�}|j�|j|j|j||f�|�nN|tjj(k�s�|jj)�s�|j
�|j�|j�|j|j|jtj�*|�|f�dSdS)NT)NF)r()NT)+rMr�r6r+r�rNrr_�	exceptionZ	FormError�EOFError�OSError�NotImplementedErrorr��removereZ	Truncatedr�rfr�ZNOERRORrJr'rKrLr&r�r�r�rPr�rAr(r
rar�rc�INr�r5ZSERVFAIL�retry_servfail�to_text)rr(r�r�rO�eZyexrrr�query_result�s�





z_Resolution.query_resultN)r-r.r/r0rr_rSr`r!rarbrcrd�boolrrrrerfrJr�rgr�r��Messager&r�rrrrr�<s
 "Er�c@s$eZdZUdZejjed<ee	e
fed<e
ed<eejjed<eed<e
ed<e
ed<eeed	<eeejje	fed
<eejje	fed<e
ed<e
ed
<eeejjed<e
ed<eed<ee
ed<eed<eed<ee
ed<d7e	ed�dd�Zdd�Zedd�dd�Zdd �d!d"�Zd8e
ee
eeee
d#�d$d%�Zejjeeeejjd&�d'd(�Zdejjfeeeejje	feejje	fdd)�d*d+�Zd,d,ejjdfeee
efe
e
eeejjdd-�d.d/�Ze
dd0�d1d2�Z e!ee	d �d3d4��Z"e"j#ee	dd5�d6d4��Z"dS)9r�zDNS stub resolver.�domainr�rNr��use_search_by_defaultr>�lifetimer�r�r�r�r�r�r�r�r�r�r��ndots�/etc/resolv.confT)�filename�	configurecCs2|��|r.tjdkr |��n|r.|�|�dS)a�*filename*, a ``str`` or file object, specifying a file
        in standard /etc/resolv.conf format.  This parameter is meaningful
        only when *configure* is true and the platform is POSIX.

        *configure*, a ``bool``.  If True (the default), the resolver
        instance is configured in the normal fashion for the operating
        system the resolver is running on.  (I.e. by reading a
        /etc/resolv.conf file on POSIX systems and from the registry
        on Windows systems.)
        r	N)rk�sys�platform�
read_registry�read_resolv_conf)rr�r�rrrrLs

zBaseResolver.__init__cCs�tj�tj�t���dd��|_t|j�dkr:tjj|_g|_	i|_
d|_g|_d|_
d|_d|_d|_d|_tjj|_d|_d|_d|_d|_d|_d|_d|_d|_d|_dS)	z1Reset all resolver configuration to the defaults.rNr�5Fg@g@r=)r_rSr`r��socket�gethostnamer�r�rootr�r�rNr�r�r>r�r�r��tsig�default_algorithmr�r�r�r�r�r�r�r�r�r�)rrrrrk_s,"

zBaseResolver.resetN)�fr7cCst|t�r<yt|�}WqFtk
r8td|����YqFXn
t�|�}|���}�x�|D�]�}t|�dksV|ddksV|ddkr�qV|��}t|�dkr�qV|ddkr�|j	�
|d�qV|ddkr�tj�
|d�|_g|_qV|dd	k�rg|_x�|dd
�D]}|j�
tj�
|���q�WqV|ddkrVx�|dd
�D]�}|dk�rNd
|_n�|dk�rb|��n~d|k�r�yt|�d�d�|_Wnttfk
�r�YnXn>d|k�r8yt|�d�d�|_Wnttfk
�r�YnX�q8WqVWWd
QRXt|j	�dk�rtd��d
S)a�Process *f* as a file in the /etc/resolv.conf format.  If f is
        a ``str``, it is used as the name of the file to open; otherwise it
        is treated as the file itself.

        Interprets the following items:

        - nameserver - name server IP address

        - domain - local domain name

        - search - search list for host-name lookup

        - options - supported options are rotate, timeout, edns0, and ndots

        zcannot open r�#�;r8rMrr�r�Nr�r�TZedns0r>�:r�zno nameservers)rr!�openr�rI�
contextlib�nullcontextr�splitr�r+r_rSr�r�r�r�r�rgr>�
ValueErrorr[r�)rr��cm�l�tokens�suffix�optrrrr�ysP

$




zBaseResolver.read_resolv_conf)r7cCsNy0tj��}|jdk	r|j|_|j|_|j|_Wntk
rHt�YnXdS)z9Extract resolver configuration from the Windows registry.N)r_Z	win32utilZget_dns_infor�r�r�rr�)r�inforrrr��s

zBaseResolver.read_registry)�startr�r6r7cCst|dkr|jn|}t��}||}|dkr.g}|dkrP|dkrLt||d��nd}||krdt||d��t|||j�S)Nrr=)r>r6)r�rQr<r�r>)rr�r�r6rz�durationrrr�_compute_timeout�szBaseResolver._compute_timeout)r'r�r7cCs�|dkr|j}g}|��r&|�|�n�|�tjj�}|r�t|j�dkrV|jdd�}n&|j	tjjkrx|j	dk	rx|j	g}ng}|j
dkr�d}n|j
}x|D]}|�||�q�Wt|�|kr�|�d|�q�|�|�n
|�|�|S)Nrr)r��is_absoluter+Zconcatenater_rSr�rr�r�r��insert)rr'r�r�Z	abs_qnameZsearch_listr�r�rrrr��s,



zBaseResolver._get_qnames_to_try)r�r�r�r7cCs||_||_||_dS)z�Add a TSIG signature to each query.

        The parameters are passed to ``dns.message.Message.use_tsig()``;
        see its documentation for details.
        N)r�r�r�)rr�r�r�rrrr�szBaseResolver.use_tsigr)r�r�r�r�r7cCs>|dks|dkrd}n|dkr"d}||_||_||_||_dS)a�Configure EDNS behavior.

        *edns*, an ``int``, is the EDNS level to use.  Specifying
        ``None``, ``False``, or ``-1`` means "do not use EDNS", and in this case
        the other parameters are ignored.  Specifying ``True`` is
        equivalent to specifying 0, i.e. "use EDNS0".

        *ednsflags*, an ``int``, the EDNS flag values.

        *payload*, an ``int``, is the EDNS sender's payload field, which is the
        maximum size of UDP datagram the sender can handle.  I.e. how big
        a response to this message can be.

        *options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS
        options.
        NFr=Tr)r�r�r�r�)rr�r�r�r�rrrr�szBaseResolver.use_edns)r�r7cCs
||_dS)zkOverrides the default flags with your own.

        *flags*, an ``int``, the message flags to use.
        N)r�)rr�rrr�	set_flags9szBaseResolver.set_flagscCs|jS)N)�_nameservers)rrrrr�AszBaseResolver.nameservers)r�r7c	Cs~t|t�rhxT|D]L}tj�|�syt|�jdkr4t�Wqtk
rZt	d|�d���YqXqW||_
nt	d�t|����dS)z�
        *nameservers*, a ``list`` of nameservers.

        Raises ``ValueError`` if *nameservers* is anything other than a
        ``list``.
        �httpsznameserver z( is not an IP address or valid https URLz%nameservers must be a list (not a {})N)
rrr_�inet�
is_addressr�schemer�r&r�r�r"�type)rr�rMrrrr�Es

)r�T)NN)$r-r.r/r0r_rSr`�__annotations__rr!rgrr�r�rrrr��Optionrrkr�r��
ErrorTupler�r�r�r�r�reZDEFAULT_EDNS_PAYLOADr�r�r3r��setterrrrrr�1sT
C**
$r�c@seZdZdZejjejjddddddfe	ej
jefe	ejj
efe	ejjefeeeeeeeeeed�
dd�Zejjejjdddddfe	ej
jefe	ejj
efe	ejjefeeeeeeeed	�	d
d�Zeeeed�d
d�Ze	ej
jefej
jd�dd�ZdS)�ResolverzDNS stub resolver.FNTr)
r'rKrLr��sourcer��source_portr�r�r7c

Cs:t|||||||	�}
t��}�x|
��\}}
|
dk	r8|
S|dk	sDt�d}x�|�s0|
��\}}}}|rnt�|�|�|||
j�}y\tj	�
|�r�|r�tjj||||||d�}q�tjj
||||||dd�}ntjj|||d�}Wn6tk
�r}z|
�d|�\}}wJWdd}~XYnX|
�|d�\}
}|
dk	rJ|
SqJWq WdS)a�Query nameservers 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.

        Raises ``dns.resolver.LifetimeTimeout`` if no answers could be found
        in the specified lifetime.

        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)r>rNr�r�T)r>rNr�r�Zraise_on_truncation)r>)r�rQr�r�r��sleepr�r6r_r�r�rBr��udpr�r&r�)rr'rKrLr�r�r�r�r�r��
resolutionr�rErO�donerMrNr�r>r(r��_rrr�resolvebsN?


zResolver.resolve)	r'rKrLr�r�r�r�r�r7c		Cs*tjdtdd�|�||||||||d�	S)a$Query nameservers to find the answer to the question.

        This method calls resolve() with ``search=True``, and is
        provided for backwards compatibility with prior versions of
        dnspython.  See the documentation for the resolve() method for
        further details.
        z2please use dns.resolver.Resolver.resolve() insteadr8)�
stacklevelT)�warnings�warn�DeprecationWarningr�)	rr'rKrLr�r�r�r�r�rrrrB�szResolver.query)�ipaddrrrr7cOs@i}|�|�tjj|d<tjj|d<|jtj�|�f|�|�S)a�Use a 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.
        rKrL)	�updater_ra�PTRrcr�r��reversename�from_address)rrrrZmodified_kwargsrrr�resolve_address�s
zResolver.resolve_address)rSr7c
CsJy|j|dd�}|j}Wn,tjjk
rD}z
|j}Wdd}~XYnX|S)a�Determine the canonical name of *name*.

        The canonical name is the name the resolver uses for queries
        after all CNAME and DNAME renamings have been applied.

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

        This method can raise any exception that ``resolve()`` can
        raise, other than ``dns.resolver.NoAnswer`` and
        ``dns.resolver.NXDOMAIN``.

        Returns a ``dns.name.Name``.
        F)r�N)r�r%r_r�r
)rrSrOr%r�rrrr%s
zResolver.canonical_name)r-r.r/r0r_ra�Arcr�rrSr`r!rbrdr�rrgr�rJr�rBrr	r%rrrrr�_s(Fm@r��default_resolver)r7cCstdkrt�tdk	st�tS)z7Get the default resolver, initializing it if necessary.N)r�reset_default_resolverr�rrrr�get_default_resolver0sr
cCs
t�adS)z�Re-initialize default resolver.

    Note that the resolver configuration (i.e. /etc/resolv.conf on UNIX
    systems) will be re-read immediately.
    N)r�rrrrrr8srFT)
r'rKrLr�r�r�r�r�r�r7c		Cst��|||||||||�	S)z�Query nameservers to find the answer to the question.

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

    See ``dns.resolver.Resolver.resolve`` for more information on the
    parameters.
    )r
r�)	r'rKrLr�r�r�r�r�r�rrrr�Csr�)	r'rKrLr�r�r�r�r�r7c
Cs(tjdtdd�t||||||||d�	S)aQuery nameservers to find the answer to the question.

    This method calls resolve() with ``search=True``, and is
    provided for backwards compatibility with prior versions of
    dnspython.  See the documentation for the resolve() method for
    further details.
    z)please use dns.resolver.resolve() insteadr8)rT)rrrr�)r'rKrLr�r�r�r�r�rrrrBesrB)rrrr7cOst�j|f|�|�S)z�Use a resolver to run a reverse query for PTR records.

    See ``dns.resolver.Resolver.resolve_address`` for more information on the
    parameters.
    )r
r	)rrrrrrr	�sr	)rSr7cCst��|�S)z�Determine the canonical name of *name*.

    See ``dns.resolver.Resolver.canonical_name`` for more information on the
    parameters and possible exceptions.
    )r
r%)rSrrrr%�sr%)rSrLr�r�r�r7c
Cs�t|t�rtj�|tjj�}|dkr*t�}|��s:t|��t	�	�}|dk	rT||}nd}�x>y\|r||t	�	�}|dkr�d}nd}|j
|tjj|||d�}|j
dk	s�t�|j
j|kr�|SWn�tjjtjjfk
�rh}	z�t|	tjj�r�|	���|�}
n|	��}
|
�rXxR|
jD]H}|jtjjk�r|j|k�r|j�|�\}}
}
|tjjk�r|jS�qWWdd}	~	XYnXy|��}Wq\tjjk
�r�t�Yq\Xq\WdS)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.resolver.Resolver`` or ``None``, the resolver to use.
    If ``None``, the default, then the default resolver is used.

    *lifetime*, a ``float``, the total time to allow for the queries needed
    to determine the zone.  If ``None``, the default, then only the individual
    query limits of the resolver apply.

    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.)

    Raises ``dns.resolver.LifetimeTimeout`` if the answer could not be
    found in the allotted lifetime.

    Returns a ``dns.name.Name``.
    Nr)r�)rr!r_rSr�r�r
r�rFrQr�raZSOArPr�r�r
rArr*r(�	authorityrKrLZfullcompareZNAMERELN_SUPERDOMAIN�parentZNoParentrG)rSrLr�r�r�r�rRZ	rlifetimerOr�r(Zrrs�nrr�rrr�
zone_for_name�sH 

rc
Cs�|tj@dkr t||||||�S|tjtjB@dkrBt�tjd��|dkr`|dkr`t�tjd��g}g}d}|dkr�t||||||�Sytj	�
|�t||||||�Stk
r�YnXy�|tjks�|tj
k�r"tj|tjjdd�}	|	j}|	j�d�}|	jdk	�r"x|	jD]}
|�|
j��qW|tjk�s:|tj
k�r�tj|tjjdd�}|j�d�}|jdk	�r�x|jD]}
|�|
j��qnWWnJtjjk
�r�t�tjd��Yn$tk
�r�t�tjd��YnXd}y|dk�r�d}nt|�}WnLtk
�r>|tj@dk�r:yt�|�}Wntk
�r8YnXYnX|dk�rXt�tjd��g}
|dk�rttj tj!g}n|g}|tj"@dk�r�|}nd}|tjk�s�|tj
k�r�xP|D]H}x@|D]8}x0t#|D]$}|
�tj|||||ddff��q�W�q�W�q�W|tjk�s|tj
k�rdxL|D]D}x<|D]4}x,t#|D] }|
�tj|||||ff��q4W�q&W�qWt$|
�dk�r�t�tjd��|
S)	Nrz*Non-recoverable failure in name resolutionzName or service not knownF)r�Tz$Temporary failure in name resolution�)%r��AI_NUMERICHOST�_original_getaddrinfo�
AI_ADDRCONFIG�AI_V4MAPPED�gaierror�EAI_FAIL�
EAI_NONAMEr_r�Zaf_for_addressr&�AF_INET6�	AF_UNSPEC�	_resolverr�raZAAAAr'r%r�rPr+�address�AF_INETr
r�r
�	EAI_AGAINrg�AI_NUMERICSERV�
getservbyname�
SOCK_DGRAM�SOCK_STREAM�AI_CANONNAME�_protocols_for_socktyper)�host�service�family�socktype�protor�Zv6addrsZv4addrsr%Zv6ZrdataZv4rN�tuplesZ	socktypesr)�addrrrr�_getaddrinfos�	





,

(r-c
	Csh|d}|d}t|�dkr,|d}tj}n
d}tj}t|||tjtjd�}t|�dkrbt�d��|ddd}|tj@r�d}nd}t	j
�|�}	|tj@dk�r y"t
�|	d�}
|
jdj�d	�}WnXt	jjt	jjfk
�r|tj@r�t�tjd
��|}|dk	�r|dt|�7}YnXn|}|dk	�r>|dt|�7}|tj@�rTt|�}nt�||�}||fS)Nrr�r9z'sockaddr resolved to multiple addressesr�r�rTzName or service not known�%)rr�rrr-r#�SOL_TCP�error�NI_DGRAMr_rr�NI_NUMERICHOSTrr�rP�targetr�r�r
rA�NI_NAMEREQDrrr!�NI_NUMERICSERV�
getservbyport)
�sockaddrr�r&rNZscoper(r+r,Zpnamer'rO�hostnamer'rrr�_getnameinfoos@





r:cCs<|dkrt��}yt|�\}}}Wntk
r6YnX|S)N)r�r��_gethostbyaddrr&)rSr�rrr�_getfqdn�sr<cCst|�ddS)Nr8r)�_gethostbyname_ex)rSrrr�_gethostbyname�sr>cCsXg}g}t|dtjtjtjtj�}|dd}x|D]}|�|dd�q4W|||fS)Nrr9r.)r-r�rr#r0r$r+)rS�aliases�	addressesr+�	canonical�itemrrrr=�s
r=c
Csy"tj�|�|dddf}tj}WnVtk
rxytj�|�Wn"tk
rdt�tjd��YnX|df}tj	}YnXt
|tj�\}}g}g}t|d|tj
tjtj�}|dd}tj�||�}	x8|D]0}
|
dd}tj�||�}|	|kr�|�|�q�W|||fS)N�PrzName or service not knownr9r.)r_Zipv6�	inet_atonr�rr&Zipv4rrrr:r5r-r#r0r$r��	inet_ptonr+)
�ipr8r(rSr�r?r@r+rAZbin_iprBr,Zbin_addrrrrr;�s0

r;)r�r7cCs:|dkrt�}|att_tt_tt_t	t_
tt_t
t_dS)a�Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    resolver, a ``dns.resolver.Resolver`` or ``None``, the resolver to use.
    N)r
rr-r��getaddrinfor:�getnameinfor<�getfqdnr>�
gethostbynamer=�gethostbyname_exr;�
gethostbyaddr)r�rrr�override_system_resolver�srMcCs,datt_tt_tt_tt_	t
t_tt_
dS)z5Undo the effects of prior override_system_resolver().N)rrr�rG�_original_getnameinforH�_original_getfqdnrI�_original_gethostbynamerJ�_original_gethostbyname_exrK�_original_gethostbyaddrrLrrrr�restore_system_resolver�srS)r)N)N)mr0�typingrrrrrr�urllib.parserr�r�r�rnrQr�rZ
dns.exceptionr_Zdns.ednsZ	dns.flagsZdns.inetZdns.ipv4Zdns.ipv6Zdns.messageZdns.nameZ	dns.queryZ	dns.rcodeZdns.rdataclassZ
dns.rdatatypeZdns.reversenameZdns.tsigr�Z
dns.win32utilr�ZDNSExceptionr
r5r!r�rgr&rer�r�r;�Timeoutr<rArDrFrGrHrIrJrhrmrSr`rarbrcrdr�rtr�r�r�r�r�rr�r
rr
r�r�r�rBr	r%rr"�SOL_UDPr#r0r%rrGrrHrNrIrOrJrPrKrQrLrRrr-r:r<r>r=r;rMrSrrrr�<module>s� 
X$EOov0O
F@
 &U
l
'