a MeP@sUdZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zej%dkrddl&ZGdddej'j(Z)Gdd d ej'j(Z*ee e+e,e-ee.e+fe ej/j0fZ1e e1e e+d d d Z2Gd ddej'j3Z4e4Z3Gdddej'j(Z5Gdddej'j(Z6Gdddej'j(Z7Gdddej'j(Z8Gdddej'j(Z9Gdddej'j(Z:GdddZ;Gddde<Z=Gdd d e=Z>Gd!d"d"Z?Gd#d$d$Z@eejAjBejCjDejEjFfZGGd%d&d&e@ZHGd'd(d(ZIGd)d*d*e@ZJGd+d,d,ZKGd-d.d.ZLGd/d0d0eLZMdaNe eMeOd1<eMd2d3d4ZPdd2d5d6ZQejCjRejEjSd7dd8dddfeejAjBe+feejCjDe+feejEjFe+fe,e e+e,e-e eTe e,e;d9 d:d;ZUejCjRejEjSd7dd8ddfeejAjBe+feejCjDe+feejEjFe+fe,e e+e,e-e eTe;d< d=d>ZVe+e e e;d?d@dAZWejXfeejAjBe+fe-e e>dBdCdDZYeejAjBe+fejAjBdEdFdGZZdgeTddIdJdKZ[ejEjSd7ddfeejAjBe+fejEjFe,e eMe eTejAjBdLdMdNZ\dOejXdfeejAjBe+fe-e-e eMeMdPdQdRZ]ejCjRejEjSd7dd8ddddOejXdf eejAjBe+feejAjBe+feejCjDe+feejEjFe+fe,e e+e,e-e eTe e,e-e-e eMe;dSdTdUZ^ej_ej`gejaejbgiZcdadejeZfejgZhejiZjejkZlejmZnejoZpddejXdddfdVdWZqdhdXdYZrdidZd[Zsd\d]Ztd^d_Zud`daZvdje eMddbdcddZwdd2dedfZxdS)kDNS stub resolver.N)AnyDictIteratorListOptionalSequenceTupleUnion)urlparsewin32csteZdZdZddhZdZfddZdddZed fd d Z e d d Z ddZ ddZ ddZddZZS)NXDOMAINz"The DNS query name does not exist.qnames responsesNcstj|i|dSNsuper__init__selfargskwargs __class__0/usr/lib/python3.9/site-packages/dns/resolver.pyr>szNXDOMAIN.__init__cCs\t|tttfstdt|dkr,td|dur:i}nt|tsLtdt||d}|S)Nz#qnames must be a list, tuple or setrz(qnames must contain at least one elementz(responses must be a dict(qname=response)rr) isinstancelisttuplesetAttributeErrorlendict)rrrrrrr _check_kwargsAs   zNXDOMAIN._check_kwargsreturncsPd|jvrtS|jd}t|dkr0d}nd}dtt|}d||S)NrzNone of DNS query names existz!The DNS query name does not existz, z{}: {})rr__str__r"joinmapstrformat)rrmsgrrrr(Ms    zNXDOMAIN.__str__c Cspd|jvrtd|jdD]D}|jd|}z|}||krJ|WSWqty^Yq0q|jddS)z%Return the unresolved canonical name.rzparametrized exception requiredrr)r TypeErrorcanonical_name Exception)rqnameresponsecnamerrrr/Xs  zNXDOMAIN.canonical_namecCsxt|jdg}t|jdi}|jdi}|jdgD]*}||vrV||||vr@||||<q@t||dS)z3Augment by results from another NXDOMAIN exception.rrr)rrgetr#appendr )rZe_nxZqnames0Z responses0Z responses1Zqname1rrr__add__is zNXDOMAIN.__add__cCs |jdS)zXAll of the names that were tried. Returns a list of ``dns.name.Name``. rrrrrrruszNXDOMAIN.qnamescCs |jdS)zA map from queried names to their NXDOMAIN responses. Returns a dict mapping a ``dns.name.Name`` to a ``dns.message.Message``. rr7r8rrrr|szNXDOMAIN.responsescCs|jd|S)zTThe response for query *qname*. Returns a ``dns.message.Message``. rr7)rr1rrrr2szNXDOMAIN.response)N)__name__ __module__ __qualname____doc__ supp_kwargsfmtrr$r+r(propertyr/r6rrr2 __classcell__rrrrr 4s     r c@seZdZdZdS)YXDOMAINz8The DNS query name is too long after DNAME substitution.Nr9r:r;r<rrrrrAsrA)errorsr&cCs,g}|D]}|d|d|dq|S)z3Turn a resolution errors trace into a list of text.zServer {} answered {}r)r5r,)rCZtextserrrrr_errors_to_textsrFcsHeZdZdZdZdeddZddhZfddZfd d ZZ S) LifetimeTimeoutz The resolution lifetime expired.z(%s after {timeout:.3f} seconds: {errors}NtimeoutrCcstj|i|dSrrrrrrrszLifetimeTimeout.__init__c s&t|d}tj|dd|dS)NrCrI; rIrC)rFr _fmt_kwargsr)rrZsrv_msgsrrrrLs zLifetimeTimeout._fmt_kwargs r9r:r;r<r-r>r=rrLr@rrrrrGs  rGcs>eZdZdZdZdhZfddZfddZdd ZZ S) NoAnswerzr=rrLr2r@rrrrrOs   rOcsHeZdZdZdZdeddZddhZfdd Zfd d ZZ 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.z%s {query}: {errors}NrHrequestrCcstj|i|dSrrrrrrrszNoNameservers.__init__c s(t|d}tj|djd|dS)NrCrSrJ)rPrC)rFrrLrQr)rMrrrrLs zNoNameservers._fmt_kwargsrNrrrrrRs  rRc@seZdZdZdS) NotAbsolutezEAn absolute domain name is required but a relative name was provided.NrBrrrrrTsrTc@seZdZdZdS) NoRootSOAzBThere is no SOA RR at the DNS root name. This should never happen!NrBrrrrrUsrUc@seZdZdZdS) NoMetaqueriesz DNS metaqueries are not allowed.NrBrrrrrVsrVc@seZdZdZdS)NoResolverConfigurationzEResolver configuration could not be read or specified no nameservers.NrBrrrrrWsrWc @sreZdZdZdejjejjej j ej j e ee eddddZddZedd d Zd d Zd dZddZdS)Answera&DNS stub resolver answer. Instances of this class bundle up the result of a successful DNS resolution. For convenience, the answer object implements much of the sequence protocol, forwarding to its ``rrset`` attribute. E.g. ``for a in answer`` is equivalent to ``for a in answer.rrset``. ``answer[i]`` is equivalent to ``answer.rrset[i]``, and ``answer[i:j]`` is equivalent to ``answer.rrset[i:j]``. Note that CNAMEs or DNAMEs in the response may mean that answer RRset's name might not be the query name. N)r1rdtyperdclassr2 nameserverportr&cCsX||_||_||_||_||_||_||_|jj|_|jj |_ t |jj |_ dSr)r1rYrZr2r[r\Zresolve_chainingZchaining_resultr/answerrrsettimeZ minimum_ttl expiration)rr1rYrZr2r[r\rrrrs    zAnswer.__init__cCs\|dkr|jjS|dkr |jjS|dkr0|jjS|dkr@|jjS|dkrP|jjSt|dS)NnamettlcoversrZrY)r^rarbrcrZrYr!)rattrrrr __getattr__szAnswer.__getattr__r%cCs|jrt|jpdSNr)r^r"r8rrr__len__)szAnswer.__len__cCs|jrt|jpttSr)r^iterrr8rrr__iter__,szAnswer.__iter__cCs|jdurt|j|Srr^ IndexErrorrirrr __getitem__/s zAnswer.__getitem__cCs|jdurt|j|=dSrrjrlrrr __delitem__4s zAnswer.__delitem__)NN)r9r:r;r<dnsraName rdatatype RdataType rdataclass RdataClassmessage QueryMessagerr+intrrergrirnrorrrrrXs" rXc@seZdZdZdS)Answersz5A dict of DNS stub resolver answers, indexed by type.NrBrrrrry:sryc@seZdZdZedeeeeeddddZe j fe e e ee fddd Ze j fe e edd d Zejjd d dZdS) HostAnswerszTA dict of DNS stub resolver answers to a host name lookup, indexed by type. NT)v6v4 add_emptyr&cCsFt}|dur$|s|jr$||tjj<|durB|s6|jrB||tjj<|Sr)rzr^rprrAAAAA)clsr{r|r}answersrrrmakeCs   zHostAnswers.make)familyr&ccs|tjkr2|tjEdH|tjEdHdS|tjkrL|tjj}n(|tjkrf|tjj }nt d||r|D]}|j |fVq|dS)Nunknown address family ) socket AF_UNSPECaddresses_and_familiesAF_INET6AF_INETr4rprrr~rNotImplementedErroraddress)rrr]ZrdatarrrrSs   z"HostAnswers.addresses_and_familiescCsdd||DS)Ncss|]}|dVqdS)rNr).0Zpairrrr gz(HostAnswers.addresses..)r)rrrrr addressesfszHostAnswers.addressesr%cCs |tjj|tjj}|jSr)r4rprrr~rr/)rr]rrrr/jszHostAnswers.canonical_name)NNT)r9r:r;r< classmethodrrXboolrrrrxrr r+rrrprarqr/rrrrrz>s$ rzc@s@eZdZdZd eeddddZdddd Zddd d ZdS) CacheStatisticszCache StatisticsrN)hitsmissesr&cCs||_||_dSrrr)rrrrrrrrszCacheStatistics.__init__r%cCsd|_d|_dSrfrr8rrrresetvszCacheStatistics.resetcCst|j|jSr)rrrr8rrrclonezszCacheStatistics.clone)rr)r9r:r;r<rxrrrrrrrrosrc@sReZdZddddZddddZedddZedd d Zedd d Z dS) CacheBaseNr%cCst|_t|_dSr) threadingLocklockr statisticsr8rrrrs zCacheBase.__init__cCs4|j|jWdn1s&0YdS)zReset all statistics to zero.N)rrrr8rrrreset_statisticsszCacheBase.reset_statisticscCs2|j|jjWdS1s$0YdS)z How many hits has the cache had?N)rrrr8rrrrszCacheBase.hitscCs2|j|jjWdS1s$0YdS)z"How many misses has the cache had?N)rrrr8rrrrszCacheBase.missescCs4|j|jWdS1s&0YdS)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)rrrr8rrrget_statistics_snapshotsz!CacheBase.get_statistics_snapshot) r9r:r;rrrxrrrrrrrrr~s rcsteZdZdZdeddfdd Zdddd Zeee d d d Z ee dd ddZ deedd ddZ Z S)Cachez$Simple thread-safe DNS answer cache.r@N)cleaning_intervalr&cs*ti|_||_t|j|_dS)zf*cleaning_interval*, a ``float`` is the number of seconds between periodic cleanings. N)rrdatarr_ next_cleaning)rrrrrrs zCache.__init__r%cCsht}|j|krdg}|jD]\}}|j|kr ||q |D] }|j|=qBt}||j|_dS)z&Clean the cache if it's time to do so.N)r_rritemsr`r5r)rnowZkeys_to_deletekvrrr _maybe_cleans    zCache._maybe_cleankeyr&cCs|jn||j|}|dus2|jtkrR|jjd7_WddS|jjd7_|WdS1sz0YdSaKGet 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') rrrr4r`r_rrr)rrrrrrr4s  z Cache.getrvaluer&cCs<|j"|||j|<Wdn1s.0YdSaAssociate 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)rrrrrrrrrputs z Cache.putcCs\|jB|dur$||jvr:|j|=ni|_t|j|_Wdn1sN0YdSa2Flush 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)rrr_rr)rrrrrflushs   z Cache.flush)r)N)r9r:r;r<floatrrCacheKeyrrXr4rrr@rrrrrs   rc@s6eZdZdZddZdddddZddd d ZdS) LRUCacheNodezLRUCache node.cCs"||_||_d|_||_||_dSrf)rrrprevnextrrrrrs zLRUCacheNode.__init__N)noder&cCs ||_|j|_||j_||_dSrrr)rrrrr link_afterszLRUCacheNode.link_afterr%cCs|j|j_|j|j_dSrrr8rrrunlinks zLRUCacheNode.unlink)r9r:r;r<rrrrrrrrsrcseZdZdZdeddfdd ZeddddZeee d d d Z eed d d Z ee ddddZ deedd ddZ ZS)LRUCachea`Thread-safe, bounded, least-recently-used DNS answer cache. This cache is better than the simple cache (above) if you're running a web crawler or other process that does a lot of resolutions. The LRUCache has a maximum number of nodes, and when it is full, the least-recently used node is removed to make space for a new one. 順N)max_sizer&cs>ti|_||tdd|_|j|j_|j|j_dS)zl*max_size*, an ``int``, is the maximum number of nodes to cache; it must be greater than 0. N)rrr set_max_sizersentinelrrrrrrrrs     zLRUCache.__init__cCs|dkr d}||_dS)Nr')rrrrrrszLRUCache.set_max_sizercCs|j|j|}|dur<|jjd7_WddS||jjtkr~|j|j =|jjd7_WddS| |j |jj d7_ |j d7_ |jWdS1s0YdSr) rrr4rrrrr`r_rrrrrrrrrrr4s    z LRUCache.getcCsr|jX|j|}|dus,|jjtkrz t|}WqHty:td|YqH0n t|}|}|D]~}t|dksT|ddksT|ddkrqT|}t|dkrqT|ddkr| |dqT|ddkrt j |d|_ g|_qT|dd krg|_|dd D]}|j t j |qqT|dd krT|dd D]}|d krBd |_n|dkrV|nzd|vrzt|dd|_WnttfyYn0n|dus|durd}n |dur"d}||_||_||_||_dS)aConfigure 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. NFrHTr)rrrr)rrrrrrrrroszBaseResolver.use_edns)rr&cCs ||_dS)zkOverrides the default flags with your own. *flags*, an ``int``, the message flags to use. N)r)rrrrr set_flagsszBaseResolver.set_flags)rr default_portr&c Csg}t|tr|D]}t|tjjr*|}nntj|rR|||}tj||}nFzt |j dkrft Wn"t yt d|dYn0tj|}||qnt dt||S)Nhttpsz 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 {}))rrrpr[rinet is_addressr4Do53Nameserverr schemerr0rZ DoHNameserverr5r,type)rrrr!Zenriched_nameserversr[Zenriched_nameserverr\rrrrs2      z BaseResolver._enrich_nameserverscCs|jSr)rr8rrrrszBaseResolver.nameservers)rr&cCs|||j|j||_dS)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)rrr\r)rrrrrrs )rT)NN))r9r:r;r<rprarq__annotations__rr+rxrrrrrr rZOptionrr[rrrrr ErrorTuplerrr r rrvZDEFAULT_EDNS_PAYLOADrr rrr?rsetterrrrrrs      G    ,  !  %rc @sHeZdZdZejjejjddddddfe ej j e fe ejj e fe ejje feee eeeeeeed ddZejjejjdddddfe ej j e fe ejj e fe ejje feee eeeeed d d Ze eeed d dZejfe ej j e feeedddZe ej j e fej j dddZdeddddZdS)ResolverrFNTr r1rYrZrsourcer source_portrrr&c  Cst||||||| } t} | \} } | dur4| Sd}|s| \}}}|rXt||| || j}z|j| ||||d}Wn@ty}z(| d|\}}WYd}~q8WYd}~n d}~00| |d\} }| dur8| Sq8qdS)aQuery 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)rIr-r.r) rr_rrsleeprrCrPr0r)rr1rYrZrr-rr.rrZ resolutionrrSr]Zdoner[rrIr2r_rrrresolves6?   "zResolver.resolve r1rYrZrr-rr.rr&c Cs*tjdtdd|||||||||d S)a$Query nameservers to find the answer to the question. This method calls resolve() with ``search=True``, and is provided for backwards compatibility with prior versions of dnspython. See the documentation for the resolve() method for further details. z2please use dns.resolver.Resolver.resolve() insteadr stacklevelTwarningswarnDeprecationWarningr1) rr1rYrZrr-rr.rrrrrP=s zResolver.queryipaddrrrr&cOsFi}||tjj|d<tjj|d<|jtj|g|Ri|S)aUse 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. rYrZ) updaterprrPTRrtrr1 reversename from_address)rr:rrmodified_kwargsrrrresolve_address`s    zResolver.resolve_addressrarrr&c Ks4i}|||ddtjj|d<|tjkrT|j|tjj fi|}t j |dS|tj kr|j|tjj fi|}t j |dS|tjkrtd||dd}|d d}t} |j|tjj fd || |d |}|j}|j|tjj fd || |d |}t j ||| d } | s0t|jd | S)aUse 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. rYNrZ)r|)r{rrTrF)rr)r{r|r}r)r;rrprtrrrr1rrrrzrrr~rrr_rr1rOr2) rrarrr?r|r{rrrrrrr resolve_namexsL              zResolver.resolve_namerar&c CsLz|j|dd}|j}Wn.tjjyF}z|j}WYd}~n d}~00|S)aDetermine 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)rN)r1r/rprr )rrar]r/rrrrr/s  zResolver.canonical_namerrr&cCshzPt|}|jtjjd|d}tj|}tj||}t|dkrN||_ Wnt ybYn0dS)aTry 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. ZSVCBrrN) r_r1rpZ_ddrZ_local_resolver_namerPZ _remainingZ_get_nameservers_syncr"rr0)rrr`r]rIrrrrtry_ddrs      zResolver.try_ddr)r)r9r:r;r<rprrrrtrr rarqr+rsrurrrxrrXr1rPrr@rrrzrBr/rFrrrrr+sb i # C r+default_resolverr%cCstdurttS)z7Get the default resolver, initializing it if necessary.N)rGreset_default_resolverrrrrget_default_resolversrIcCs tadS)zRe-initialize default resolver. Note that the resolver configuration (i.e. /etc/resolv.conf on UNIX systems) will be re-read immediately. N)r+rGrrrrrHsrHFTr,c Cst||||||||| 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. )rIr1) r1rYrZrr-rr.rrrrrr1 sr1r2c Cs(tjdtddt||||||||d S)aQuery nameservers to find the answer to the question. This method calls resolve() with ``search=True``, and is provided for backwards compatibility with prior versions of dnspython. See the documentation for the resolve() method for further details. z)please use dns.resolver.resolve() insteadrr3Tr5)r1rYrZrr-rr.rrrrrP*srPr9cOstj|g|Ri|S)zUse a resolver to run a reverse query for PTR records. See ``dns.resolver.Resolver.resolve_address`` for more information on the parameters. )rIr@)r:rrrrrr@Ksr@rAcKstj||fi|S)zUse a resolver to query for address records. See ``dns.resolver.Resolver.resolve_name`` for more information on the parameters. )rIrB)rarrrrrrBUs rBrCcCs t|S)zDetermine the canonical name of *name*. See ``dns.resolver.Resolver.canonical_name`` for more information on the parameters and possible exceptions. )rIr/rarrrr/asr/rrDcCs t|S)aTry 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. )rIrFrErrrrFksrF)rarZrrrr&c Cst|trtj|tjj}|dur*t}|s:t|t }|durT||}nd}zT|dur||t }|dkrd}nd}|j |tj j |||d}|j j|kr|WSWntjjtjjfyb} zt| tjjr| |} n| } | rN| jD]P} | jtj j kr| j|kr| j|\} } } | tjjkr| jWYd} ~ SqWYd} ~ n d} ~ 00z |}WqXtjjytYqX0qXdS)aFind 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``. NrrE)rr+rprarr rIrrTr_r1rrZSOAr^rr rOrr4r2Z authorityrYrZZ fullcompareZNAMERELN_SUPERDOMAINparentZNoParentrU)rarZrrrrr`Z rlifetimer]rr2Zrrsnrr0rrr zone_for_nameusF       . rMr)wherer\rrr&cCs|durt}g}t|tr>tj|r>|tj||n*| || D]}|tj||qNtj j dd}||_ |S)aMake 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. NF)r)rIrr+rpr#r$r5r[r%rBrrr+r)rNr\rrrrresrrrmake_resolver_atsrP)rNr1rYrZrr-rr.rrr\rrr&c Cs$t|| | | ||||||||| 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. )rPr1) rNr1rYrZrr-rr.rrr\rrrrr resolve_atsrQc CsT|tj@dkr t||||||S|tjtjB@dkrBttjd|dur`|dur`ttjdg}d}|durt||||||Sz tj |t||||||WSt yYn0z&t ||}|}|d}WnFtjjyttjdYn"t y"ttjdYn0d} z|dur:d} nt|} WnHt y|tj@dkrzt|} Wnt yYn0Yn0| durttjdg} |dkrtjtjg} n|g} |tj@dkr|} nd} |D]L\} }| D]<}t|D],}tj | | f|}| |||| |fqqqt| dkrPttjd| S)Nrz*Non-recoverable failure in name resolutionName or service not knownTz$Temporary failure in name resolution)rZAI_NUMERICHOST_original_getaddrinfoZ AI_ADDRCONFIGZ AI_V4MAPPEDgaierrorZEAI_FAIL EAI_NONAMErpr#Zaf_for_addressr0 _resolverrBrr/rrr Z EAI_AGAINrxZAI_NUMERICSERVZ getservbyname SOCK_DGRAM SOCK_STREAM AI_CANONNAME_protocols_for_socktypeZlow_level_address_tupler5r")hostservicerZsocktypeprotorZaddrsr/rr\tuplesZ socktypesr3addrafZ addr_tuplerrr _getaddrinfo*sj            rbc Csf|d}|d}t|dkr,|d}tj}n d}tj}t|||tjtjd}t|dkrbtd|ddd}|tj@rd}nd}t j |} |tj @dkrz"t | d} | jdjd } WnVt jjt jjfy|tj@rttjd |} |dur| d t|7} Yn0n|} |dur<| d t|7} |tj@rRt|} n t||} | | fS) Nrr'rDz'sockaddr resolved to multiple addressesZudprr<TrR%)r"rrrrbrYSOL_TCPerrorZNI_DGRAMrpr=r>ZNI_NUMERICHOSTrWr1r^targetrrr rO NI_NAMEREQDrUrVr+ZNI_NUMERICSERVZ getservbyport) sockaddrrr\r\Zscoperr_r`Zpnamer1r]hostnamer]rrr _getnameinfo~s@            rkcCs:|durt}zt|\}}}Wnty4Yn0|Sr)rr _gethostbyaddrr0)rar0rrr_getfqdns rmcCst|ddS)Nrr)_gethostbyname_exrJrrr_gethostbynamesrocCsTg}g}t|dtjtjtjtj}|dd}|D]}||ddq2|||fS)NrrDrc)rbrrrYrerZr5)raaliasesrr_ canonicalitemrrrrns rnc Csz"tj||dddf}tj}WnRtytztj|Wn ty`ttjdYn0|df}tj }Yn0t |tj \}}g}g}t |d|tj tjtj}|dd}tj||} |D]0} | dd} tj|| } | | kr|| q|||fS)NPrrRrDrc)rpZipv6Z inet_atonrrr0Zipv4rUrVrrkrhrbrYrerZr#Z inet_ptonr5) Ziprirrar0rprr_rqZbin_iprrr`Zbin_addrrrrrls2         rl)rr&cCs:|durt}|att_tt_tt_t t_ t t_ t t_dS)aOverride 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)rIrWrbr getaddrinfork getnameinformgetfqdnro gethostbynamerngethostbyname_exrl gethostbyaddr)rrrroverride_system_resolversrzcCs,datt_tt_tt_tt_ t t_ t t_ dS)z5Undo the effects of prior override_system_resolver().N)rWrTrrt_original_getnameinforu_original_getfqdnrv_original_gethostbynamerw_original_gethostbyname_exrx_original_gethostbyaddrryrrrrrestore_system_resolversr)r)r)N)N)yr<rrrrrr_r6typingrrrrrrr r urllib.parser Zdns._ddrrpZdns.ednsZ dns.exceptionZ dns.flagsZdns.inetZdns.ipv4Zdns.ipv6Z dns.messageZdns.nameZdns.nameserverZ dns.queryZ dns.rcodeZdns.rdataclassZ dns.rdatatypeZdns.rdtypes.svcbbaseZdns.reversenameZdns.tsigrZ dns.win32utilrZ DNSExceptionr rAr+rrxr0rvrr)rFZTimeoutrGrOrRrTrUrVrWrXr#ryrzrrrarqrrrsrtrurrrrrrr+rGr(rIrHrrrr1rPr@rrBr/rFrMrPrQrXZSOL_UDPrYrer[rWrtrTrur{rvr|rwr}rxr~ryrrbrkrmrornrlrzrrrrrsl(  X   E1OoU!  # !    W ' /   T '