
    "                     `   S r SSKrSSKrSSKrSSKr SSKrSSK	r
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKr
SSKJrJr  \R2                  S:X  a   SSKr " S S\
R8                  R:                  5      r " S S	\
R8                  R:                  5      r\
R8                  R@                  r  " S
 S\
R8                  R:                  5      r! " S S\
R8                  R:                  5      r" " S S\
R8                  R:                  5      r# " S S\
R8                  R:                  5      r$ " S S\
R8                  R:                  5      r% " S S\&5      r' " S S\&5      r( " S S\&5      r) " S S\&5      r* " S S\&5      r+Sq,S r-S r.\
R^                  R`                  \
Rb                  Rd                  S SS!SS4S" jr3\
Rb                  Rd                  S S4S# jr4\Rj                  \Rl                  /\Rn                  \Rp                  /0r9Sq:\Rv                  r<\Rz                  r>\R~                  r@\R                  rB\R                  rD\R                  rFSS\R                  SSS4S$ jrHS,S% jrIS-S& jrJS' rKS( rLS) rMS-S* jrNS+ rOg! \ a    SSKr GNf = f! \ a    SSKr GNGf = f).DNS stub resolver.    N   )xrangestring_typeswin32c                   n   ^  \ rS rSrSrSS1rSrSS jrU 4S jrS r	\
" \	S	S
9r	S rS rS rS rSrU =r$ )NXDOMAIN2   z"The DNS query name does not exist.qnames	responsesNc                     [        U[        [        [        45      (       d  [	        S5      e[        U5      S:X  a  [	        S5      eUc  0 nO [        U[        5      (       d  [	        S5      e[        XS9nU$ )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)selfr   r   kwargss       lib/third_party/dns/resolver.py_check_kwargsNXDOMAIN._check_kwargs7   sm    &4"455 !FGGv;! !KLLIIt,, !KLLV9    c                    > SU R                   ;  a  [        [        U ]  5       $ U R                   S   n[	        U5      S:  a  SnOSnSR                  [        [        U5      5      nSR                  X!5      $ )Nr   r   zNone of DNS query names existz!The DNS query name does not existz, z{}: {})	r   superr	   __str__r   joinmapstrformat)r   r   msg	__class__s      r   r   NXDOMAIN.__str__C   sf    4;;&4022X&v;?1C5C3sF+,s++r   c                    SU R                   ;  a  [        S5      e[        R                  R                  n[        R
                  R                  nS nU R                   S    H  nU R                   S   U   nUR                   HL  nUR                  U:w  d  UR                  U:w  a  M%  UR                  S   R                  R                  5       nMN     Uc  Mv  [        R                  R                  U5      s  $    U R                   S   S   $ )Nr   zparametrized exception requiredr   r   )r   	TypeErrordns
rdataclassIN	rdatatypeCNAMEanswerrdtyperdclassitemstargetto_textname	from_text)r   r*   r,   cnameqnameresponser-   s          r   canonical_nameNXDOMAIN.canonical_nameN   s    4;;&=>>^^##[[*E{{;/6H"//==E)V^^r-AQ..668 *  xx))%00 + {{8$Q''r   z%Return the unresolved canonical name.)docc                 l   [        U R                  R                  S/ 5      5      n[        U R                  R                  S0 5      5      nUR                  R                  S0 5      nUR                  R                  S/ 5       H&  nXR;  a  UR	                  U5        XT;   d  M   XE   X5'   M(     [        X#S9$ )z3Augment by results from another NXDOMAIN exception.r   r   r   )r   r   getr   appendr	   )r   e_nxqnames0
responses0
responses1qname1s         r   __add__NXDOMAIN.__add__`   s    t{{x45$++//+r:;
[[__["5
kkooh3F$v&#%/%7
"	 4
 w==r   c                      U R                   S   $ )zHAll of the names that were tried.

Returns a list of ``dns.name.Name``.
r   r   r   s    r   r   NXDOMAIN.qnamesl   s    
 {{8$$r   c                      U R                   S   $ )zA map from queried names to their NXDOMAIN responses.

Returns a dict mapping a ``dns.name.Name`` to a
``dns.message.Message``.
r   rF   rG   s    r   r   NXDOMAIN.responsess   s     {{;''r   c                 &    U R                   S   U   $ )zDThe response for query *qname*.

Returns a ``dns.message.Message``.
r   rF   )r   r6   s     r   r7   NXDOMAIN.response{   s    
 {{;'..r    N)__name__
__module____qualname____firstlineno____doc__supp_kwargsfmtr   r   r8   propertyrC   r   r   r7   __static_attributes____classcell__r$   s   @r   r	   r	   2   sN    ,[)K
C
	,( n/2N
>%(/ /r   r	   c                       \ rS rSrSrSrg)YXDOMAIN   z8The DNS query name is too long after DNAME substitution.rM   NrO   rP   rQ   rR   rS   rW   rM   r   r   r[   r[      s    Br   r[   c                   6   ^  \ rS rSrSrSrS1rU 4S jrSrU =r	$ )NoAnswer   z<The DNS response does not contain an answer to the question.zDThe DNS response does not contain an answer to the question: {query}r7   c                 @   > [         [        U ]  US   R                  S9$ )Nr7   )query)r   r_   _fmt_kwargsquestion)r   r   r$   s     r   rc   NoAnswer._fmt_kwargs   s*    Xt0$-- 1 / 	/r   rM   )
rO   rP   rQ   rR   rS   rU   rT   rc   rW   rX   rY   s   @r   r_   r_      s    F%C,K/ /r   r_   c                   H   ^  \ rS rSrSrSrS\SS -  rSS1rU 4S	 jrS
r	U =r
$ )NoNameservers   zAll 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}Nrequesterrorsc           
         > / nUS    H;  nUR                  SR                  US   US   (       a  SOSUS   US   5      5        M=     [        [        U ]  US	   R
                  S
R                  U5      S9$ )Nrk   z Server {} {} port {} answered {}r   r   TCPUDP      rj   z; )rb   rk   )r=   r"   r   rg   rc   rd   r   )r   r   srv_msgserrr$   s       r   rc   NoNameservers._fmt_kwargs   s    (#COO>EEc!f%(VEAAH I $ ]D5#,,TYYx5H 6 J 	Jr   rM   )rO   rP   rQ   rR   rS   r#   rU   rT   rc   rW   rX   rY   s   @r   rg   rg      s5     8C
 3s8
+Ch'KJ Jr   rg   c                       \ rS rSrSrSrg)NotAbsolute   zEAn absolute domain name is required but a relative name was provided.rM   Nr]   rM   r   r   ru   ru      s    Or   ru   c                       \ rS rSrSrSrg)	NoRootSOA   zBThere is no SOA RR at the DNS root name. This should never happen!rM   Nr]   rM   r   r   rx   rx      s    Lr   rx   c                       \ rS rSrSrSrg)NoMetaqueries   z DNS metaqueries are not allowed.rM   Nr]   rM   r   r   r{   r{      s    *r   r{   c                   B    \ rS rSrSr SS jrS rS rS rS r	S r
S	rg
)Answer   a  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.
c                    Xl         X l        X0l        X@l        SnS n[	        SS5       HC  n UR                  UR                  UX25      nUS:X  d  UR                  U:  a  UR                  n  O   Uc  U(       a	  [        US9eXl        Xpl        Uc}    UR                  UR                   UU[        R                  R"                  5      nUS:X  d  UR                  U:  a  UR                  nUS   R$                  U:  a  US   R$                  n [,        R,                  " 5       U-   U l        g ! [         a    U[        R                  R                  :w  a   UR                  UR                  UU[        R                  R                  5      n	US:X  d  U	R                  U:  a  U	R                  nU	 H  n
U
R                  n  O    GM  ! [         a    U(       a	  [        US9e Of = fU(       a	  [        US9e GM  f = f! [         a;     UR'                  5       n O+! [        R(                  R*                   a      GM0  f = ff = fGM  )Nri   r      r7   )r6   r.   r/   r7   r   
find_rrsetr-   ttlKeyErrorr(   r+   r,   r1   r_   r8   rrset	authoritySOAminimumparentr3   NoParenttime
expiration)r   r6   r.   r/   r7   raise_on_no_answermin_ttlr   countcrrsetrdsrrsets               r   __init__Answer.__init__   s   
 Ar]E6 ++HOOU,3=b=EII$7#iiG #2 =/H--#
=%001C1CU18#--:K:KMF"}

W(<"(**ay((72"()"3"3 ))+/O  6S]]000>!)!4!4X__5:5<58]]5H5H"J #b=FJJ,@&,jjG"(B$&IIE! #) !# >-"*H"== .> &"H55 &!6D    %88,,  s[   ?D-A:G? -(G<A-GG$!G<#G$$G<;G<?
I
HI :I?I  Ic                 0   US:X  a  U R                   R                  $ US:X  a  U R                   R                  $ US:X  a  U R                   R                  $ US:X  a  U R                   R                  $ US:X  a  U R                   R
                  $ [        U5      e)Nr3   r   coversr/   r.   )r   r3   r   r   r/   r.   r   )r   attrs     r   __getattr__Answer.__getattr__  s    6>::??"U]::>>!X::$$$Y::%%%X::$$$ &&r   c                 d    U R                   =(       a    [        U R                   5      =(       d    S$ )Nr   )r   r   rG   s    r   __len__Answer.__len__  s    zz-c$**o22r   c                     U R                   =(       a    [        U R                   5      =(       d    [        [        5       5      $ rN   )r   iterr   rG   s    r   __iter__Answer.__iter__  s%    zz.d4::.?$uw-?r   c                 F    U R                   c  [        eU R                   U   $ rN   r   
IndexErrorr   is     r   __getitem__Answer.__getitem__  s     ::zz!}r   c                 D    U R                   c  [        eU R                   U	 g rN   r   r   s     r   __delitem__Answer.__delitem__  s    ::JJqMr   )r8   r   r6   r/   r.   r7   r   N)T)rO   rP   rQ   rR   rS   r   r   r   r   r   r   rW   rM   r   r   r~   r~      s,      %)60p'3@
r   r~   c                   >    \ rS rSrSrS
S jrS rS rS rSS jr	S	r
g)Cachei!  z$Simple thread-safe DNS answer cache.c                     0 U l         Xl        [        R                  " 5       U R                  -   U l        [        R
                  " 5       U l        g)zV*cleaning_interval*, a ``float`` is the number of seconds between
periodic cleanings.
N)datacleaning_intervalr   next_cleaning
_threadingLocklock)r   r   s     r   r   Cache.__init__$  s8    
 	!2!YY[4+A+AAOO%	r   c                 \   [         R                   " 5       nU R                  U::  a  / nU R                  R                  5        H(  u  p4UR                  U::  d  M  UR                  U5        M*     U H  nU R                  U	 M     [         R                   " 5       nXR                  -   U l        gg)z&Clean the cache if it's time to do so.N)r   r   r   r0   r   r=   r   )r   nowkeys_to_deletekvs        r   _maybe_cleanCache._maybe_clean.  s     iik$N))//+<<3&"))!, , $IIaL $))+C!$'='=!=D %r   c                     U R                   R                  5         U R                  5         U R                  R	                  U5      nUb#  UR
                  [        R                  " 5       ::  a   U R                   R                  5         gUU R                   R                  5         $ ! U R                   R                  5         f = fzGet the answer associated with *key*.

Returns None if no answer is cached for the key.

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

Returns a ``dns.resolver.Answer`` or ``None``.
N)r   acquirer   r   r<   r   r   release)r   keyr   s      r   r<   	Cache.get<  s    	 II		c"AyALLDIIK7 II IIDIIs   A+B% 	B% %Cc                      U R                   R                  5         U R                  5         X R                  U'   U R                   R	                  5         g! U R                   R	                  5         f = fzAssociate key and value in the cache.

*key*, a ``(dns.name.Name, int, int)`` 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   r   values      r   put	Cache.putQ  sO    	 II"IIcNIIDIIs   8A A1Nc                 H    U R                   R                  5         Ub  XR                  ;   a  U R                  U	 O.0 U l        [        R                  " 5       U R                  -   U l        U R                   R                  5         g! U R                   R                  5         f = fzFlush the cache.

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

*key*, a ``(dns.name.Name, int, int)`` tuple whose values are the
query name, rdtype, and rdclass respectively.
N)r   r   r   r   r   r   r   )r   r   s     r   flushCache.flusha  ss    		 II))#		#	%)YY[43I3I%I"IIDIIs   A(B B!)r   r   r   r   )g     r@rN   )rO   rP   rQ   rR   rS   r   r   r<   r   r   rW   rM   r   r   r   r   !  s    .&> *   r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	LRUCacheNodeiw  zLRUCache node.c                 4    Xl         X l        X l        X l        g rN   )r   r   prevnextr   s      r   r   LRUCacheNode.__init__z  s    
		r   c                 ^    UR                   U l         Xl        XR                   l        Xl         g rN   r   r   r   nodes     r   link_beforeLRUCacheNode.link_before  s     II					r   c                 ^    Xl         UR                  U l        XR                  l         Xl        g rN   r   r   s     r   
link_afterLRUCacheNode.link_after  s     	II				r   c                 p    U R                   U R                  l         U R                  U R                   l        g rN   r   rG   s    r   unlinkLRUCacheNode.unlink  s     				r   )r   r   r   r   N)
rO   rP   rQ   rR   rS   r   r   r   r   rW   rM   r   r   r   r   w  s    #r   r   c                   >    \ rS rSrSrS
S jrS rS rS rSS jr	S	r
g)LRUCachei  aH  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.
c                     0 U l         U R                  U5        [        SS5      U l        [        R
                  " 5       U l        g)z\*max_size*, an ``int``, is the maximum number of nodes to cache;
it must be greater than 0.
N)r   set_max_sizer   sentinelr   r   r   r   max_sizes     r   r   LRUCache.__init__  s5    
 	(#$T40OO%	r   c                      US:  a  SnXl         g )Nr   )r   r   s     r   r   LRUCache.set_max_size  s    a<H r   c                 L    U R                   R                  5         U R                  R                  U5      nUc   U R                   R	                  5         gUR                  5         UR                  R                  [        R                  " 5       ::  a3  U R                  UR                  	  U R                   R	                  5         gUR                  U R                  5        UR                  U R                   R	                  5         $ ! U R                   R	                  5         f = fr   )r   r   r   r<   r   r   r   r   r   r   r   r   )r   r   r   s      r   r<   LRUCache.get  s    	 II99==%D| II KKMzz$$		3IIdhh' II OODMM*::IIDIIs   8D AD &D D#c                     U R                   R                  5         U R                  R                  U5      nUb'  UR	                  5         U R                  UR
                  	 [        U R                  5      U R                  :  ab  U R                  R                  nUR	                  5         U R                  UR
                  	 [        U R                  5      U R                  :  a  Mb  [        X5      nUR                  U R                  5        X0R                  U'   U R                   R                  5         g! U R                   R                  5         f = fr   )r   r   r   r<   r   r   r   r   r   r   r   r   r   )r   r   r   r   s       r   r   LRUCache.put  s    	 II99==%DIIdhh'dii.DMM1}}))IIdhh' dii.DMM1  +DOODMM*!IIcNIIDIIs   C"D5 &4D5 5ENc                     U R                   R                  5         UbF  U R                  R                  U5      nUb'  UR	                  5         U R                  UR
                  	 OYU R                  R                  nX R                  :w  a-  UR                  nSUl        SUl        UnX R                  :w  a  M-  0 U l        U R                   R                  5         g! U R                   R                  5         f = fr   )
r   r   r   r<   r   r   r   r   r   r   )r   r   r   r   s       r   r   LRUCache.flush  s    	 IIyy}}S)#KKM		$((+}}))mm+99D $DI $DID	 mm+
 	IIDIIs   B3C 7C C5)r   r   r   r   )i rN   )rO   rP   rQ   rR   rS   r   r   r<   r   r   rW   rM   r   r   r   r     s     &!
 6 2 r   r   c                      \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rSS jr\R"                  R$                  \R&                  R(                  SSSSS4S jrS\R,                  R.                  4S jrS rS rSrg)Resolveri  r   Tc                    SU l         SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l	        SU l
        SU l        SU l        SU l        SU l        SU l        SU l        U R#                  5         U(       a?  [$        R&                  S:X  a  U R)                  5         gU(       a  U R+                  U5        ggg)a  *filename*, a ``text`` 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.)
NFr   )domainnameserversnameserver_portsportsearchtimeoutlifetimekeyringkeynamekeyalgorithmedns	ednsflagspayloadcacheflagsretry_servfailrotateresetsysplatformread_registryread_resolv_conf)r   filename	configures      r   r   Resolver.__init__  s      $	 	

#

||w&""$%%h/  r   c                 2   [         R                  R                  [         R                  R                  [        R
                  " 5       5      SS 5      U l        [        U R                  5      S:X  a  [         R                  R                  U l        / U l	        0 U l
        SU l        / U l        SU l        SU l        SU l        SU l        [         R"                  R$                  U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        g)	z1Reset all resolver configuration to the defaults.r   Nr   5   g       @g      >@ri   F)r(   r3   Namer4   socketgethostnamer   r   rootr   r   r   r   r   r   r   r   tsigdefault_algorithmr   r   r   r   r   r   r  r  rG   s    r   r  Resolver.reset#  s     HHMM#((,,V-?-?-AB12FG 	t{{q ((--DK "	HH66	

#r   c                    [        U[        5      (       a   [        US5      nSnOSn U GH  n[        U5      S:X  d  US   S:X  d	  US   S:X  a  M'  UR                  5       n[        U5      S	:  a  MH  US   S
:X  a   U R                  R                  US   5        Mq  US   S:X  a)  [        R                  R                  US   5      U l        M  US   S:X  aF  USS  H;  nU R                  R                  [        R                  R                  U5      5        M=     M  US   S:X  d  M  SUSS ;   d  GM	  SU l        GM     U(       a  UR                  5         [        U R                  5      S:X  a  U R                  R                  S5        gg! [         a    S/U l         gf = f! U(       a  UR                  5         f f = f)zProcess *f* as a file in the /etc/resolv.conf format.  If f is
a ``text``, it is used as the name of the file to open; otherwise it
is treated as the file itself.r	127.0.0.1NTFr   #;ro   
nameserverr   r   r   optionsr  )r   r   openIOErrorr   r   splitr=   r(   r3   r4   r   r   r  close)r   f
want_closeltokenssuffixs         r   r  Resolver.read_resolv_conf;  s   
 a&&CL JJ	q6Q;!A$#+1 v;?!9,$$++F1I6AY(*"%(("4"4VAY"?DKAY(*"(***388+=+=f+EF #-AY)+6!":-&*% ( 	t A%##K0 &?   %0= 	: 	 s)   F C;F% (F% 4F% F"!F"%F?c                 n    UR                  S5      S:  a  SnU$ UR                  S5      S:  a  SnU$ SnU$ )N r   ,)find)r   entry
split_chars      r   _determine_split_charResolver._determine_split_chare  sM     ::c?aJ  ZZ_!J  Jr   c                     [        U5      nU R                  U5      nUR                  U5      nU H/  nX@R                  ;  d  M  U R                  R	                  U5        M1     g rN   )r!   r+  r  r   r=   )r   r   r*  ns_listnss        r   _config_win32_nameservers"Resolver._config_win32_nameserverst  sV    +&//<
##J/B)))  ''+ r   c                 ^    [         R                  R                  [        U5      5      U l        g rN   )r(   r3   r4   r!   r   )r   r   s     r   _config_win32_domainResolver._config_win32_domain}  s    hh((V5r   c                    [        U5      nU R                  U5      nUR                  U5      nU HL  nX@R                  ;  d  M  U R                  R	                  [
        R                  R                  U5      5        MN     g rN   )r!   r+  r  r   r=   r(   r3   r4   )r   r   r*  search_listss        r   _config_win32_searchResolver._config_win32_search  s^    V//7
ll:.A#""388#5#5a#89 r   c                     [         R                  " US5      u  p4U(       a  U R                  U5        U(       d  U(       a3   [         R                  " US5      u  pTU(       a  U R	                  U5        Od [         R                  " US5      u  p4U(       aC  U R                  U5         [         R                  " US5      u  pTU(       a  U R	                  U5         [         R                  " US5      u  pdU(       a  U R                  U5        g g ! [         a    S n Nf = f! [         a     NRf = f! [         a    S n Nf = f! [         a     Ntf = f! [         a    S n Nlf = f)N
NameServerDomainDhcpNameServer
DhcpDomain
SearchList)_winregQueryValueExWindowsErrorr0  r3  r8  )r   r   always_try_domainserversrtypedomr   s          r   _config_win32_fromkeyResolver._config_win32_fromkey  sM   	$11#|DNG **73'$11#x@
--c2!(!5!5c;K!L ..w7!(!5!5c<!HJC11#6	#00lCMF %%f- 9  	G	   
    $   	F	sY   D 1D 5D. '1E  E DD
D+*D+.D=<D= 
EEEEc                 J   [         R                  " S[         R                  5      nSn  [         R                  " US5      nSn U R                  US5        UR                  5         U(       a  [         R                  " US5      n Sn  [         R                  " XE5      nUS-  n[         R                  " XF5      nU R                  XU5      (       d  ML   U R                  US5        UR                  5         Mp  UR                  5         g! [         a    [         R                  " US5      n Nf = f! UR                  5         f = f! UR                  5         f = f! [         a     Of = fUR                  5         N! UR                  5         f = f! UR                  5         f = f)	z9Extract resolver configuration from the Windows registry.NFz2SYSTEM\CurrentControlSet\Services\Tcpip\ParametersTz+SYSTEM\CurrentControlSet\Services\VxD\MSTCPz=SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfacesr   r   )	r@  ConnectRegistryHKEY_LOCAL_MACHINEOpenKeyEnvironmentErrorrG  CloseEnumKey_win32_is_nic_enabled)r   lm	want_scan
tcp_params
interfacesr   guidr   s           r   r  Resolver.read_registry  sz    $$T7+E+EF	'	
E$__R.KL
 !	#**:t<  "$__R.<=
'A"#*??:#ADFA")//*"CC#'#=#=b#L#L (, $ : :3 F #		   HHJA $ E$__R.DE
E   "$ !$		/ "!" $$&J$$&HHJs   D	 D0 .F E; 	AE E; E &E 6E; 	!D-*F ,D--F 0EF EE 
E'$E; &E''E; *F ;FF F"c                 n    [         R                  " USU-  5      n [         R                  " US5      u  pVU[         R                  :w  a  [        e[         R                  " USU-  5      n [         R                  " US5      u  pU[         R
                  :w  a  [        eUS-  (       + UR                  5         UR                  5         $ ! UR                  5         f = f! UR                  5         f = f! [        [        4 a2     [         R                  " US5      u  pU	S Ls $ ! [         a      gf = ff = f)Nz]SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%s\ConnectionPnpInstanceIDz SYSTEM\CurrentControlSet\Enum\%sConfigFlagsr   NTEContextListF)	r@  rL  rA  REG_SZ
ValueError	REG_DWORDrN  rM  rB  )
r   rQ  rU  interface_keyconnection_keypnp_idttype
device_keyr   ntes
             r   rP  Resolver._win32_is_nic_enabled  s1   /	 %__"$()*N'")"6"6"O#5 GNN*$$$__;fDF
'%,%9%9"M&3NU  1 11((  %s{? $$&$$& $$&$$& *- 	&33M4D F$& 	s_   C2 AC +<C 'C 7C2 CC C//C2 2D4D"D4"
D0,D4/D00D4Nc                     Uc  U R                   OUn[        R                  " 5       nX1-
  nUS:  a  US:  a	  [        US9eUnXB:  a	  [        US9e[        X$-
  U R                  5      $ )Nr   ri   )r   )r   r   Timeoutminr   )r   startr   r   durations        r   _compute_timeoutResolver._compute_timeout  si    $,$44==(iik;a<"}h//
 (++8&55r   Fr   c	                    [        U[        5      (       a   [        R                  R	                  US5      n[        U[        5      (       a  [        R
                  R	                  U5      n[        R
                  R                  U5      (       a  [        e[        U[        5      (       a  [        R                  R	                  U5      n[        R                  R                  U5      (       a  [        e/ n	UR                  5       (       a  U	R                  U5        O[        U5      S:  a8  U	R                  UR                  [        R                  R                  5      5        U R                  (       a4  U R                   H#  n
U	R                  UR                  U
5      5        M%     O*U	R                  UR                  U R                   5      5        Sn0 n["        R"                  " 5       nSnU	 GH  nU R$                  (       aK  U R$                  R'                  XU45      nUb+  UR(                  c  U(       a  [+        UR,                  S9eUs  $ [        R.                  R1                  XU5      nU R2                  b/  UR5                  U R6                  U R2                  U R8                  S9  UR;                  U R<                  U R>                  U R@                  5        U RB                  b  U RB                  Ul!        SnU RD                  SS n/ nU RF                  (       a  [H        RJ                  " U5        SnUGcb  [        U5      S:X  a
  [M        UUS9eUSS  GH  nU RO                  X5      nU RP                  R'                  UU RR                  5      n UnU(       a#  [        RT                  RW                  UUUUUUS	9nO[        RT                  RY                  UUUUUUS	9nURB                  [        RB                  RZ                  -  (       a5  SnU RO                  X5      n[        RT                  RW                  UUUUUUS	9nURm                  5       nU[        Rl                  Rn                  :X  a"  [o        5       nUR                  UUUUU45        UeU[        Rl                  Rp                  :X  d  U[        Rl                  Rr                  :X  a    OzU[        Rl                  Rt                  :w  d  U Rv                  (       d  URi                  U5        UR                  UUU[        Rl                  Ry                  U5      U45        SnGM     Ub  OM[        U5      S:  a8  U RO                  X5      n[{        UU5      nUS
-  n["        R|                  " U5        Uc  GMb  URm                  5       [        Rl                  Rr                  :X  a  UX'   GM  Sn  O   U(       a	  [s        XS9e[        XUWU5      nU R$                  (       a  U R$                  R                  XU4U5        U$ ! [\        R^                  [        R`                  Rb                  4 a$  nUR                  UWUUU45        Sn SnAGM  SnAf[        RT                  Rd                   a$  nUR                  UWUUU45        Sn SnAGMY  SnAf[        R`                  Rf                   a5  nURi                  U5        UR                  UWUUU45        Sn SnAGM  SnAf[j         a5  nURi                  U5        UR                  UWUUU45        Sn SnAGM  SnAff = f)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 ``text``, the query name.

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

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

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

*source*, a ``text`` 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 long query should run before timing out.

Raises ``dns.exception.Timeout`` 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.
Nr   Tr   )	algorithmg?r   )rj   rk   )sourcesource_portro   Fr   )Ar   r   r(   r3   r4   r+   is_metatyper{   r)   is_metaclassis_absoluter=   r   concatenater  r   r   r   r   r<   r   r_   r7   message
make_queryr   use_tsigr   r   use_ednsr   r   r   r   r   r  randomshufflerg   rj  r   r   rb   tcpudpTCr  error	exceptionrf  UnexpectedSource	FormErrorremoveEOFErrorrcoder[   NOERRORr	   SERVFAILr  r2   rg  sleepr~   r   )r   r6   r.   r/   rz  rn  r   ro  r   qnames_to_tryr#  all_nxdomainnxdomain_responsesrh  _qnamer-   rj   r7   r   rk   backoffr  r   r   tcp_attemptexr  
sleep_times                               r   rb   Resolver.query"  s   Z e\**HH&&ud3Efl++]],,V4F==$$V,,g|,,nn..w7G>>&&w//  '5zA~$$U%6%6sxx}}%EF{{"kkF!(():):6)BC * $$U%6%6t{{%CD		#Fzz(AB%||+0B&@@%kk,,VWEG||'  t||+/+<+< ! >TYYEzz% $

H **1-KF{{{+G"{#q('GG"-a.J"33EDG0044ZKD<!&)'*yy}}Wj5<d<BAL (5 (NH
 (+yy}}Wj5<d<BAL (5 (NH  (~~		<.2*.*?*?*P$'IIMM':2949?>I %2 %K !)Z %NN,E		 2 22%Zz;b'/'1 2 		 1 11!SYY%7%77 		 2 22$:M:M#**:6MM:{D#&99#4#4U#;X#G H#He #1f ' {#a'
 #33EDG!$Wg!6JqLGJJz*G "H ~~399#5#55-5"* LA $B -NN*,::JJNNFG4f=i #LL#--*?*?@ !
 z;b'/'1 2#' 9955 ! z;b'/'1 2#' ==22 
! $**:6z;b'/'1 2#' # ! $**:6z;b'/'1 2#' !sC   +X#?BX##.]Y00!]Z00!])\])\>>]c                     Xl         Uc,  [        U R                   R                  5       5      S   U l        OX l        X0l        g)a  Add a TSIG signature to the query.

See the documentation of the Message class for a complete
description of the keyring dictionary.

*keyring*, a ``dict``, the TSIG keyring to use.  If a
*keyring* is specified but a *keyname* is not, then the key
used will be the first key in the *keyring*.  Note that the
order of keys in a dictionary is not defined, so applications
should supply a keyname when a keyring is used, unless they
know the keyring contains only one key.

*keyname*, a ``dns.name.Name`` or ``None``, the name of the TSIG key
to use; defaults to ``None``. The key must be defined in the keyring.

*algorithm*, a ``dns.name.Name``, the TSIG algorithm to use.
Nr   )r   r   keysr   r   )r   r   r   rm  s       r   rv  Resolver.use_tsig  s7    ( ? 1 1 34Q7DL"L%r   c                 2    Uc  SnXl         X l        X0l        g)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.
Nri   )r   r   r   )r   r   r   r   s       r   rw  Resolver.use_edns  s     <D	"r   c                     Xl         g)z[Overrides the default flags with your own.

*flags*, an ``int``, the message flags to use.
N)r   )r   r   s     r   	set_flagsResolver.set_flags!  s	     
r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   )z/etc/resolv.confTrN   )rO   rP   rQ   rR   rS   r   r  r  r+  r0  r3  r8  rG  r  rP  rj  r(   r+   Ar)   r*   rb   r  r  rv  rw  r  rW   rM   r   r   r   r     s    #0J0(1T,6: .D,\5n6" #&--//3>>;L;L1M^ )-8855&6*r   r   c                  0    [         c
  [        5         [         $ )z7Get the default resolver, initializing it if necessary.)default_resolverreset_default_resolverrM   r   r   get_default_resolverr  .  s     r   c                      [        5       qg)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  rM   r   r   r  r  5  s      zr   FTc           
      <    [        5       R                  XX#UXVU5      $ )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.query`` for more information on the
parameters.
)r  rb   )r6   r.   r/   rz  rn  r   ro  r   s           r   rb   rb   @  s&      !''wV(:(02 2r   c                 |   [        U [        5      (       a8  [        R                  R	                  U [        R                  R
                  5      n Uc
  [        5       nU R                  5       (       d  [        U 5      e  UR                  U [        R                  R                  X5      nUR                  R                  U :X  a  U $   U R!                  5       n M\  ! [        R                  R                  [        R                  R                  4 a     NMf = f! [        R                  R"                   a    [$        ef = f)a;  Find the name of the zone which contains the specified name.

*name*, an absolute ``dns.name.Name`` or ``text``, 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 resolver is used.

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

Returns a ``dns.name.Name``.
)r   r   r(   r3   r4   r  r  rr  ru   rb   r+   r   r   resolverr	   r_   r   r   rx   )r3   r/   rz  r  r-   s        r   zone_for_namer  Q  s    & $%%xx!!$6')$
	^^D#--*;*;WJF||  D( )
	;;=D  %%s||'<'<= 		 xx   	O	s   =AC D 8DD%D;c                 
   U[         R                  [         R                  -  -  S:w  a  [        eU c'  Uc$  [         R                  " [         R
                  5      e/ n/ nS n U c_  SnU[         R                  -  S:w  a#  UR                  S5        UR                  S5        O~UR                  S5        UR                  S5        O[U R                  S5      n	[        U	5      S:X  a  U	S   n
OU n
[        R                  R                  U
5      nUR                  U 5        U n S n Uc  SnO[A        U5      n Uc$  [         R                  " [         R
                  5      e/ nUS:X  a!  [         RF                  [         RH                  /nOU/nU[         RJ                  -  S:w  a  UnOSnU[         R                   :X  d  U[         R"                  :X  aH  U HB  nU H9  n[L        U    H)  nUR                  [         R                   X4UXSS445        M+     M;     MD     U[         R6                  :X  d  U[         R"                  :X  aF  U H@  nU H7  n[L        U    H'  nUR                  [         R6                  X4UX445        M)     M9     MB     [        U5      S:X  a$  [         R                  " [         R
                  5      eU$ ! [         GaH     [        R                  R                  U 5      nUR                  U 5        U n GN! [         Ga    U[         R                  -  S:X  Ga   U[         R                   :X  d  U[         R"                  :X  a  [$        R'                  U [        R(                  R*                  S	S
9nUR,                  n UR.                  R1                  S5      nUR2                  b.  UR2                   H  nUR                  UR4                  5        M      U[         R6                  :X  d  U[         R"                  :X  a  [$        R'                  U [        R(                  R8                  S	S
9nUR,                  n UR.                  R1                  S5      nUR2                  b.  UR2                   H  nUR                  UR4                  5        M        GNn! [        R:                  R<                   a%    [         R                  " [         R
                  5      e[         a%    [         R                  " [         R>                  5      ef = f  GNf = ff = f! [         aG    U[         RB                  -  S:X  a,   [         RD                  " U5      n GN! [         a      GN!f = f GN(f = f)Nr   	localhostz::z0.0.0.0z::1r  %ro   F)r   T )'r  AI_ADDRCONFIGAI_V4MAPPEDNotImplementedErrorgaierror
EAI_NONAME
AI_PASSIVEr=   r  r   r(   ipv6	inet_aton	Exceptionipv4AI_NUMERICHOSTAF_INET6	AF_UNSPEC	_resolverrb   r+   AAAAr6   r8   r2   r   addressAF_INETr  r  r	   
EAI_SYSTEMintAI_NUMERICSERVgetservbyname
SOCK_DGRAMSOCK_STREAMAI_CANONNAME_protocols_for_socktype)hostservicefamilysocktypeprotor   v6addrsv4addrsr8   partsahostaddrv6rdatav4r   tuples	socktypesr5   s                      r   _getaddrinfor    sf   $$v'9'99:a?!!|oof//00GGN1=<(Nv(((A-t$y)u%{+JJsOE5zQa88%%e,DNN4 !N@ D?Dw<D |oof//00F1}&&(:(:;	J	v"""a' Ff.>.>$>D%4X>EMM6??H#(4q!*<#> ? ? & 
 6V-=-=#=D%4X>EMM6>>8#(4,#8 9 ? & 
 6{aoof//00MK  =	=88%%d+DNN4 !N 	=v,,,1=0Ff>N>N4N&__T3==3E3E@E - G  "xx)+):):)B)B4)H88/)+ 'u}} = *2/6V=M=M3M&__T3==??@E - G!xx)+):):)B)B4)H88/)+ 'u}} = *2||,, = //&*;*;<<  = //&*;*;<<=- 2	==L  6(((A-++G4  .s    >J4 "J4 AJ4  T
 &T
 4T 2K55#TE.RTA0S;;T>TTT
!U,U
UUUUUc                 *   U S   nU S   n[        U 5      S:X  a  U S   n[        R                  nOS n[        R                  n[	        X#U[        R
                  [        R                  S5      n[        U5      S:  a  [        R                  " S5      eUS   S   S   nU[        R                  -  (       a  SnOSn[        R                  R                  U5      n	U[        R                  -  S:X  a@   [        R                  U	S5      n
U
R                  S   R                   R#                  S	5      nOUnUb  US
[1        U5      -   -  nU[        R2                  -  (       a  [1        U5      nX4$ [        R4                  " X85      nX4$ ! [        R$                  R&                  [        R$                  R(                  4 aU    U[        R*                  -  (       a$  [        R,                  " [        R.                  5      eUnUb  US
[1        U5      -   -  n Nf = f)Nr   r      rp   z'sockaddr resolved to multiple addressesr{  rz  PTRTr  )r   r  r  r  r  r  SOL_TCPr}  NI_DGRAMr(   reversenamefrom_addressNI_NUMERICHOSTr  rb   r   r1   r2   r  r	   r_   NI_NAMEREQDr  r  r!   NI_NUMERICSERVgetservbyport)sockaddrr   r  r   scoper  r  r  pnamer6   r-   hostnamer  s                r   _getnameinfor    s   A;DA;D
8}$ff.@.@ ..!-F
6{QllDEE!9Q<?DvOO((.Ev$$$)	-__UE2F||A--55d;H c%j((Hv$$$d)  &&t3 %%s||'<'<= 	-v)))oof&7&788H C#e*,,	-s   1>F B
HHc                     U c  [         R                  " 5       n  [        [        U S5      S   S   5      S   $ ! [         a    U s $ f = f)NP   r   r  )r  r  r  r  r  r3   s    r   _getfqdnr    sO    |!!#Lr215a89!<< s   8 AAc                 $    [        U 5      S   S   $ )Nro   r   )_gethostbyname_exr  s    r   _gethostbynamer    s    T"1%a((r   c                     / n/ n[        U S[        R                  [        R                  [        R                  [        R
                  5      nUS   S   nU H  nUR                  US   S   5        M     XAU4$ )Nr   rp   r  )r  r  r  r  r  r  r=   )r3   aliases	addressesr  	canonicalitems         r   r  r  #  sq    GI$6>>63E3E ..&*=*=?Fq	!Ia$  	**r   c                     [         R                  R                  U 5        U SSS4n[        R                  n[        U[        R                  5      u  p4/ n/ n[        USU[        R                  [        R                  [        R                  5      nUS   S   nU H  n	UR                  U	S   S   5        M     XU4$ ! [
         a    U S4n[        R                  n Nf = f)Nr  r   rp   r  )r(   r  r  r  r  r  r  r  r  r  r  r  r  r=   )
ipr  r  r3   r   r  r  r  r  r  s
             r   _gethostbyaddrr  /  s     2Aq>  &*<*<=LTGI$66+=+=v~~ --/Fq	!Ia$  	**   8 s   5B= =CCc                     U c
  [        5       n U q[        [        l        [
        [        l        [        [        l        [        [        l
        [        [        l        [        [        l        g)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  C  sF     ')I%F%FFN)F/F)Fr   c                      Sq [        [        l        [        [        l        [        [        l        [        [        l	        [        [        l        [        [        l        g)z5Undo the effects of prior override_system_resolver().N)r  _original_getaddrinfor  r  _original_getnameinfor  _original_getfqdnr  _original_gethostbynamer  _original_gethostbyname_exr  _original_gethostbyaddrr  rM   r   r   restore_system_resolverr  ]  s8     I.F.F&FN2F8F2Fr   )r   rN   )PrS   r  r  r   rx  	threadingr   ImportErrordummy_threadingdns.exceptionr(   	dns.flagsdns.ipv4dns.ipv6dns.messagedns.name	dns.query	dns.rcodedns.rdataclassdns.rdatatypedns.reversenamedns.tsig_compatr   r   r  winregr@  r~  DNSExceptionr	   r[   rf  r_   rg   ru   rx   r{   objectr~   r   r   r   r   r  r  r  r+   r  r)   r*   rb   r  r  SOL_UDPr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rM   r   r   <module>r     s  $   
  )"             )<<7 N/s}})) N/bCs}})) C --

/s}})) /JCMM.. J,P#--,, PM** M+CMM.. +dV dNS F S l#6 #4g v g Tlv l`  " 1B1BDT$2" !$ 1 1ut $X '
( 
 	** ** NN  .. #44  ..  D1A1AAaH%P)	++(*4
3E*  )()(  s#   J !J 
JJ
J-,J-