
    ,h                     
   U 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Zddlm	Z	m
Z
mZmZmZmZmZmZ ddlm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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!Zddl"Zddl#Zddl$Zddl%ZejL                  dk(  rddl'Z G d dejP                  jR                        Z* G d d	ejP                  jR                        Z+eee,   e-e.ee/e,f   eej`                  jb                     f   Z2d
ee2   dee,   fdZ3 G d dejP                  jh                        Z5e5Z4 G d dejP                  jR                        Z6 G d dejP                  jR                        Z7 G d dejP                  jR                        Z8 G d dejP                  jR                        Z9 G d dejP                  jR                        Z: G d dejP                  jR                        Z; G d d      Z< G d de=      Z> G d d e>      Z? G d! d"      Z@ G d# d$      ZAeej                  j                  ej                  j                  ej                  j                  f   ZH G d% d&eA      ZI G d' d(      ZJ G d) d*eA      ZK G d+ d,      ZL G d- d.      ZM G d/ d0eM      ZNdaOeeN   ePd1<   deNfd2ZQdYd3ZRej                  j                  ej                  j                  d4dd5dddfd6eej                  j                  e,f   d7eej                  j                  e,f   d8eej                  j                  e,f   d9e-d:ee,   d;e-d<e.d=eeU   d>ee-   de<fd?ZVej                  j                  ej                  j                  d4dd5ddfd6eej                  j                  e,f   d7eej                  j                  e,f   d8eej                  j                  e,f   d9e-d:ee,   d;e-d<e.d=eeU   de<fd@ZWdAe,dBe	dCe	de<fdDZXej                  fdEeej                  j                  e,f   dFe.dCe	de?fdGZZdEeej                  j                  e,f   dej                  j                  fdHZ[dZd=eUddfdIZ\ej                  j                  d4ddfdEeej                  j                  e,f   d8ej                  j                  d9e-dJeeN   d=eeU   dej                  j                  fdKZ]dLej                  dfdMeej                  j                  e,f   dNe.dFe.dJeeN   deNf
dOZ^ej                  j                  ej                  j                  d4dd5ddddLej                  dfdMeej                  j                  e,f   d6eej                  j                  e,f   d7eej                  j                  e,f   d8eej                  j                  e,f   d9e-d:ee,   d;e-d<e.d=eeU   d>ee-   dNe.dFe.dJeeN   de<fdPZ_ej                  ej                  gej                  ej                  giZddaeej                  Zgej                  Ziej                  Zkej                  Zmej                  Zoej                  Zqddej                  dddfdQZrd[dRZsd\dSZtdT ZudU ZvdV Zwd\dJeeN   ddfdWZxdYdXZyy)]DNS stub resolver.    N)AnyDictIteratorListOptionalSequenceTupleUnion)urlparsewin32c                   n     e Zd ZdZddhZdZ fdZddZdef fdZ	e
d	        Zd
 Zd Zd Zd Z xZS )NXDOMAINz"The DNS query name does not exist.qnames	responsesNc                 $    t        |   |i | y Nsuper__init__selfargskwargs	__class__s      N/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/dns/resolver.pyr   zNXDOMAIN.__init__?       $)&)    c                     t        |t        t        t        f      st	        d      t        |      dk(  rt	        d      |i }nt        |t              st	        d      t        ||      }|S )Nz#qnames must be a list, tuple or setr   z(qnames must contain at least one elementz(responses must be a dict(qname=response)r   r   )
isinstancelisttuplesetAttributeErrorlendict)r   r   r   r   s       r   _check_kwargszNXDOMAIN._check_kwargsB   si    &4"45 !FGGv;! !KLLIIt, !KLLVy9r   returnc                     d| j                   vrt        | 	         S | j                   d   }t        |      dkD  rd}nd}dj	                  t        t        |            }| d| S )Nr      zNone of DNS query names existz!The DNS query name does not existz, z: )r   r   __str__r&   joinmapstr)r   r   msgr   s      r   r,   zNXDOMAIN.__str__N   se    4;;&7?$$X&v;?1C5C3sF+,b!!r   c                     d| j                   vrt        d      | j                   d   D ].  }| j                   d   |   }	 |j                         }||k7  r|c S 0 | j                   d   d   S # t        $ r Y Nw xY w)z%Return the unresolved canonical name.r   zparametrized exception requiredr   r   )r   	TypeErrorcanonical_name	Exception)r   qnameresponsecnames       r   r3   zNXDOMAIN.canonical_nameY   s     4;;&=>>[[* 		E{{;/6H //1E> L "			 {{8$Q''	   s   A,,	A87A8c                 n   t        | j                  j                  dg             }t        | j                  j                  di             }|j                  j                  di       }|j                  j                  dg       D ]$  }||vr|j	                  |       ||v s||   ||<   & t        ||      S )z3Augment by results from another NXDOMAIN exception.r   r   r    )r"   r   getr'   appendr   )r   e_nxqnames0
responses0
responses1qname1s         r   __add__zNXDOMAIN.__add__j   s    t{{x45$++//+r:;
[[__["5
kkooh3 	8FW$v&#%/%7
6"		8
 w*==r   c                      | j                   d   S )zXAll of the names that were tried.

        Returns a list of ``dns.name.Name``.
        r   r   r   s    r   r   zNXDOMAIN.qnamesv   s    
 {{8$$r   c                      | j                   d   S )zA map from queried names to their NXDOMAIN responses.

        Returns a dict mapping a ``dns.name.Name`` to a
        ``dns.message.Message``.
        r   rB   rC   s    r   r   zNXDOMAIN.responses}   s     {{;''r   c                 &    | j                   d   |   S )zTThe response for query *qname*.

        Returns a ``dns.message.Message``.
        r   rB   )r   r5   s     r   r6   zNXDOMAIN.response   s    
 {{;'..r   r   )__name__
__module____qualname____doc__supp_kwargsfmtr   r(   r/   r,   propertyr3   r@   r   r   r6   __classcell__r   s   @r   r   r   5   sS    ,[)K
C*
	" 	" ( ( 
>%(/r   r   c                       e Zd ZdZy)YXDOMAINz8The DNS query name is too long after DNAME substitution.NrF   rG   rH   rI    r   r   rP   rP      s    Br   rP   errorsr)   c                 R    g }| D ]  }|j                  d|d    d|d           ! |S )z3Turn a resolution errors trace into a list of text.zServer r   z
 answered    )r:   )rS   textserrs      r   _errors_to_textrX      s<    E ;ws1vhjQ9:;Lr   c                   H     e Zd ZdZdZedd  dZddhZ fdZ fdZ xZ	S )	LifetimeTimeoutz The resolution lifetime expired.Nz& after {timeout:.3f} seconds: {errors}timeoutrS   c                 $    t        |   |i | y r   r   r   s      r   r   zLifetimeTimeout.__init__   r   r   c                 f    t        |d         }t        | 	  |d   dj                  |            S )NrS   r\   ; r\   rS   )rX   r   _fmt_kwargsr-   r   r   srv_msgsr   s      r   ra   zLifetimeTimeout._fmt_kwargs   s<    "6(#34w"9%dii.A # 
 	
r   
rF   rG   rH   rI   r0   rK   rJ   r   ra   rM   rN   s   @r   rZ   rZ      s7    *
,C"XJ@
ACh'K*
 
r   rZ   c                   <     e Zd ZdZdZdhZ fdZ fdZd Z x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}r6   c                 $    t        |   |i | y r   r   r   s      r   r   zNoAnswer.__init__   r   r   c                 >    t         |   |d   j                        S )Nr6   )query)r   ra   question)r   r   r   s     r   ra   zNoAnswer._fmt_kwargs   s!    w"
);)D)D"EEr   c                      | j                   d   S )Nr6   rB   rC   s    r   r6   zNoAnswer.response   s    {{:&&r   )
rF   rG   rH   rI   rK   rJ   r   ra   r6   rM   rN   s   @r   rf   rf      s"    F
PC,K*F'r   rf   c                   H     e Zd ZdZdZedd  dZddhZ fdZ fd	Z xZ	S )
NoNameserverszAll 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.Nr[   z {query}: {errors}requestrS   c                 $    t        |   |i | y r   r   r   s      r   r   zNoNameservers.__init__   r   r   c                 z    t        |d         }t        | 	  |d   j                  dj	                  |            S )NrS   rn   r_   )ri   rS   )rX   r   ra   rj   r-   rb   s      r   ra   zNoNameservers._fmt_kwargs   sB    "6(#34w"#,,TYYx5H # 
 	
r   rd   rN   s   @r   rm   rm      s;     8C"XJ,
-Ch'K*
 
r   rm   c                       e Zd ZdZy)NotAbsolutezEAn absolute domain name is required but a relative name was provided.NrQ   rR   r   r   rr   rr          Or   rr   c                       e Zd ZdZy)	NoRootSOAzBThere is no SOA RR at the DNS root name. This should never happen!NrQ   rR   r   r   ru   ru      s    Lr   ru   c                       e Zd ZdZy)NoMetaqueriesz DNS metaqueries are not allowed.NrQ   rR   r   r   rw   rw      s    *r   rw   c                       e Zd ZdZy)NoResolverConfigurationzEResolver configuration could not be read or specified no nameservers.NrQ   rR   r   r   ry   ry      rs   r   ry   c                   >   e Zd ZdZ	 	 ddej
                  j                  dej                  j                  dej                  j                  dej                  j                  dee   dee   d	dfd
Zd Zd	efdZd	eej(                  j*                     fdZd Zd Zy)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.
    Nr5   rdtyperdclassr6   
nameserverportr)   c                 N   || _         || _        || _        || _        || _        || _        |j                         | _        | j                  j                  | _        | j                  j                  | _
        t        j                         | j                  j                  z   | _        y r   )r5   r|   r}   r6   r~   r   resolve_chainingchaining_resultr3   answerrrsettimeminimum_ttl
expiration)r   r5   r|   r}   r6   r~   r   s          r   r   zAnswer.__init__  s     
 $	'88: #22AA))00
))+(<(<(H(HHr   c                 &   |dk(  r| j                   j                  S |dk(  r| j                   j                  S |dk(  r| j                   j                  S |dk(  r| j                   j                  S |dk(  r| j                   j
                  S t        |      )Nnamettlcoversr}   r|   )r   r   r   r   r}   r|   r%   )r   attrs     r   __getattr__zAnswer.__getattr__  s    6>::??"U]::>>!X::$$$Y::%%%X::$$$ &&r   c                 P    | j                   xr t        | j                         xs dS Nr   )r   r&   rC   s    r   __len__zAnswer.__len__*  s    zz-c$**o22r   c                 r    | j                   xr t        | j                         xs t        t                     S r   )r   iterr#   rC   s    r   __iter__zAnswer.__iter__-  s%    zz.d4::.?$uw-?r   c                 D    | j                   t        | j                   |   S r   r   
IndexErrorr   is     r   __getitem__zAnswer.__getitem__0  s     ::zz!}r   c                 B    | j                   t        | j                   |= y r   r   r   s     r   __delitem__zAnswer.__delitem__5  s    ::JJqMr   NN)rF   rG   rH   rI   dnsr   Name	rdatatype	RdataType
rdataclass
RdataClassmessageQueryMessager   r/   intr   r   r   r   rdataRdatar   r   r   rR   r   r   r{   r{      s    * %)"Ixx}}I ''I **	I
 ++**I SMI smI 
I,'3 3@(399??3 @
r   r{   c                       e Zd ZdZy)Answersz5A dict of DNS stub resolver answers, indexed by type.NrQ   rR   r   r   r   r   ;  s    ?r   r   c            
           e Zd ZdZe	 	 	 ddee   dee   dedd fd       Ze	j                  fdedeeeef      fd	Ze	j                  fdedee   fd
Zdej$                  j&                  fdZy)HostAnswerszTA dict of DNS stub resolver answers to a host name lookup, indexed by
    type.
    Nv6v4	add_emptyr)   c                     t               }|+|s|j                  r||t        j                  j                  <   |+|s|j                  r||t        j                  j
                  <   |S r   )r   r   r   r   AAAAA)clsr   r   r   answerss        r   makezHostAnswers.makeD  sP     ->yBHH*,GCMM&&'>yBHH')GCMMOO$r   familyc              #     K   |t         j                  k(  rO| j                  t         j                        E d {    | j                  t         j                        E d {    y |t         j                  k(  r*| j                  t        j                  j                        }nK|t         j                  k(  r*| j                  t        j                  j                        }nt        d|       |r|D ]  }|j                  |f  y y 7 7 w)Nunknown address family )socket	AF_UNSPECaddresses_and_familiesAF_INET6AF_INETr9   r   r   r   r   NotImplementedErroraddress)r   r   r   r   s       r   r   z"HostAnswers.addresses_and_familiesT  s      V%%%226??CCC226>>BBBv&XXcmm001Fv~~%XXcmmoo.F%(?x&HII .}}f--.  DBs"   6DD&DD
 B)D
Dc                 2    d | j                  |      D        S )Nc              3   &   K   | ]	  }|d      yw)r   NrR   ).0pairs     r   	<genexpr>z(HostAnswers.addresses.<locals>.<genexpr>h  s     HDQHs   )r   )r   r   s     r   	addresseszHostAnswers.addressesg  s    HD$?$?$GHHr   c                     | j                  t        j                  j                  | j                  t        j                  j                              }|j
                  S r   )r9   r   r   r   r   r3   )r   r   s     r   r3   zHostAnswers.canonical_namek  s9    #--,,dhhs}}.GH$$$r   )NNT)rF   rG   rH   rI   classmethodr   r{   boolr   r   r   r   r   r
   r/   r   r   r   r   r   r3   rR   r   r   r   r   ?  s       $#	V V 	
 
   #,,..	%S/	".& '-&6&6 I I8C= I% %r   r   c                   6    e Zd ZdZd	dededdfdZd
dZddZy)CacheStatisticszCache Statisticshitsmissesr)   Nc                      || _         || _        y r   r   r   )r   r   r   s      r   r   zCacheStatistics.__init__s  s    	r   c                      d| _         d| _        y r   r   rC   s    r   resetzCacheStatistics.resetw  s    	r   c                 B    t        | j                  | j                        S r   )r   r   r   rC   s    r   clonezCacheStatistics.clone{  s    tyy$++66r   )r   r   r)   N)r)   r   )rF   rG   rH   rI   r   r   r   r   rR   r   r   r   r   p  s)    S c $ 7r   r   c                   @    e Zd ZddZddZdefdZdefdZdefdZ	y)		CacheBaser)   Nc                 T    t        j                         | _        t               | _        y r   )	threadingLocklockr   
statisticsrC   s    r   r   zCacheBase.__init__  s    NN$	)+r   c                 z    | j                   5  | j                  j                          ddd       y# 1 sw Y   yxY w)zReset all statistics to zero.N)r   r   r   rC   s    r   reset_statisticszCacheBase.reset_statistics  s.    YY 	$OO!!#	$ 	$ 	$s   1:c                 r    | j                   5  | j                  j                  cddd       S # 1 sw Y   yxY w)z How many hits has the cache had?N)r   r   r   rC   s    r   r   zCacheBase.hits  s+    YY 	(??''	( 	( 	(   -6c                 r    | j                   5  | j                  j                  cddd       S # 1 sw Y   yxY w)z"How many misses has the cache had?N)r   r   r   rC   s    r   r   zCacheBase.misses  s+    YY 	*??))	* 	* 	*r   c                 z    | j                   5  | j                  j                         cddd       S # 1 sw Y   yxY w)zReturn 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)r   r   r   rC   s    r   get_statistics_snapshotz!CacheBase.get_statistics_snapshot  s0     YY 	+??((*	+ 	+ 	+s   1:r   )
rF   rG   rH   r   r   r   r   r   r   r   rR   r   r   r   r     s0    ,$
(c (
* *
+ +r   r   c                   x     e Zd ZdZddeddf fdZddZdedee	   fdZ
ded	e	ddfd
Zddee   ddfdZ xZS )Cachez$Simple thread-safe DNS answer cache.cleaning_intervalr)   Nc                     t         |           i | _        || _        t	        j                         | j                  z   | _        y)zf*cleaning_interval*, a ``float`` is the number of seconds between
        periodic cleanings.
        N)r   r   datar   r   next_cleaning)r   r   r   s     r   r   zCache.__init__  s8    
 	,.	!2$(IIK$2H2H$Hr   c                 N   t        j                          }| j                  |k  rg }| j                  j                         D ]&  \  }}|j                  |k  s|j                  |       ( |D ]  }| j                  |=  t        j                          }|| j                  z   | _        yy)z&Clean the cache if it's time to do so.N)r   r   r   itemsr   r:   r   )r   nowkeys_to_deletekvs        r   _maybe_cleanzCache._maybe_clean  s     iik$N		) -1<<3&"))!,- $ !IIaL!))+C!$t'='=!=D %r   keyc                 v   | j                   5  | j                          | j                  j                  |      }|!|j                  t        j
                         k  r)| j                  xj                  dz  c_        	 ddd       y| j                  xj                  dz  c_        |cddd       S # 1 sw Y   yxY waK  Get 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+   )	r   r   r   r9   r   r   r   r   r   )r   r   r   s      r   r9   z	Cache.get  s     YY 			c"AyALLDIIK7&&!+&	 	 OO  A% 	 	 	s   A/B/ B//B8valuec                     | j                   5  | j                          || j                  |<   ddd       y# 1 sw Y   yxY wa  Associate 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)r   r   r   r   r   r   s      r   putz	Cache.put  s9     YY 	#"DIIcN	# 	# 	#s    6?c                     | j                   5  ||| j                  v r;| j                  |= n-i | _        t        j                         | j                  z   | _        ddd       y# 1 sw Y   yxY wa2  Flush 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)r   r   r   r   r   )r   r   s     r   flushzCache.flush  s`     YY 	J$))#		#	%)YY[43I3I%I"	J 	J 	Js   AA""A+)g     r@r   r   )rF   rG   rH   rI   floatr   r   CacheKeyr   r{   r9   r   r   rM   rN   s   @r   r   r     sn    .I% ID I>x HV$4 (#x # #4 #J(+ Jt Jr   r   c                   &    e Zd ZdZd ZddZddZy)LRUCacheNodezLRUCache node.c                 J    || _         || _        d| _        | | _        | | _        y r   )r   r   r   prevnextr   s      r   r   zLRUCacheNode.__init__  s%    
			r   Nc                 d    || _         |j                  | _        | |j                  _         | |_        y r   r   r   )r   nodes     r   
link_afterzLRUCacheNode.link_after  s&    	II				r   c                 p    | j                   | j                  _         | j                  | j                   _        y r   r  rC   s    r   unlinkzLRUCacheNode.unlink   s     				r   )r  r   r)   Nr   )rF   rG   rH   rI   r   r  r  rR   r   r   r   r     s    #r   r   c                        e Zd ZdZddeddf fdZdeddfdZdedee	   fdZ
dedefd	Zded
e	ddfdZddee   ddfdZ xZS )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_sizer)   Nc                     t         |           i | _        | j                  |       t	        dd      | _        | j
                  | j
                  _        | j
                  | j
                  _        y)zl*max_size*, an ``int``, is the maximum number of nodes to cache;
        it must be greater than 0.
        N)r   r   r   set_max_sizer   sentinelr   r   )r   r  r   s     r   r   zLRUCache.__init__  sS    
 	24	(#&24&>!]]!]]r   c                      |dk  rd}|| _         y )Nr+   )r  )r   r  s     r   r
  zLRUCache.set_max_size  s    a<H r   r   c                 ~   | j                   5  | j                  j                  |      }|)| j                  xj                  dz  c_        	 ddd       y|j                          |j                  j                  t        j                         k  r@| j                  |j                  = | j                  xj                  dz  c_        	 ddd       y|j                  | j                         | j                  xj                  dz  c_        |xj                  dz  c_        |j                  cddd       S # 1 sw Y   yxY wr   )r   r   r9   r   r   r  r   r   r   r   r  r  r   r   r   r  s      r   r9   zLRUCache.get   s     YY 	99==%D|&&!+&		 	 KKMzz$$		3IIdhh'&&!+&	 	 OODMM*OO  A% IINI::	 	 	s   >D3A2D3AD33D<c                    | j                   5  | j                  j                  |      }|+|j                  j                  t        j
                         k  r
	 ddd       y|j                  cddd       S # 1 sw Y   yxY w)zBReturn the number of cache hits associated with the specified key.Nr   )r   r   r9   r   r   r   r   r  s      r   get_hits_for_keyzLRUCache.get_hits_for_key<  sb    YY 	!99==%D|tzz44		C	! 	!
 yy	! 	! 	!s   A
A5 A55A>r   c                 >   | j                   5  | j                  j                  |      }|'|j                          | j                  |j                  = t        | j                        | j                  k\  r`| j                  j                  }|j                          | j                  |j                  = t        | j                        | j                  k\  r`t        ||      }|j                  | j                         || j                  |<   ddd       y# 1 sw Y   yxY wr   )r   r   r9   r  r   r&   r  r  r   r   r  )r   r   r   r  gnodes        r   r   zLRUCache.putE  s     YY 	"99==%DIIdhh'dii.DMM1**IIeii( dii.DMM1  U+DOODMM*!DIIcN	" 	" 	"s   CD6DDc                    | j                   5  |E| j                  j                  |      }||j                          | j                  |j                  = nZ| j
                  j                  }|| j
                  k7  r.|j                  }|j                          |}|| j
                  k7  r.i | _        ddd       y# 1 sw Y   yxY wr   )r   r   r9   r  r   r  r   )r   r   r  r  r   s        r   r   zLRUCache.flush[  s     YY 	yy}}S)#KKM		$((+**t}}, ::DLLN E t}}, 		 	 	s   BB8(B88C)i r   )rF   rG   rH   rI   r   r   r
  r   r   r{   r9   r  r   r   rM   rN   s   @r   r  r    s    
+ 
+$ 
+!S !T !
x HV$4 8!H ! !"x " "4 ",(+ t r   r  c                      e Zd ZdZdddeej                  j                  ef   deej                  j                  ef   deej                  j                  ef   deded	ee   d
dfdZd
eeej"                  j$                     ee   f   fdZd
eej*                  j,                  eef   fdZdeej"                  j2                     dee   d
eee   ef   fdZy)_Resolutiona  Helper 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.
    resolverBaseResolverr5   r|   r}   tcpraise_on_no_answersearchr)   Nc                    t        |t              r t        j                  j	                  |d       }t        j
                  j                  j                  |      }t        j
                  j                  |      rt        t        j                  j                  j                  |      }t        j                  j                  |      rt        || _        |j                  ||      | _        | j                  d d  | _        || _        || _        || _        || _        i | _        t        j                  j,                  | _        g | _        g | _        g | _        d | _        d| _        d| _        d | _        d| _        y )NF        ) r!   r/   r   r   	from_textr   r   r   is_metatyperw   r   r   is_metaclassr  _get_qnames_to_tryqnames_to_tryr   r|   r}   r  r  nxdomain_responsesemptyr5   nameserverscurrent_nameserversrS   r~   tcp_attemptretry_with_tcprn   backoff)r   r  r5   r|   r}   r  r  r  s           r   r   z_Resolution.__init__  s&    eS!HH&&ud3E((--f5==$$V,..++009>>&&w/ %88G((+"4QSXX^^
<>DF (*?C #;?r   c                 X   t        | j                        dkD  rq| j                  j                  d      | _        | j                  j
                  r*| j                  j
                  j                  | j                  | j                  | j                  f      }|2|j                  "| j                  rt        |j                        d|fS | j                  j
                  j                  | j                  t        j                  j                  | j                  f      }|Z|j                  j!                         t        j                   j"                  k(  r%|j                  | j$                  | j                  <   zt        j&                  j)                  | j                  | j                  | j                        }| j                  j*                  P|j-                  | j                  j.                  | j                  j*                  | j                  j0                         |j3                  | j                  j4                  | j                  j6                  | j                  j8                  | j                  j:                         | j                  j<                  | j                  j<                  |_        | j                  j?                  | j                  j@                  | j                  jB                  | j                  jD                        | _#        | j                  jH                  rtK        jL                  | jF                         | jF                  dd | _'        g | _(        d| _)        d| _*        d| _+        || _,        d| _-        |dfS t#        | j\                  | j$                        )	zGet 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.
        r   Nr6   )	algorithm)optionsFg?r    )/r&   r   popr5   r  cacher9   r|   r}   r   r  rf   r6   r   r   ANYrcoder   r"  r   
make_querykeynameuse_tsigkeyringkeyalgorithmuse_ednsedns	ednsflagspayloadednsoptionsflags_enrich_nameservers_nameserversnameserver_portsr   r$  rotaterandomshuffler%  rS   r~   r&  r'  rn   r(  r!  )r   r   rn   s      r   next_requestz_Resolution.next_request  s    $++"+DJ }}"",,00ZZdll; %||+0G0G&@@ $f~-,,00ZZ!2!2DLLA %&//*?*?*ASYYEWEW*W ;A//D++DJJ7 kk,,TZZdllSG}}$$0  MM))MM))"mm88 ! 
 ""''%%11	   }}"". $ 3 3#}}@@**.."" D
 }}##t//0'+'7'7':D$DK"DO$D"'D"DLDLT?" d00D<S<STTr   c                 ~   | j                   rG| j                  J | j                  j                         rJ d| _        d| _         | j                  ddfS d}| j                  swt        | j                        dk(  r!t        | j                  | j                        | j                  d d  | _        | j                  }t        | j                  dz  d      | _
        | j                  j                  d      | _        | j                  xs | j                  j                         | _        | j                  | j                  |fS )NTFr   r  )rn   rS      )r'  r~   is_always_max_sizer&  r%  r&   r$  rm   rn   rS   r(  minr-  r  )r   r(  s     r   next_nameserverz_Resolution.next_nameserver  s   ??..99;;#D"'DOOT1--''4##$)#DLLMM'+'7'7':D$llGt||a/3DL2266q988Kt'I'I'K!1!17;;r   r6   exc           	         | j                   J |r1|J | j                  j                  t        | j                         | j                  | j                   j                         ||f       t        |t        j                  j                        s0t        |t              s t        |t              st        |t              r&| j                  j                  | j                          yt        |t        j                  j                         r9| j                  r&| j                  j                  | j                          yd| _        y|J t        |t        j                  j$                        sJ |j'                         }|t        j&                  j(                  k(  r	 t+        | j,                  | j.                  | j0                  || j                   j3                         | j                   j                               }| j6                  j8                  rG| j6                  j8                  j;                  | j,                  | j.                  | j0                  f|       |j<                  "| j>                  rtA        |jB                        |dfS |t        j&                  jD                  k(  r	 t+        | j,                  t        jF                  jH                  t        jJ                  jL                  |      }|| jN                  | j,                  <   | j6                  j8                  rU| j6                  j8                  j;                  | j,                  t        jF                  jH                  | j0                  f|       y|t        j&                  jP                  k(  ratQ               }| j                  j                  t        | j                         | j                  | j                   j                         ||f       ||t        j&                  jR                  k7  s| j6                  jT                  s%| j                  j                  | j                          | j                  j                  t        | j                         | j                  | j                   j                         t        j&                  jW                  |      |f       y# t4        $ r}| j                  j                  t        | j                         | j                  | j                   j                         ||f       | j                  j                  | j                          Y d }~yd }~ww xY w# t4        $ r}| j                  j                  t        | j                         | j                  | j                   j                         ||f       | j                  j                  | j                          Y d }~yd }~ww xY w)NT)NFr*  )NT),r~   rS   r:   r/   r&  answer_portr!   r   	exception	FormErrorEOFErrorOSErrorr   r$  remover   	Truncatedr'  r   r0  NOERRORr{   r5   r|   r}   answer_nameserverr4   r  r.  r   r   r  rf   r6   r   r   r/  r   INr"  rP   SERVFAILretry_servfailto_text)r   r6   rH  r0  r   eyexs          r   query_resultz_Resolution.query_result  s[    **##KK($$OO//1 2s}}667b(+b'*b"56   ''8 ! B 5 56##$$++DOO< ! +/D' ##(CKK$<$<== CII%%%%JJKKLLOO557OO//1* }}""##''T[[$,,(OQWX||#(?(?88D>!cii(((%JJ 1 13>>3D3Dh  3;D##DJJ/}}""##''ZZ!2!2DLLA6
  cii(((*CKK($$OO//1 I 		***$--2N2N  ''8KK($$OO//1II%%e, !U  %""DOO,((335    ''8$%2  %""DOO,((335    ''8$%s4   AR< &AU <	U	A:UU		WA:WW)rF   rG   rH   rI   r   r   r   r   r/   r   r   r   r   r   r   r   r
   r   r   r{   rB  r~   
Nameserverr   rG  Messager4   rY  rR   r   r   r  r  t  s/   	# # SXX]]C'(# cmm--s23	#
 s~~00#56# # !# # 
#JIU	x0018F3CC	DIUV<s~~'@'@$'M!N <*z! !4!45z!;CI;Nz!	x%	&z!r   r  c                      e Zd ZU dZej
                  j                  ed<   ee	e
f   ed<   e
ed<   eej
                  j                     ed<   eed<   eed<   eed<   ee   ed	<   eeej
                  j                  e	f      ed
<   eej
                  j                  e	f   ed<   e
ed<   e
ed<   eeej"                  j$                        ed<   e
ed<   eed<   ee
   ed<   eed<   eed<   ee
   ed<   eee	ej(                  j*                  f      ed<   	 d/de	deddfdZd0dZdeddfdZd0dZ	 	 d1dedee   d eee      defd!Zd"ej
                  j                  dee   deej
                  j                     fd#Zdej:                  j<                  fd	ed
eeej
                  j                  e	f      d$eej
                  j                  e	f   ddfd%Zd&d&ej@                  jB                  dfdeee
ef      de
de
d'eeej"                  j$                        ddf
d(Z"de
ddfd)Z#e$d*eee	ej(                  j*                  f      dee	e
f   d+e
deej(                  j*                     fd,       Z%e&deee	ej(                  j*                  f      fd-       Z'e'jP                  d*eee	ej(                  j*                  f      ddfd.       Z'y)2r  r   domainr>  r   r  use_search_by_defaultr\   lifetimer4  r2  r5  r7  r8  r:  r9  r.  r;  rU  r?  ndotsr=  filename	configurer)   Nc                     | j                          |r9t        j                  dk(  r| j                          y|r| j	                  |       yyy)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)r   sysplatformread_registryread_resolv_conf)r   ra  rb  s      r   r   zBaseResolver.__init__  sC     	

||w&""$%%h/  r   c                 X   t         j                  j                  t         j                  j                  t	        j
                               dd       | _        t        | j                        dk(  rt         j                  j                  | _        g | _	        i | _
        d| _        g | _        d| _        d| _        d| _        d| _        d| _        t         j$                  j&                  | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        y)	z1Reset all resolver configuration to the defaults.r+   Nr   5   Fg       @      @r[   )r   r   r   r  r   gethostnamer]  r&   rootr=  r>  r   r  r^  r\   r_  r4  r2  tsigdefault_algorithmr5  r7  r8  r:  r9  r.  r;  rU  r?  r`  rC   s    r   r   zBaseResolver.reset  s     hhmmCHH$6$6v7I7I7K$LQR$PQt{{q ((--DK "	%*"HH66	

#
r   fc                 L   g }t        |t              r	 t        |      }nt        j                  |      }|5 }|D ]m  }t        |      dk(  s|d   dk(  s|d   dk(  r#|j                         }t        |      dk  rB|d   dk(  r|j                  |d          _|d   dk(  r/t        j                  j                  |d         | _        g | _        |d   d	k(  rJg | _        |dd
 D ]:  }| j                  j                  t        j                  j                  |             < |d   dk(  s|dd
 D ]u  }|dk(  rd| _        |dk(  r| j!                          &d|v r$	 t#        |j                  d      d         | _        Nd|v sS	 t#        |j                  d      d         | _        w p 	 d
d
d
       t        |      dk(  rt	        d      || _        y
# t        $ r t	        d|       w xY w# t&        t(        f$ r Y w xY w# t&        t(        f$ r Y w xY w# 1 sw Y   oxY w)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   #;rD  r~   r+   r]  r  Nr,  r?  Tedns0r\   :r`  zno nameservers)r!   r/   openrN  ry   
contextlibnullcontextr&   splitr:   r   r   r  r]  r  r?  r6  r   r\   
ValueErrorr   r`  r$  )r   ro  r$  cmltokenssuffixopts           r   rg  zBaseResolver.read_resolv_conf  s<   " aB8<Q
 ''*B &	%1 %%q6Q;!A$#+1 v;?!9,&&vay1AY(*"%(("4"4VAY"?DK"$DKAY(*"$DK"(* G**388+=+=f+EFG AY)+%abz %(?*.DK G^ MMO&#-%/2399S>!3D/E %^%-031B-C
%/%%&	%N {q )*:;; 'a  B-QC.@AABJ %/
#; % $%
 %/
#; % $%K&	% &	%se   G C3H+/H"G0=H"H&HG-0H	?HH	HH	HH	HH#c                     	 t         j                  j                         }|j                  |j                  | _        |j                  | _        |j
                  | _        y# t        $ r t        w xY w)z9Extract resolver configuration from the Windows registry.N)r   	win32utilget_dns_infor]  r$  r  r%   r   )r   infos     r   rf  zBaseResolver.read_registry  s\    	&==--/D{{&"kk#//D++DK 	&%%	&s   AA   A0startrS   c                     || j                   n|}t        j                         }||z
  }|g }|dk  r|dk  rt        ||      d}||k\  rt        ||      t        ||z
  | j                        S )Nr   r[   r`   )r_  r   rZ   rF  r\   )r   r  r_  rS   r   durations         r   _compute_timeoutzBaseResolver._compute_timeout  s     %-$44==(iik;>Fa<"}%hvFF
 x!(6BB8h&55r   r5   c                    || j                   }g }|j                         r|j                  |       |S |j                  t        j
                  j                        }|rt        | j                        dkD  r| j                  d d  }nC| j                  t        j
                  j                  k7  r| j                  | j                  g}ng }| j                  d}n| j                  }|D ]  }|j                  ||z           t        |      |kD  r|j                  d|       |S |j                  |       |S |j                  |       |S )Nr   r+   )r^  is_absoluter:   concatenater   r   rl  r&   r  r]  r`  insert)r   r5   r  r!  	abs_qnamesearch_listr`  r}  s           r   r   zBaseResolver._get_qnames_to_try7  s2   
 >//F  '< 9 ))#((--8It{{#a'"&++a.K[[CHHMM1dkk6M $(;;-K"$K::%E JJE) 9F!((89u:% "((I6  "((3  $$Y/r   r+  c                 .    || _         || _        || _        y)zAdd a TSIG signature to each query.

        The parameters are passed to ``dns.message.Message.use_tsig()``;
        see its documentation for details.
        N)r4  r2  r5  )r   r4  r2  r+  s       r   r3  zBaseResolver.use_tsig`  s     %r   r   r,  c                 Z    ||du rd}n|du rd}|| _         || _        || _        || _        y)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   )r7  r8  r9  r:  )r   r7  r8  r9  r,  s        r   r6  zBaseResolver.use_ednsp  s=    0 <45=DT\D	""r   c                     || _         y)zkOverrides the default flags with your own.

        *flags*, an ``int``, the message flags to use.
        N)r;  )r   r;  s     r   	set_flagszBaseResolver.set_flags  s     
r   r$  default_portc                 2   g }t        |t              r|D ]  }t        |t        j                  j                        r|}nt        j
                  j                  |      r3|j                  ||      }t        j                  j                  ||      }n?	 t        |      j                  dk7  rt        	 t        j                  j                  |      }|j                  |        |S t        dt!        |       d      # t        $ r t        d| d      w xY w)Nhttpsznameserver z\ is not a dns.nameserver.Nameserver instance or text form, IP address, nor a valid https URLz+nameservers must be a list or tuple (not a ))r!   r"   r   r~   rZ  inet
is_addressr9   Do53Nameserverr   schemer   r4   ry  DoHNameserverr:   type)r   r$  r>  r  enriched_nameserversr~   enriched_nameserverr   s           r   r<  z BaseResolver._enrich_nameservers  s"     "k4() A
j#..*C*CD*4'XX((4+//
LID*-..*G*G"D+'#J/66'A"55 B +...*F*Fz*R'$++,?@)A2 $# =d;>O=PPQR  % ()* 6@ @ s   C==Dc                     | j                   S r   )r=  rC   s    r   r$  zBaseResolver.nameservers  s        r   c                 `    | j                  || j                  | j                         || _        y)a  
        *nameservers*, a ``list`` of nameservers, where a nameserver is either
        a string interpretable as a nameserver, or a ``dns.nameserver.Nameserver``
        instance.

        Raises ``ValueError`` if *nameservers* is not a list of nameservers.
        N)r<  r>  r   r=  )r   r$  s     r   r$  zBaseResolver.nameservers  s(     	  d.C.CTYYO'r   )z/etc/resolv.confTr   r   ))rF   rG   rH   rI   r   r   r   __annotations__r   r/   r   r   r   r   r   r   r   r7  Optionr	   r~   rZ  r   r   rg  rf  
ErrorTupler  r   rm  rn  r3  r   DEFAULT_EDNS_PAYLOADr6  r  r   r<  rL   r$  setterrR   r   r   r  r    s{    HHMM38n$
INOc]eCHHMM3./00s*++
IN$sxx/00LJC=LC=5cnn&?&?!?@AA EI00=A0	0*4E'# E'$ E'N	& %)-1	66 5/6 j)*	6
 
60'XX]]',4TN'	chhmm	'X 8</2xx/I/I	&& %s 234& +,	&
 
&$ ,-{{7737#uS$Y'(# # 	#
 $sxx/0# 
#Bs t  !$eC)B)B$BCD!$ sCx.!$ 	!$
 
cnn''	(!$ !$F !	%S^^6667	8! !
 (#E#s~~/H/H*H$IJ(	( (r   r  c                   n   e Zd ZdZej
                  j                  ej                  j                  ddddddfde	ej                  j                  ef   de	ej
                  j                  ef   de	ej                  j                  ef   d	ed
ee   dededee   dee   defdZej
                  j                  ej                  j                  dddddfde	ej                  j                  ef   de	ej
                  j                  ef   de	ej                  j                  ef   d	ed
ee   dededee   defdZdedededefdZej2                  fde	ej                  j                  ef   dededefdZde	ej                  j                  ef   dej                  j                  fdZddeddfdZy)Resolverr   FNTr   r5   r|   r}   r  sourcer  source_portr_  r  r)   c
           	         t        | ||||||	      }
t        j                         }	 |
j                         \  }}||S |J d}|s{|
j                         \  }}}|rt        j                  |       | j                  |||
j                        }	 |j                  |||||      }|
j                  |d      \  }}||S |s{# t        $ r}|
j                  d|      \  }}Y d}~d}~ww xY w)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\   r  r  r  )
r  r   rB  rG  sleepr  rS   ri   r4   rY  )r   r5   r|   r}   r  r  r  r  r_  r  
resolutionr  rn   r   doner~   r(  r\   r6   rH  _s                        r   resolvezResolver.resolve  s!   ~ !%#/A6

 		 * 7 7 9Wf
 !&&D-7-G-G-I*S'JJw'//xARARS
)// '%$/!$  0  H ",!8!84!H
 %!M-  0 !  * 7 7b AIQs   C 	C*C%%C*c	                 l    t        j                  dt        d       | j                  ||||||||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() insteadrD  
stacklevelTwarningswarnDeprecationWarningr  )	r   r5   r|   r}   r  r  r  r  r_  s	            r   ri   zResolver.query<  sG    $ 	@	

 ||

 
	
r   ipaddrr   r   c                    i }|j                  |       t        j                  j                  |d<   t        j                  j
                  |d<    | j                  t        j                  j                  |      g|i |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.
        r|   r}   )	updater   r   PTRr   rS  r  reversenamefrom_address)r   r  r   r   modified_kwargss        r   resolve_addresszResolver.resolve_address_  st      +-v&$'MM$5$5!%(^^%6%6	"t||OO((0
37
;J
 	
r   r   r   c                    i }|j                  |       |j                  dd       t        j                  j                  |d<   |t
        j                  k(  rB | j                  |t        j                  j                  fi |}t        j                  |      S |t
        j                  k(  rB | j                  |t        j                  j                  fi |}t        j                  |      S |t
        j                  k7  rt        d|       |j                  dd      }|j                  d	d      }t!        j                          }	 | j                  |t        j                  j                  fd
| j#                  |	|      d|}|j$                  } | j                  |t        j                  j                  fd
| j#                  |	|      d|}t        j                  |||       }
|
st'        |j(                        |
S )a  Use a resolver to query for address records.

        This utilizes the resolve() method to perform A and/or AAAA lookups on
        the specified name.

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

        *family*, an ``int``, the address family.  If socket.AF_UNSPEC
        (the default), both A and AAAA records will be retrieved.

        All other arguments that can be passed to the resolve() function
        except for rdtype and rdclass are also supported by this
        function.
        r|   Nr}   )r   )r   r   r  Tr_  F)r  r_  )r   r   r   r*  )r  r-  r   r   rS  r   r   r  r   r   r   r   r   r   r   r   r   r  r5   rf   r6   )r   r   r   r   r  r   r   r  r_  r  r   s              r   resolve_namezResolver.resolve_namew  s   . +-v&Hd+%(^^%6%6	"V^^#dCMMOOGGB##r#**v&dCMM$6$6J/JB##r#**v'''%(?x&HII,001EtL"&&z48		T\\MM
  %**5(;	

 
 xxT\\MMOO
  %**5(;	

 
 ""bR?Q;Q"RBKK00r   c                     	 | j                  |d      }|j                  }|S # t        j                  j                  $ r}|j                  }Y d}~|S d}~ww xY w)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  r3   r   r  r   )r   r   r   r3   rW  s        r   r3   zResolver.canonical_name  sY    	.\\$5\AF#22N  ||$$ 	.--N	.s   # A AAc                 T   	 t        j                          |z   }| j                  t        j                  j                  d|      }t        j
                  j                  |      }t        j                  j                  ||      }t        |      dkD  r|| _	        yy# t        $ r Y yw xY w)a  Try to update the resolver's nameservers using Discovery of Designated
        Resolvers (DDR).  If successful, the resolver will subsequently use
        DNS-over-HTTPS or DNS-over-TLS for future queries.

        *lifetime*, a float, is the maximum time to spend attempting DDR.  The default
        is 5 seconds.

        If the SVCB query is successful and results in a non-empty list of nameservers,
        then the resolver's nameservers are set to the returned servers in priority
        order.

        The current implementation does not use any address hints from the SVCB record,
        nor does it resolve addresses for the SCVB target name, rather it assumes that
        the bootstrap nameserver will always be one of the addresses and uses it.
        A future revision to the code may offer fuller support.  The code verifies that
        the bootstrap nameserver is in the Subject Alternative Name field of the
        TLS certficate.
        SVCBr_  r   N)r   r  r   _ddr_local_resolver_nameri   
_remaining_get_nameservers_syncr&   r$  r4   )r   r_  r   r   r\   r$  s         r   try_ddrzResolver.try_ddr  s    &
	x/J\\--v " F ii**:6G((88IK;!##.  $ 		s   BB 	B'&B'rj  )rF   rG   rH   rI   r   r   r   r   rS  r   r   r   r/   r   r   r   r   r   r   r{   r  ri   r   r  r   r   r   r  r3   r  rR   r   r   r  r    s]   
 7:mmoo9<9J9J $#'$(!%d"SXX]]C'(d" cmm--s23d" s~~00#56	d"
 d" d" !d" d" 5/d" d" 
d"R 7:mmoo9<9J9J $#'$(!
SXX]]C'(!
 cmm--s23!
 s~~00#56	!

 !
 !
 !!
 !
 5/!
 
!
F
c 
# 
 
 
6 &&?CHHMM3&'? ? 	?
 
?F5);#<  .  r   r  default_resolverc                  >    t         
t                t         J t         S )z7Get the default resolver, initializing it if necessary.)r  reset_default_resolverrR   r   r   get_default_resolverr    s     ''r   c                      t               ay)zRe-initialize default resolver.

    Note that the resolver configuration (i.e. /etc/resolv.conf on UNIX
    systems) will be re-read immediately.
    N)r  r  rR   r   r   r  r    s      zr   FTr5   r|   r}   r  r  r  r  r_  r  c	                 D    t               j                  | ||||||||	      S )zQuery 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  )	r5   r|   r}   r  r  r  r  r_  r  s	            r   r  r    s5    (  !))
 
r   c                 `    t        j                  dt        d       t        | |||||||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.
    z)please use dns.resolver.resolve() insteadrD  r  Tr  )r5   r|   r}   r  r  r  r  r_  s           r   ri   ri   )  sC    " MM35GTU 
 
r   r  r   r   c                 >     t               j                  | g|i |S )zUse a resolver to run a reverse query for PTR records.

    See ``dns.resolver.Resolver.resolve_address`` for more information on the
    parameters.
    )r  r  )r  r   r   s      r   r  r  J  s%     2!11&J4J6JJr   r   r   c                 :     t               j                  | |fi |S )zUse a resolver to query for address records.

    See ``dns.resolver.Resolver.resolve_name`` for more information on the
    parameters.
    )r  r  )r   r   r   s      r   r  r  T  s"     /!..tVFvFFr   c                 4    t               j                  |       S )zDetermine the canonical name of *name*.

    See ``dns.resolver.Resolver.canonical_name`` for more information on the
    parameters and possible exceptions.
    )r  r3   r   s    r   r3   r3   `  s      !0066r   c                 4    t               j                  |       S )a  Try to update the default resolver's nameservers using Discovery of Designated
    Resolvers (DDR).  If successful, the resolver will subsequently use
    DNS-over-HTTPS or DNS-over-TLS for future queries.

    See :py:func:`dns.resolver.Resolver.try_ddr` for more information.
    )r  r  r  s    r   r  r  j  s      !))(33r   r  c                    t        | t              r8t        j                  j	                  | t        j                  j
                        } |
t               }| j                         st        |       t        j                         }|||z   }nd}	 	 ||t        j                         z
  }|dk  rd}nd}|j                  | t        j                  j                  |||      }|j                  J |j                  j                  | k(  r| S 	 	 | j3                         } # t        j                  j                  t        j                  j                   f$ r}	t        |	t        j                  j                        r |	j#                         j%                  |       }
n|	j'                         }
|
r|
j(                  D ]  }|j*                  t        j                  j                  k(  s+|j,                  |k(  s;|j                  j/                  |       \  }}}|t        j                  j0                  k(  sx|j                  c cY d}	~	S  Y d}	~	=d}	~	ww xY w# t        j                  j4                  $ r t6        w xY w)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  )r!   r/   r   r   r  rl  r  r  rr   r   r  r   SOAr   r  r   rf   r   r9   r6   	authorityr|   r}   fullcompareNAMERELN_SUPERDOMAINparentNoParentru   )r   r}   r  r  r_  r  r   	rlifetimer   rW  r6   rrsnrr  s                 r   zone_for_namer  t  s   @ $xx!!$6')$IIKEX%


	,%&4	> !I 	%%cmm''#	 & F <<++||  D( ),	;;=DI   %%s||'<'<= 	,!S\\223;;=,,T2::<#-- 
,CzzS]]%6%663;;';Q%(XX%9%9$%?
Q!>!>> $'88O
,	,* xx   	O	sD   A9D I 7IBI!I1<I.I;III$I4ri  wherer   c                    |
t               }g }t        | t              rOt        j                  j                  |       r0|j                  t        j                  j                  | |             nT|j                  | |      j                         D ]1  }|j                  t        j                  j                  ||             3 t        j                  j                  d      }||_        |S )a  Make a stub resolver using the specified destination as the full resolver.

    *where*, a ``dns.name.Name`` or ``str`` the domain name or IP address of the
    full resolver.

    *port*, an ``int``, the port to use.  If not specified, the default is 53.

    *family*, an ``int``, the address family to use.  This parameter is used if
    *where* is not an address.  The default is ``socket.AF_UNSPEC`` in which case
    the first address returned by ``resolve_name()`` will be used, otherwise the
    first address of the specified family will be used.

    *resolver*, a ``dns.resolver.Resolver`` or ``None``, the resolver to use for
    resolution of hostnames.  If not specified, the default resolver will be used.

    Returns a ``dns.resolver.Resolver`` or raises an exception.
    F)rb  )r  r!   r/   r   r  r  r:   r~   r  r  r   r  r  r$  )r  r   r   r  r$  r   ress          r   make_resolver_atr    s    . ')?AK%#(("5"5e"<3>>88EF,,UF;EEG 	MGs~~<<WdKL	M
,,

%

0C!COJr   c                 L    t        | |
||      j                  |||||||||		      S )a}  Query nameservers to find the answer to the question.

    This is a convenience function that calls ``dns.resolver.make_resolver_at()`` to
    make a resolver, and then uses it to resolve the query.

    See ``dns.resolver.Resolver.resolve`` for more information on the resolution
    parameters, and ``dns.resolver.make_resolver_at`` for information about the resolver
    parameters *where*, *port*, *family*, and *resolver*.

    If making more than one query, it is more efficient to call
    ``dns.resolver.make_resolver_at()`` and then use that resolver for the queries
    instead of calling ``resolve_at()`` multiple times.
    )r  r  )r  r5   r|   r}   r  r  r  r  r_  r  r   r   r  s                r   
resolve_atr    s=    8 E4:BB
 
r   c           
         |t         j                  z  dk7  rt        | |||||      S |t         j                  t         j                  z  z  dk7  r$t        j
                  t         j                  d      | &|$t        j
                  t         j                  d      g }d }| t        | |||||      S 	 t        j                  j                  |        t        | |||||      S # t        $ r Y nw xY w	 t        j                  | |      }|j                         }|j                         j!                  d      }nq# t        j"                  j$                  $ r% t        j
                  t         j                  d      t        $ r% t        j
                  t         j&                  d      w xY wd }		 |d}	nt)        |      }	nK# t        $ r? |t         j*                  z  dk(  r&	 t        j,                  |      }	n# t        $ r Y nw xY wY nw xY w|	$t        j
                  t         j                  d      g }
|dk(  r!t         j.                  t         j0                  g}n|g}|t         j2                  z  dk7  r|}nd}|D ]R  \  }}|D ]H  }t4        |   D ]:  }t        j                  j7                  ||	f|      }|
j9                  |||||f       < J T t;        |
      dk(  r$t        j
                  t         j                  d      |
S )Nr   z*Non-recoverable failure in name resolutionName or service not knownTz$Temporary failure in name resolution )r   AI_NUMERICHOST_original_getaddrinfoAI_ADDRCONFIGAI_V4MAPPEDgaierrorEAI_FAIL
EAI_NONAMEr   r  af_for_addressr4   	_resolverr  r   r3   rV  r  r   	EAI_AGAINr   AI_NUMERICSERVgetservbyname
SOCK_DGRAMSOCK_STREAMAI_CANONNAME_protocols_for_socktypelow_level_address_tupler:   r&   )hostservicer   socktypeprotor;  addrsr3   r   r   tuples	socktypesr7   addraf
addr_tuples                   r   _getaddrinfor  )  s    v$$$) %T7FHeUSS$$v'9'99:a? ooOOI
 	
 |oof//1LMMEN |$T7FHeUSS 	%$T7FHeUSS 
X((v6..0 //199$?<<   Noof//1LMM X oof..0VWW	X
 D?Dw<D 6(((A-++G4 	 |oof//1LMMF1}&&(:(:;	J	v"""a' Hb! 	HH0: H XX==tTlBO
r8UE:FGH	HH
 6{aoof//1LMMMsV   1.C   	C,+C,0AD6 6A.F$*F; ;HG10H1	G=:H<G==HHc                    | d   }| d   }t        |       dk(  r| d   }t        j                  }nd }t        j                  }t	        |||t        j
                  t        j                  d      }t        |      dkD  rt        d      |d   d   d   }|t        j                  z  rd}nd}t        j                  j                  |      }	|t        j                  z  dk(  r@	 t        j                  |	d      }
|
j                  d   j                   j#                  d	      }n|}||dt1        |      z   z  }|t        j2                  z  rt1        |      }||fS t        j4                  ||      }||fS # t        j$                  j&                  t        j$                  j(                  f$ rO |t        j*                  z  r$t        j,                  t        j.                  d
      |}||dt1        |      z   z  }Y w xY w)Nr   r+      rU   z'sockaddr resolved to multiple addressesudpr  r  Tr  %)r&   r   r   r   r  r  SOL_TCPrN  NI_DGRAMr   r  r  NI_NUMERICHOSTr  r  r   targetrV  r  r   rf   NI_NAMEREQDr  r  r/   NI_NUMERICSERVgetservbyport)sockaddrr;  r  r   scoper   r  r  pnamer5   r   hostnamer  s                r   _getnameinfor  }  s   A;DA;D
8}$ff.@.@&..RSTF
6{Q?@@!9Q<?DvOO((.Ev$$$)	-&&ue4F||A--55d;H c%j((Hv$$$d) g &&tU3g %%s||'<'<= 	-v)))oof&7&79TUUH C#e*,,	-s   >E/ /BG54G5c                 r    | t        j                         } 	 t        |       \  } }}| S # t        $ r Y | S w xY wr   )r   rk  _gethostbyaddrr4   )r   r  s     r   _getfqdnr    sJ    |!!#%d+q!
 K  Ks   ) 	66c                 $    t        |       d   d   S )NrD  r   )_gethostbyname_exr  s    r   _gethostbynamer    s    T"1%a((r   c                     g }g }t        | dt        j                  t        j                  t        j                  t        j
                        }|d   d   }|D ]  }|j                  |d   d           |||fS )Nr   rU   r  )r  r   r   r  r	  r  r:   )r   aliasesr   r  	canonicalitems         r   r  r    sz    GIa!3!3V^^VEXEXF q	!I %a$% w	**r   c                    	 t         j                  j                  |        | dddf}t        j                  }t        |t        j                        \  }}g }g }t        |d|t        j                  t        j                  t        j                        }|d   d   }t         j                   j#                  ||       }	|D ]A  }
|
d   d   }t         j                   j#                  ||      }|	|k(  s1|j%                  |       C |||fS # t
        $ rj 	 t         j                  j                  |        n1# t
        $ r% t        j                  t        j                  d      w xY w| df}t        j                  }Y @w xY w)NP   r   r  rU   r  )r   ipv6	inet_atonr   r   r4   ipv4r  r  r   r  r  r  r  r	  r  r  	inet_ptonr:   )ipr  r   r   r  r  r   r  r  bin_ipr  r  bin_addrs                r   r  r    sZ   
 2Aq> Xv'9'9:IT1GIa++V^^V=P=PF q	!I XX+F #Awqz88%%fd3XT"	# w	**1   	RHHr" 	R//&"3"35PQQ	R8 s)   5D 	E8D/.E8/.EE87E8c                     | 
t               } | at        t        _        t
        t        _        t        t        _        t        t        _
        t        t        _        t        t        _        y)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  r  r  r   getaddrinfor  getnameinfor  getfqdnr  gethostbynamer  gethostbyname_exr  gethostbyaddr)r  s    r   override_system_resolverr/    sF     ')I%F%FFN)F/F)Fr   c                      da t        t        _        t        t        _        t        t        _        t        t        _	        t        t        _        t        t        _        y)z5Undo the effects of prior override_system_resolver().N)r  r  r   r)  _original_getnameinfor*  _original_getfqdnr+  _original_gethostbynamer,  _original_gethostbyname_exr-  _original_gethostbyaddrr.  rR   r   r   restore_system_resolverr6    s8     I.F.F&FN2F8F2Fr   r   r  )r   r   )zrI   rv  r@  r   rd  r   r   r  typingr   r   r   r   r   r	   r
   r   urllib.parser   dns._ddrr   dns.ednsdns.exception	dns.flagsdns.inetdns.ipv4dns.ipv6dns.messagedns.name	dns.rdatadns.nameserver	dns.query	dns.rcodedns.rdataclassdns.rdatatypedns.rdtypes.svcbbasedns.reversenamedns.tsigre  dns.win32utilrK  DNSExceptionr   rP   r/   r   r   r4   r   r[  r  rX   TimeoutrZ   rf   rm   rr   ru   rw   ry   r{   r'   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r   rS  r   r  ri   r  r   r  r3   r  r  r  r  r  SOL_UDPr  r	  r  r  r)  r  r*  r1  r+  r2  r,  r3  r-  r4  r.  r5  r  r  r  r  r  r  r/  r6  rR   r   r   <module>rO     s  $     
    N N N !                  <<7U/s}})) U/pCs}})) C SM	)S.S[[  !	#
D, c 
cmm++ 
, 's}})) '$
CMM.. 
2P#--,, PM** M+CMM.. +Pcmm88 PB BJ@d @.%' .%b7 7+ +>  7 79R9RRSLJI LJ^# #*ly l^K! K!\N( N(b
[| [~ (, (8$ +h " 36--//58^^5F5F # $!#$#--))3./ 3>>,,c12 
	
 SM   uo TN F 36--//58^^5F5F # $#$#--))3./ 3>>,,c12 
	
 SM   uo BKC K Ks Kv K 4:3C3C	G
s"
#	G-0	GOR	G	G7sxx}}c12 7sxx}} 74e 4d 4 *-):):#' $R
s"
#R^^&&R 
R x 	R
 uoR 	XX]]Rn ""#'	!#$!
! ! x 	!
 !N 36--//58^^5F5F # $!""#'&#$&#$& #--))3./& 3>>,,c12	&
 
& SM& & & uo& TN& & & x & &^ '
( 
 	** ** NN  .. #44  ..  
tF$4$4qQRQh$N	)
++@*x'9 *T *4
3r   