f dZddlZddlZddlZddlmZmZmZmZm Z m Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ Gdde j<j>Z Gdde j<j>Z!Gdd e j<jDZ#Gd d e j<j>Z$Gd d e j<j>Z%Gdde j<jDZ&Gdde j<jDZ'Gdde j<jDZ(Gdde j<jDZ)Gdde j<jDZ*Gdde j<jVZ,Gdde jZj\Z/GddZ0dZ1dZ2e e3e jhjje jljne jpjree jpjree jljnfZ:ee:e jvjxfZ=e e3e>ee jvjxfZ?Gd d!Z@Gd"d#ZAGd$d%e@ZBd&ZCd'ZDGd(d)ZE dUd+eFd,eed-eeFd.eGd/ee jhjjd0ee e jje jjfd1eGd2eGd3eGd4eGd5eGd6eGd7e@fd8ZKGd9d:ZL dVd;e>dee jhjjd7e@fd?ZN dWd@edfdCe e jpjre>fdDe e jljne>fdEee e3eGfdFeGdGee3dHee3dIee3dJeee jjdZ7e deefd?Z8e defd@Z9e/d*e:dfdAZ;d*d*e:ddd*fdBee3eefdCedDedEeedFee e jxjzdGeddfdHZ>e defdIZ)reprrMr*s r__repr__zMessage.__repr__s"T$'']2S88rc"|jSr")to_textr*s r__str__zMessage.__str__s||~rr[ relativizekwc tj}|jd|jz|jdtj j |j z|jdtjj |jz|jdtjj |jz|jdk\r|jd|jz|jdk7r;|jdtjj|jz|jd|jz|jD]$}|jd |j z&|jjj!D]d\}}|jd |d |j#|D]6}|j|j ||fi||jd 8f|j%d d S)zConvert the message to text. The *origin*, *relativize*, and any other keyword arguments are passed to the RRset ``to_wire()`` method. Returns a ``str``. zid %d z opcode %s z rcode %s z flags %s rzedns %s z eflags %s z payload %d z option %s ; N)ioStringIOwriterMrOopcoderxrcoderRedns ednsflags edns_to_textpayloadoptions _section_enum __members__itemssection_from_numbergetvalue) r%r[rzr{srTnamewhichrrsets rrxzMessage.to_texts KKM  DGG#$   2 24;;= AAB  syy00>>?  syy00<<= 99> GGK$))+ ,~~"  (>(>t~~(NNO GGNT\\1 2<>"a' ::   + A&A % rrct|jD]\}}||us |j|cStd)zReturn the "section number" of the specified section for use in indexing. *section* is one of the section attributes of this message. Raises ``ValueError`` if the section isn't known. Returns an ``int``. zunknown section)rrSr ValueError)r%rr our_sections rsection_numberzMessage.section_number5sB( 6NA{+%))!,,7*++rnumbercV|jj|}|j|S)aReturn the section list associated with the specified section number. *number* is a section number `int` or the text form of a section name. Raises ``ValueError`` if the section isn't known. Returns a ``list``. )rmakerS)r%rrs rrzMessage.section_from_numberEs)$$))&1}}W%%rFrrdclassrdtypecoversdeletingcreate force_unique idna_codecc t|tr|} |j| }nNt|tr-|jj |} |j| }n|j |} t|tr!tjj || }tjjj|}tjjj|}tjjj|}|)tjjj|}| |||||f} |sK|j|jj| } | "| S|D]} | j!|||||s| cS|st"tj$j'|||||} |j)| |j| |j| <| S)aFind the RRset with the given attributes in the specified section. *section*, an ``int`` section number, a ``str`` section name, or one of the section attributes of this message. This specifies the the section of the message to search. For example:: my_message.find_rrset(my_message.answer, name, rdclass, rdtype) my_message.find_rrset(dns.message.ANSWER, name, rdclass, rdtype) my_message.find_rrset("ANSWER", name, rdclass, rdtype) *name*, a ``dns.name.Name`` or ``str``, the name of the RRset. *rdclass*, an ``int`` or ``str``, the class of the RRset. *rdtype*, an ``int`` or ``str``, the type of the RRset. *covers*, an ``int`` or ``str``, the covers value of the RRset. The default is ``dns.rdatatype.NONE``. *deleting*, an ``int``, ``str``, or ``None``, the deleting value of the RRset. The default is ``None``. *create*, a ``bool``. If ``True``, create the RRset if it is not found. The created RRset is appended to *section*. *force_unique*, a ``bool``. If ``True`` and *create* is also ``True``, create a new RRset regardless of whether a matching RRset exists already. The default is ``False``. This is useful when creating DDNS Update messages, as order matters for them. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. Raises ``KeyError`` if the RRset was not found and create was ``False``. Returns a ``dns.rrset.RRset object``. r)rrIrstrr from_textrrOr rdatatype RdataTyper rdataclass RdataClassr]get full_matchKeyErrorrRRsetappend) r%rrrrrrrrrrkeyrs r find_rrsetzMessage.find_rrsetTsh gs #$N..~>G  %!//99'BN..~>G!009N dC 88%%dz%BD((--f5..++009((--f5  ~~0055h?HtWffhGzz% s+$ L$E''gvvxP$ %N gvvxHu :: !#DJJsO rc ^ |j||||||||| } | S#t$rd} Y| SwxYw)ajGet the RRset with the given attributes in the specified section. If the RRset is not found, None is returned. *section*, an ``int`` section number, a ``str`` section name, or one of the section attributes of this message. This specifies the the section of the message to search. For example:: my_message.get_rrset(my_message.answer, name, rdclass, rdtype) my_message.get_rrset(dns.message.ANSWER, name, rdclass, rdtype) my_message.get_rrset("ANSWER", name, rdclass, rdtype) *name*, a ``dns.name.Name`` or ``str``, the name of the RRset. *rdclass*, an ``int`` or ``str``, the class of the RRset. *rdtype*, an ``int`` or ``str``, the type of the RRset. *covers*, an ``int`` or ``str``, the covers value of the RRset. The default is ``dns.rdatatype.NONE``. *deleting*, an ``int``, ``str``, or ``None``, the deleting value of the RRset. The default is ``None``. *create*, a ``bool``. If ``True``, create the RRset if it is not found. The created RRset is appended to *section*. *force_unique*, a ``bool``. If ``True`` and *create* is also ``True``, create a new RRset regardless of whether a matching RRset exists already. The default is ``False``. This is useful when creating DDNS Update messages, as order matters for them. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. Returns a ``dns.rrset.RRset object`` or ``None``. N)rr) r%rrrrrrrrrrs r get_rrsetzMessage.get_rrsetsSf OO E  E  s  ,,cxt|tr|}|j|}nNt|tr-|jj |}|j|}n|j |}td|D}|tjk(r"|j|dz }|j|dz }|S)aReturns the number of records in the specified section. *section*, an ``int`` section number, a ``str`` section name, or one of the section attributes of this message. This specifies the the section of the message to count. For example:: my_message.section_count(my_message.answer) my_message.section_count(dns.message.ANSWER) my_message.section_count("ANSWER") c3FK|]}tdt|yw)r7N)maxr).0rrss r z(Message.section_count..s8C3s8$8s!r7) rrIrrrrrsumr6rArTrX)r%rrcounts r section_countzMessage.section_counts gs #$N..~>G  %!//99'BN..~>G!009N888 ^66 6xx# yy$  rc|jsyd}|jdjD]#}|j}|t|dzz }%|jr|dz }|S)z:Compute the size required for the OPT RR, padding excludedr )rTrto_wirerrV)r%sizeoptionwires r_compute_opt_reservezMessage._compute_opt_reserves`xx hhqk))F>>#D CIM !D* 88 AID rc|jsytj}|jj|t |j S)z)Compute the size required for the TSIG RRr)rXrBytesIOrrr)r%fs r_compute_tsig_reservezMessage._compute_tsig_reserves<yy JJL !1::<  rrmax_sizemultir\prepend_lengthprefer_truncationc ||j |j}|dk(r|jdk7r |j}nd}|dkrd}n|dkDrd}tjj |j |j ||}|j} |j| |j} |j|  |jD]3} |j| j| j| j5|jD].} |j tjj"| fi|0|j$D].} |j tjj&| fi|0|j(D].} |j tjj*| fi|0 |j5|j6(|j9|j6|j:| | |j=|j>tj>jA|jC|jD|j>dtGtIjH|jJ||\} } |j>jM|j>jO| |j!tjj*|j>|j=|r| |_(|jC}|rtS|jUdd|z}|S#tj,j.$r\|rU|j0tjj*kr/|xj tj j2zc_nYwxYw)aReturn a string containing the message in DNS compressed wire format. Additional keyword arguments are passed to the RRset ``to_wire()`` method. *origin*, a ``dns.name.Name`` or ``None``, the origin to be appended to any relative names. If ``None``, and the message has an origin attribute that is not ``None``, then it will be used. *max_size*, an ``int``, the maximum size of the wire format output; default is 0, which means "the message's request payload, if nonzero, or 65535". *multi*, a ``bool``, should be set to ``True`` if this message is part of a multiple message sequence. *tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the ongoing TSIG context, used when signing zone transfers. *prepend_length*, a ``bool``, should be set to ``True`` if the caller wants the message length prepended to the message itself. This is useful for messages sent over TCP, TLS (DoT), or QUIC (DoQ). *prefer_truncation*, a ``bool``, should be set to ``True`` if the caller wants the message to be truncated if it would otherwise exceed the maximum length. If the truncation occurs before the additional section, the TC bit will be set. Raises ``dns.exception.TooBig`` if *max_size* was exceeded. Returns a ``bytes``. riir8big)+r[rUrOrendererRendererrMrRrreserverrc add_questionrrrrk add_rrsetr?rnr@rqrArETooBigrTCrelease_reservedrTadd_optrV write_headerrXsignget_wirerWrIr_rYclearaddr\rto_bytes)r%r[rrr\rrr{r opt_reserve tsig_reservernew_tsigctxrs rrzMessage.to_wire(sX >dkk5[[F q=##q(//  c>H  H LL ! !$''4::x H//1  +113  , uzz5<<G' CLL//="=% CLL22E@R@( CLL33UAbA)  88  IIdhh+| D  99 !hhmm   ! DIIK   OXs IIOO  IIMM( # KK // ; NN  # zz| t9%%a/$6D ;}}##  99s||666GGsyy||+G  sC9MA5N?>N?c tjjjjtjjtj j||||||| }tj j|d|Srf)rOrdtypesANYTSIGrrr from_rdata) keyname algorithm time_signedfudgemac original_iderrorrrXs r _make_tsigzMessage._make_tsigsl{{##(( NN   MM           yy##GQ55r,rrWrrr tsig_error other_datarc zt|tjjr|}|j}nt |r |||}n{t|t rtjj|}|tt|}||}t|tr!tjj|||}||_ | |j}|j||jjd|dtjj|jjz||||_y)aWhen sending, a TSIG signature using the specified key should be added. *key*, a ``dns.tsig.Key`` is the key to use. If a key is specified, the *keyring* and *algorithm* fields are not used. *keyring*, a ``dict``, ``callable`` or ``dns.tsig.Key``, is either the TSIG keyring or key to use. The format of a keyring dict is a mapping from TSIG key name, as ``dns.name.Name`` to ``dns.tsig.Key`` or a TSIG secret, a ``bytes``. If a ``dict`` *keyring* is specified but a *keyname* is not, 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 ``dict`` keyring is used, unless they know the keyring contains only one key. If a ``callable`` keyring is specified, the callable will be called with the message and the keyname, and is expected to return a key. *keyname*, a ``dns.name.Name``, ``str`` or ``None``, the name of this TSIG key to use; defaults to ``None``. If *keyring* is a ``dict``, the key must be defined in it. If *keyring* is a ``dns.tsig.Key``, this is ignored. *fudge*, an ``int``, the TSIG time fudge. *original_id*, an ``int``, the TSIG original id. If ``None``, the message's id is used. *tsig_error*, an ``int``, the TSIG error code. *other_data*, a ``bytes``, the TSIG other data. *algorithm*, a ``dns.name.Name`` or ``str``, the TSIG algorithm to use. This is only used if *keyring* is a ``dict``, and the key entry is a ``bytes``. Nr)rrOrXKeyrcallablerrnextiterbytesrWrMrr mac_sizes) r%rWrrrrrrrs ruse_tsigzMessage.use_tsigs^ gsxx|| ,ChhG g $(C'3'((,,W5tG}-'"C#u%hhll7C;  ''KOO  LL " "  chh(()?)?@ @      rcH|jr|jjSyr")rXrr*s rrzMessage.keynames 9999>> !rcN|jr|jdjSyrf)rXrr*s r keyalgorithmzMessage.keyalgorithms 9999Q<)) )rcN|jr|jdjSyrf)rXrr*s rrz Message.macs 9999Q<## #rcN|jr|jdjSyrf)rXrr*s rrzMessage.tsig_errors 9999Q<%% %rc,t|jSr")boolrXr*s rhad_tsigzMessage.had_tsigsDIIrc(tjjjj|tjj|xsd}tj j tjjt||S)Nr) rOrrOPTrrrrrootrI)rRrrrTs r _make_optzMessage._make_optsWkkoo!!%%gs}}/@/@'-RPyy##CHHMM3u:sCCrrrrrUrrVc||durd}n|durd}|dkrd|_d|_y|dz}||dzz}|g}|j||||_||}||_|dkr td||_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. *request_payload*, an ``int``, is the EDNS payload size to use when sending this message. If not specified, defaults to the value of *payload*. *options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS options. *pad*, a non-negative ``int``. If 0, the default, do not pad; otherwise add padding bytes to make the message size a multiple of *pad*. Note that if padding is non-zero, an EDNS PADDING option will always be added to the message. NFrTrl~rJzpad must be non-negative)rTrUrrrV)r%rrrrUrrVs ruse_ednszMessage.use_edns s@ <45=D T\D !8DH#$D   #I  #I~~i'BDH&")#2D Qw !;<<DHrc@|jr|jdzdz Sy)NirJr)rTrr*s rrz Message.ednsAs 88NNX-"4 4rcH|jr|jjSyrf)rTttlr*s rrzMessage.ednsflagsHs 8888<< rcr|jr||j_y|r|j||_yyr")rTrrrgs rrzMessage.ednsflagsOs, 88DHHL ~~a(DHrcN|jr|jdjSyrf)rTrr*s rrzMessage.payloadVs 8888A;&& &rcN|jr|jdjSy)Nrr)rTrr*s rrzMessage.options]s 8888A;&& &rwantedc|r.|xjtjjzc_y|jr8|xjt tjjzc_yy)a!Enable or disable 'DNSSEC desired' flag in requests. *wanted*, a ``bool``. If ``True``, then DNSSEC data is desired in the response, EDNS is enabled if required, and then the DO bit is set. If ``False``, the DO bit is cleared if EDNS is enabled. N)rrOrRDOrTrI)r%r#s r want_dnsseczMessage.want_dnssecdsG  NNciill *N XX NNs399<<00 0Nrctjjt|jt|j S)zBReturn the rcode. Returns a ``dns.rcode.Rcode``. )rOrrrIrRrr*s rrz Message.rcoders, yy##C OS5HIIrrctjj|\}}|xjdzc_|xj|zc_|xjdzc_|xj|zc_y)zUSet the rcode. *rcode*, a ``dns.rcode.Rcode``, is the rcode to set. iiN)rOrto_flagsrRr)r%rvalueevalues r set_rcodezMessage.set_rcodeysT )),,U3 f  e  *$ & rcftjjt|jS)zEReturn the opcode. Returns a ``dns.opcode.Opcode``. )rOrrrIrRr*s rrzMessage.opcodes! zz$$S_55rrc|xjdzc_|xjtjj|zc_y)zZSet the opcode. *opcode*, a ``dns.opcode.Opcode``, is the opcode to set. iN)rRrOrr))r%rs r set_opcodezMessage.set_opcodes/ f  cjj))&11 rc|Sr"r)r%r*s r_get_one_rr_per_rrsetzMessage._get_one_rr_per_rrsets rc||ddfSNFr)r%rrrrs r_parse_rr_headerzMessage._parse_rr_headersu--rc|tjjk(rB|tjk7s)|j s|tj jk7rat|tjjk(r>|tjk7s%|tjjk7s||dz k7rt||ddfS)Nr7F) rOrrr6rArTrrrrrr)r%rrpositionrrrs r_parse_special_rr_headerz Message._parse_special_rr_headers S]]&& &>44488388==( s}})) )>444cmm///uqy( u--rr")NT)NrFNFF)T)Mr r rrr6rrrIr$propertyrrOrrrcsetterrkrnrqrvryrNamerrrrrxrrrrrrNONE SectionTyperrr IDNACodecrrrrrr r staticmethodrrXdefault_algorithmrrrrrrrDEFAULT_EDNS_PAYLOADrrOptionrrrrrr&rRcoder,rOpcoder/r1r4r7rrrrLrLsN"M8C=( $syy/  __ SYY__-   ]] 4 0   D1  9 +/$!'$!$!38n $! $!L.&$$t$L,d399??&;,, &# &$syy2G &*+.--*<*<8<"37SShhmmS** S  '' S  '' S3>>445SSSSXX//0S Sv+.--*<*<8<"37AAhhmmA** A  '' A  '' A3>>445AAASXX//0A #))// "AF[S8c& !s !+/"&$"'b'bb b 3- b  b b38nb bH66&8<%)/2xx/I/IH H % s 234H  H c] H  H H +,H  H T#((--0 hsxx}}5 Xe_ HSM $#7DD ,-+)-373uS$Y'(33 3 "# 3 $sxx/0 33 3jc 3 ))   1$ 1$ 1JsyyJ !syy !4 !6 ))62!2!22t2 . .rrLc eZdZdZdej j deejjde de ejjfdZ y)ChainingResultaThe result of a call to dns.message.QueryMessage.resolve_chaining(). The ``answer`` attribute is the answer RRSet, or ``None`` if it doesn't exist. The ``canonical_name`` attribute is the canonical name after all chaining has been applied (this is the same name as ``rrset.name`` in cases where rrset is not ``None``). The ``minimum_ttl`` attribute is the minimum TTL, i.e. the TTL to use if caching the data. It is the smallest of all the CNAME TTLs and either the answer TTL if it exists or the SOA TTL and SOA minimum values for negative answers. The ``cnames`` attribute is a list of all the CNAME RRSets followed to get to the canonical name. canonical_namerk minimum_ttlcnamesc<||_||_||_||_yr")rFrkrGrH)r%rFrkrGrHs rr$zChainingResult.__init__s"- & rN) r r rrrOrr:rrrrIrr$rrrrErEsT$   )   SYY__% rrEcLeZdZdefdZdej jfdZy) QueryMessager`c|jtjjzdk(rtt |j dk7rtj j|j d}|j}tjj}d}d}g}|tkrJ |j|j||j|j}t!||j} |tk\rt,|j/tj.j0k(r|t2|i|} |j|j4| |jtj$j6} t!|| j| dj8} t?||||S#t"$r|jtj$j&k7r |j|j||jtj$j&}|j)|t!||j}|D]}|j*}n|dz }Y#t"$rYY|wxYwYwxYw#t"$r: | j;} n%#tjj<$rYYwxYwYnwxYw)aFollow the CNAME chain in the response to determine the answer RRset. Raises ``dns.message.NotQueryResponse`` if the message is not a response. Raises ``dns.message.ChainTooLong`` if the CNAME chain is too long. Raises ``dns.message.AnswerForNXDOMAIN`` if the rcode is NXDOMAIN but an answer was found. Raises ``dns.exception.FormError`` if the question count is not 1. Returns a ChainingResult object. rr7N) rRrOrr.rrcrE FormErrorrrMAX_TTL MAX_CHAINrrkrrminrrCNAMErtargetr0rNXDOMAINr2rnSOAminimumparentNoParentrE) r%rcqnamemin_ttlrkrrHcrrsetrdaunamesrrsets rresolve_chainingzQueryMessage.resolve_chainingsZ :: $ )" " t}}  "--)) )==# ''//i KK(8(8(//gvzz2( I   ::<399-- -&2D# # >F !__0@0@#--BSBSF"'6::vay7H7HIG eVWf==Q ??cmm&9&99 !% KK0@0@#--BUBU" f-"%gvzz":"(B$&IIE!#)  # % F !'88,,si(AF,9A$I8,0I5BI  I.)I5-I..I54I58 J;JJ;J50J;4J55J;:J;c6|jjS)aReturn the canonical name of the first name in the question section. Raises ``dns.message.NotQueryResponse`` if the message is not a response. Raises ``dns.message.ChainTooLong`` if the CNAME chain is too long. Raises ``dns.message.AnswerForNXDOMAIN`` if the rcode is NXDOMAIN but an answer was found. Raises ``dns.exception.FormError`` if the question count is not 1. )r^rFr*s rrFzQueryMessage.canonical_names$$&555rN) r r rrEr^rOrr:rFrrrrKrKs%I>.I>V6 6rrKc ddl}yrf) dns.update)rOs r_maybe_import_updaterb-s rc|tjjk(rtS|tjjk(r$t tj jStSr") rOrQUERYrKUPDATErbupdate UpdateMessagerL)rs r_message_factory_from_opcoderh6sG !!! 3::$$ $zz'''rc<eZdZdZ ddZdZdZdZdZy) _WireReaderaiWire format reader. parser: the binary parser message: The message object being built initialize_message: Callback to set message parsing options question_only: Are we only reading the question? one_rr_per_rrset: Put each RR into its own RRset? keyring: TSIG keyring ignore_trailing: Ignore trailing junk at end of request? multi: Is this message part of a multi-message sequence? DNS dynamic updates. continue_on_error: try to extract as much information as possible from the message, accumulating MessageErrors in the *errors* attribute instead of raising them. Nc tjj||_d|_||_||_||_||_||_ ||_ ||_ g|_ yr") rOrParserparserr initialize_message question_onlyone_rr_per_rrsetignore_trailingrWrcontinue_on_errorr^) r%rrnrorprqrWrrrs rr$z_WireReader.__init__Qs\hhood+  "4* 0.  !2 rc |jJ|jj|}t|D]}|jj |jj }|jj d\}}|jj||||\}}}}|jj||||ddy)zhRead the next *qcount* records from the wire data and add them to the question section. Nz!HHTrr) r rSrangermget_namer[ get_structr4r)r%rqcountr_rXrrs r _get_questionz_WireReader._get_questiongs||''',,''7vAKK(()<)<=E $ 6 6u = VW&*ll&C&Cw' #Wfa LL # #4 $  rcv|jjt||jjyr")r^rrDrmcurrent)r%es r _add_errorz_WireReader._add_errorws% <4;;+>+>?@rc  |jJ|jj|}|j}t|D]g}|jj }|jj }|jj&|j|jj}n|}|jjd\} } } } | tjjtjjfvr&|jj||||| | \} } } }n#|jj||| | \} } } }|jj } |r<| dkDrtj j"d}tjj$}nt|jj'| 5tj(j+| | |j|jj}dddj-}|jj.r| tjj0k(rd}| tjjk(r2tj2j5|| ||j_n | tjjk(r|j8 t;dt=|j8t>rW|j8jA|}t=|tBrjtjDjG|||jH}n>tK|j8r|j9|j|}n |j8}|t;d|z||j_tjDjM|jjN|||tQtSjR|jjT||jjV|jX |j_+tj2j5|d||j_"n=|jj[||| | || d|}|| dkDrd} |j]|| jy#1swYxYw#t^$rH}|j`r0|jc||jje|| znYd}~d}~wwxYw)zRead the next I{count} records from the wire data and add them to the specified section. section_number: the section of the message to which to add records count: the number of records to read Nz!HHIHrTz"got signed message without keyringzkey '%s' unknowni)3r rSrprurmr|rvr[rzrwrOrrrr7r4rErMr; restrict_tordatafrom_wire_parserrrZrTrrrTrWrrdictrr rXrrr validaterrIr_rYr\rrrrHrrr~seek)r%rrrrrrr_start absolute_namerrrrrdlenrempty rdata_startr[rrrr}s r _get_sectionz_WireReader._get_sectionzs||''',,''7,, uA{{**H KK002M||"".$// 0C0CD$,0KK,B,B7,K )VWc5#--++S]]-?-?@@ LL99"E1dGV  6:\\5R5R"D'662&(E++--K> qy!mm555B ]]//F007 YY77#VT[[$,,:M:M YY[F<<###--2C2C(C#'LS]]...'*yy';';D#r'JDLL$s}}111||+,-QRR!$,,5"ll..}=%c51"%((,,}c2<<"PC!$,,/"ll4<<G"ll{,-?$-FGG+.DLL(,/HH,=,= ((%DIIK( 00  --  -DLL)), (<(<]Ar(RDLL% LL33 $ E~+"#C "c*]:d ))OOA&KK$$[5%89: s3'AR8AR+J&R8+R5 0R88 T =TT c|jjdkrt|jjd\}}}}}}t t j j|}|||_t jj||j_ |j|j|jj|j|_ |jtj ||j"r |jS|j%tj&||j%tj(||j%tj*||j,s#|jjdk7rt.|j0re|jj2rO|jj4s9|jj2j7|jj8|jS#t:$r4}|j<r|j?|nYd}~|jSd}~wwxYw)zNRead a wire format DNS message and build a dns.message.Message object. z!HHHHHHrMrN) rm remainingr rwrhrOrrr rRFlagrnr1rprzr6r>rorr?r@rArqrrr\rrfrrHrrr~) r%rMrRrxancountaucountadcountfactoryr}s rreadz_WireReader.reads ;; "R ' 9=9O9O : 6UFGWg/szz/D/DU/KL"~  YY^^E2   - $ B B  ! !!     ~66 ?!!||#   n33W =   n66 @   n77 A''DKK,A,A,Cq,H""zzdll33DLL ||  %%"#||  s07H4(DH44 I1=I,,I1)FFFNFF) r r rrr$rzr~rrrrrrjrj@s7(, A^@ rrjFrrWrYrZr[r\rrorprqraise_on_truncationrrr`c dfd} t|| ||| ||| } | j}|j tj jzr| r t|| r| j|_ |S#tjj$rW| j rI| j j tj jzr| rt| j wxYw)aConvert a DNS wire format message into a message object. *keyring*, a ``dns.tsig.Key`` or ``dict``, the key or keyring to use if the message is signed. *request_mac*, a ``bytes`` or ``None``. If the message is a response to a TSIG-signed request, *request_mac* should be set to the MAC of that request. *xfr*, a ``bool``, should be set to ``True`` if this message is part of a zone transfer. *origin*, a ``dns.name.Name`` or ``None``. If the message is part of a zone transfer, *origin* should be the origin name of the zone. If not ``None``, names will be relativized to the origin. *tsig_ctx*, a ``dns.tsig.HMACTSig`` or ``dns.tsig.GSSTSig`` object, the ongoing TSIG context, used when validating zone transfers. *multi*, a ``bool``, should be set to ``True`` if this message is part of a multiple message sequence. *question_only*, a ``bool``. If ``True``, read only up to the end of the question section. *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset. *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the message. *raise_on_truncation*, a ``bool``. If ``True``, raise an exception if the TC bit is set. *continue_on_error*, a ``bool``. If ``True``, try to continue parsing even if errors occur. Erroneous rdata will be ignored. Errors will be accumulated as a list of MessageError objects in the message's ``errors`` attribute. This option is recommended only for DNS analysis tools, or for use in a server as part of an error handling path. The default is ``False``. Raises ``dns.message.ShortHeader`` if the message is less than 12 octets long. Raises ``dns.message.TrailingJunk`` if there were octets in the message past the end of the proper DNS message, and *ignore_trailing* is ``False``. Raises ``dns.message.BadEDNS`` if an OPT record was in the wrong section, or occurred more than once. Raises ``dns.message.BadTSIG`` if a TSIG record was not the last record of the additional data section. Raises ``dns.message.Truncated`` if the TC flag is set and *raise_on_truncation* is ``True``. Returns a ``dns.message.Message``. rc>|_|_|_|_yr")rYrZr[r\)r r[rYr\rZs rrnz%from_wire..initialize_messageFs!) #r)r ) rjrrOrErMr rRrrr^)rrWrYrZr[r\rrorprqrrrrnreaderms ```` r from_wirersL $    F  KKM ww"5""== H! == " " NN%% 4#FNN3 3 s A>>A4C2c>eZdZdZ d dZdZdZdZdZdZ y) _TextReaderatText format reader. tok: the tokenizer. message: The message object being built. DNS dynamic updates. last_name: The most recently read name when building a message object. one_rr_per_rrset: Put each RR into its own RRset? origin: The origin for relative names relativize: relativize names? relativize_to: the origin to relativize to. Nc>d|_tjj|||_d|_||_||_||_||_ d|_ d|_ d|_ t|_d|_tj j"|_d|_y)Nrrr)r rO tokenizer Tokenizertok last_namerpr[rz relativize_torMrrr@rrrrdrR)r%textrrpr[rzrs rr$z_TextReader.__init__xs ==**4J*G 0 $* +  jj&&  rc|jj}|j}|dk(r!|jj|_ns|dk(r |jj}|j s|jj |n&|jtjj|jz|_|dk(rB|jj|_ |j|jdzz|_ n|dk(r|jdkrd|_ |jj}|j s|jj |n@|jtjj|jz|_ |dk(r6|jj|_ |jdkrd|_ n|dk(rz|jj}tjj||_|jtjj!|jz|_nJ|d k(r?|jj}tj"j||_nt$|jj'y ) z5Process one line from the text format header section.rMrRrrJeflagsrrrrN)rrr*get_intrM is_identifierungetrRrOrrredns_from_textr get_stringrr)rrget_eol)r%rytokenwhatrs r _header_linez_TextReader._header_lines {{ 4<hh&&(DG W_ **,HHNN5)!ZZ#))*=*=ekk*JJ  V^((*DI!^^tyyB?DN X yy1}  **,HHNN5)!%#))2J2J5;;2W!W  Y 88++-DLyy1} X 88&&(D**..t4DKcjj&9&9$++&FFDJ W_88&&(D,,T2DJ$ $ rc~|jj|}|jjd}|j sK|jj ||jj |j|j|_ |j}|t|jj}|jstjj tjj!|j"}|jj}|jstjj tj(j!|j"}|jj+||||\}}}}|jj-||||dd|jj/y#tjj$rtjjt$$rtjj&}YwxYw)z7Process one line from the text format question section.T want_leadingNrt)r rSrr is_whitespaceas_namer[rzrrr4rrOrE SyntaxErrorrrr*rHINrr4rr)r%rrrrrrrys r_question_linez_TextReader._question_lines,,''7 $ /""$!XX--t||**DOOT=O=ODN~~ <  ""$--++ + (nn..u{{;GHHLLNE&&(mm///)((5"&,,"?"? D'6# &!Q  T7F4d   }}(( ,--++ + (nn''G (s*A-G AH<;H<c |jj|}|jjd}|j sK|jj ||jj |j|j|_ |j}|t|jj}|jstjj t|j d}|jj}|jstjj tj$j'|j }|jj}|jstjj tj*j'|j }|jj-||||\}}}} |jj}| r*|j/stjj| s*|j/rtjj0|j/s|jj3|tj4j'|||j|jj |j|j} | j7} nd} tj*j8} |jj;||||| |d|j<} | | j?| |yy#tjj$rtjjt"$rd}YawxYw#tjj$rtjjt"$rtj$j(}YRwxYw)zfProcess one line from the text format answer, authority, or additional data sections. TrNr) r rSrrrrr[rzrrr4rrOrErrIr*rHrrrrr4 is_eol_or_eof UnexpectedEndrrrr;rrpr) r%rrrrrrrrrr[rrs r_rr_linez_TextReader._rr_lines  ,,''7 $ /""$!XX--t||**DOOT=O=ODN~~ <  ""$--++ + ekk1%CHHLLNE&&(mm///) (nn..u{{;GHHLLNE&&(mm///)((5-1\\-J-J D'6. *&(E  ,,.--++ +,,.---- -""$ HHNN5 !$$ ##"" BYY[FB]]''F ''         ! !   > IIb#  a}}(( ,--++ + C }}(( ,--++ + (nn''G (s(*AM"A-N*"AN'&N'*APPct|j}||j}|j|_|jdk\r1|j |j|j |j|jr|j|j|jr|j|_ |S)Nrr) rhrrMrRrrrrrr,r[)r%rr s r _make_messagez_TextReader._make_message's.t{{;TWW%  99>   TYY E ::   djj ) ;;![[GNrc4|j}d} |jjdd}|jrn |j r|j j }|dk(r |j}|jr |j}n|j} |jj|}|js'||_|j|j|_ |tjk(r |j}n |j }|jj%*|jj'|||N|js|j|_|jS#t"$rYywxYw)zNRead a text format DNS message and build a dns.message.Message object.NTHEADER)rrrr is_commentr*upperr rrrr1rpr6r>rrrHrr)r% line_methodrrur s rrz_TextReader.read3s`'' HHLLt,E""$!KK%%'="&"3"3K<<"llG#002G%,%:%:%D%DQ%GN <<'. 070M0M 111-&)@)@@&*&9&9 &*mm   " HHNN5 !  'EF||--/DL||!s#A:F FF)FNTN) r r rrr$rrrrrrrrrrks7  0'R!FIV +rrrrrzrcBt||||||}|jS)aConvert the text format message into a message object. The reader stops after reading the first blank line in the input to facilitate reading multiple messages from a single file with ``dns.message.from_file()``. *text*, a ``str``, the text format message. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. *one_rr_per_rrset*, a ``bool``. If ``True``, then each RR is put into its own rrset. The default is ``False``. *origin*, a ``dns.name.Name`` (or ``None``), the origin to use for relative names. *relativize*, a ``bool``. If true, name will be relativized. *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use when relativizing names. If not set, the *origin* value will be used. Raises ``dns.message.UnknownHeaderField`` if a header is unknown. Raises ``dns.exception.SyntaxError`` if the text is badly formed. Returns a ``dns.message.Message object`` )rr)rrrpr[rzrrs rrras+T j*FJ F ;;=rrct|tr t|}ntj|}|5}t |||cdddS#1swYnxYwJ)aRead the next text format message from the specified file. Message blocks are separated by a single blank line. *f*, a ``file`` or ``str``. If *f* is text, it is treated as the pathname of a file to open. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. *one_rr_per_rrset*, a ``bool``. If ``True``, then each RR is put into its own rrset. The default is ``False``. Raises ``dns.message.UnknownHeaderField`` if a header is unknown. Raises ``dns.exception.SyntaxError`` if the text is badly formed. Returns a ``dns.message.Message object`` N)rropen contextlib nullcontextr)rrrpcms r from_filersS4!S04Q  # #A & :qJ(89:::5s A  ArXrrrr&rrrUrrMrRrVc Pt|tr!tjj || }tj j j|}tjjj|}t| } tjj| | _ | j| j|||ddi}|||d<|||d<|||d<|||d<|r|d }||d <| |d <| jd i|| j!|| S) aMake a query message. The query name, type, and class may all be specified either as objects of the appropriate type, or as strings. The query will have a randomly chosen query id, and its DNS flags will be set to dns.flags.RD. qname, a ``dns.name.Name`` or ``str``, the query name. *rdtype*, an ``int`` or ``str``, the desired rdata type. *rdclass*, an ``int`` or ``str``, the desired rdata class; the default is class IN. *use_edns*, an ``int``, ``bool`` or ``None``. The EDNS level to use; the default is ``None``. If ``None``, EDNS will be enabled only if other parameters (*ednsflags*, *payload*, *request_payload*, or *options*) are set. See the description of dns.message.Message.use_edns() for the possible values for use_edns and their meanings. *want_dnssec*, a ``bool``. If ``True``, DNSSEC data is desired. *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. *request_payload*, an ``int``, is the EDNS payload size to use when sending this message. If not specified, defaults to the value of *payload*. *options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS options. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. *id*, an ``int`` or ``None``, the desired query id. The default is ``None``, which generates a random query id. *flags*, an ``int``, the desired query flags. The default is ``dns.flags.RD``. *pad*, a non-negative ``int``. If 0, the default, do not pad; otherwise add padding bytes to make the message size a multiple of *pad*. Note that if padding is non-zero, an EDNS PADDING option will always be added to the message. Returns a ``dns.message.QueryMessage`` rrTrtrrrUrrrrVr)rrrOrrrrrrrrKrRrrrcrr&)rXrrrr&rrrUrrrMrRrVrr's r make_queryrsL%""5Z"@ ]] $ $ ) )& 1Fnn'',,W5GAiinnU#AGLLUGVDtLT F'{#y"$3 !#y ("F6NF5MAJJMM+ Hrqueryrecursion_available our_payloadrrc |jtjjzrtjj dt |j }||j}tjj|jtjjzz|_|r-|xjtjjzc_|j|j t|j|_ |jdk\ri|Gd}|jD]6}|jtjj j"k(s5d}8|j%dd||j&||j(rF|j+|j,|j.|d|d|j0|j2|_|S)aMake a message which is a response for the specified query. The message returned is really a response skeleton; it has all of the infrastructure required of a response, but none of the content. The response's question section is a shallow copy of the query's question section, so the query's question RRsets should not be changed. *query*, a ``dns.message.Message``, the query to respond to. *recursion_available*, a ``bool``, should RA be set in the response? *our_payload*, an ``int``, the payload size to advertise in EDNS responses. *fudge*, an ``int``, the TSIG time fudge. *tsig_error*, an ``int``, the TSIG error. *pad*, a non-negative ``int`` or ``None``. If 0, the default, do not pad; otherwise if not ``None`` add padding bytes to make the message size a multiple of *pad*. Note that if padding is non-zero, an EDNS PADDING option will always be added to the message. If ``None``, add padding following RFC 8467, namely if the request is padded, pad the response to 468 otherwise do not pad. Returns a ``dns.message.Message`` object whose specific class is appropriate for the query. For example, if query is a ``dns.update.UpdateMessage``, response will be too. z&specified query message is not a queryrrNi)rVr)rRrOrrErMrhrrMRDRAr/listrcrrotype OptionTypePADDINGrrrrrWrrrrY) rrrrrrVrresponsers r make_responsers^H {{SYY\\!mm%%&NOO*5<<>:G%((#HYY\\U[[399<<%?@HN#)),,&  'U^^,H zzQ ;C--<<388#6#6#>#>>C( !Q U]]D ~~ MM MM         %yy Or) NrFNNFFFFFF)NFNTNr3)Fi rrN)[rrrr_typingrrrrrrdns.ednsrO dns.entropydns.enum dns.exception dns.flagsdns.name dns.opcode dns.rcode dns.rdatadns.rdataclass dns.rdatatypedns.rdtypes.ANY.OPTdns.rdtypes.ANY.TSIG dns.renderer dns.rrsetdns.tsigdns.ttldns.wirerErMr r DNSExceptionrrrrrr.r0r2rr4enumIntEnumr6rDr@rOrIrr:rrrr IndexKeyTyperr IndexTyperr<rLrErKrbrhrjr rrXHMACTSigGSSTSigrrr=rrrrRrrrArrr>r?r@rArrrrs$ ::=#--))=P3==**P33 $cmm%%$ $cmm%%$ 3S]]//3& **&$0s}}110'3==--'9 229&S]]..& SXX%%    HHMMNNMM S]] $ $% S^^ & &' )  syy. / Cd399??334 a .a .H@Z67Z6zzz~"#&&*EI"! %#k k c]k %k   k SXX]] # k uSXX..0@0@@AB k  k k k k k k  k \ssp04"&*-1 - -++,-- SXX]] # -  - CHHMM* - -d04"   ++,   L69^^5F5F+/#!%)/3/3_ # $_ #--))3. /_ 3>>,,c1 2_ uS$Y'( _  _ } _ c]_ c]_ d388??+ ,_ ++,_   _  _  _ _ H!& @ @@@  @  @ # @ @J  " "     $ $  & & r