3 ê@éWy¨ã @sœdZddlmZddlmZddlZddlZddlZddl Zddl Zddl Zddl Zddl ZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZGdd„dejjƒZGd d „d ejjƒZGd d „d ejjƒZGd d„dejjƒZ Gdd„dejjƒZ!Gdd„dejjƒZ"Gdd„de#ƒZ$Gdd„de#ƒZ%d(dd„Z&Gdd„de#ƒZ'dd„Z(d d!„Z)ej*j+ddddddfd"d#„Z,d)d&d'„Z-dS)*z DNS Messagesé)Úabsolute_import)ÚStringIONé)ÚlongÚxrangeÚ string_typesc@seZdZdZdS)Ú ShortHeaderz2The DNS packet passed to from_wire() is too short.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r ú/usr/lib/python3.6/message.pyr*src@seZdZdZdS)Ú TrailingJunkzEThe DNS packet passed to from_wire() has extra junk at the end of it.N)r r r r r r r rr/src@seZdZdZdS)ÚUnknownHeaderFieldzVThe header field name was not recognized when converting from text into a message.N)r r r r r r r rr4src@seZdZdZdS)ÚBadEDNSzVOPT record occurred somewhere other than the start of the additional data section.N)r r r r r r r rr:src@seZdZdZdS)ÚBadTSIGzWA TSIG record occurred somewhere other than the end of the additional data section.N)r r r r r r r rr@src@seZdZdZdS)ÚUnknownTSIGKeyz(A TSIG with an unknown key was received.N)r r r r r r r rrFsrc@sØeZdZdZd-dd„Zdd„Zdd„Zd.d d „Zd d „Zdd„Z dd„Z dd„Z e j jdddfdd„Ze j jdddfdd„Zd/dd„Zddddde jjfdd„Zd0d!d"„Zd1d#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„ZdS)2ÚMessagea, A DNS message. @ivar id: The query id; the default is a randomly chosen id. @type id: int @ivar flags: The DNS flags of the message. @see: RFC 1035 for an explanation of these flags. @type flags: int @ivar question: The question section. @type question: list of dns.rrset.RRset objects @ivar answer: The answer section. @type answer: list of dns.rrset.RRset objects @ivar authority: The authority section. @type authority: list of dns.rrset.RRset objects @ivar additional: The additional data section. @type additional: list of dns.rrset.RRset objects @ivar edns: The EDNS level to use. The default is -1, no Edns. @type edns: int @ivar ednsflags: The EDNS flags @type ednsflags: long @ivar payload: The EDNS payload size. The default is 0. @type payload: int @ivar options: The EDNS options @type options: list of dns.edns.Option objects @ivar request_payload: The associated request's EDNS payload size. @type request_payload: int @ivar keyring: The TSIG keyring to use. The default is None. @type keyring: dict @ivar keyname: The TSIG keyname to use. The default is None. @type keyname: dns.name.Name object @ivar keyalgorithm: The TSIG algorithm to use; defaults to dns.tsig.default_algorithm. Constants for TSIG algorithms are defined in dns.tsig, and the currently implemented algorithms are HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, and HMAC_SHA512. @type keyalgorithm: string @ivar request_mac: The TSIG MAC of the request message associated with this message; used when validating TSIG signatures. @see: RFC 2845 for more information on TSIG fields. @type request_mac: string @ivar fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @ivar original_id: TSIG original id; defaults to the message's id @type original_id: int @ivar tsig_error: TSIG error code; default is 0. @type tsig_error: int @ivar other_data: TSIG other data. @type other_data: string @ivar mac: The TSIG MAC for this message. @type mac: string @ivar xfr: Is the message being used to contain the results of a DNS zone transfer? The default is False. @type xfr: bool @ivar origin: The origin of the zone in messages which are used for zone transfers or for DNS dynamic updates. The default is None. @type origin: dns.name.Name object @ivar tsig_ctx: The TSIG signature context associated with this message. The default is None. @type tsig_ctx: hmac.HMAC object @ivar had_tsig: Did the message decoded from wire format have a TSIG signature? @type had_tsig: bool @ivar multi: Is this message part of a multi-message sequence? The default is false. This variable is used when validating TSIG signatures on messages which are part of a zone transfer. @type multi: bool @ivar first: Is this message standalone, or the first of a multi message sequence? This variable is used when validating TSIG signatures on messages which are part of a zone transfer. @type first: bool @ivar index: An index of rrsets in the message. The index key is (section, name, rdclass, rdtype, covers, deleting). Indexing can be disabled by setting the index to None. @type index: dict NcCsÂ|dkrtjjƒ|_n||_d|_g|_g|_g|_g|_d|_ d|_ d|_ g|_ d|_ d|_d|_tjj|_d|_d|_d|_d|_|j|_d|_d|_d|_d|_d|_d|_d|_i|_dS)NrrÚi,FTéÿÿÿÿ) ÚdnsZentropyZ random_16ÚidÚflagsÚquestionÚanswerÚ authorityÚ additionalÚednsÚ ednsflagsÚpayloadÚoptionsÚrequest_payloadÚkeyringÚkeynameÚtsigÚdefault_algorithmÚ keyalgorithmÚ request_macÚ other_dataÚ tsig_errorÚfudgeÚ original_idÚmacÚxfrÚoriginÚtsig_ctxÚhad_tsigÚmultiÚfirstÚindex)Úselfrr r rÚ__init__˜s: zMessage.__init__cCsdt|jƒdS)Nz)Úreprr)r5r r rÚ__repr__¸szMessage.__repr__cCs|jƒS)N)Úto_text)r5r r rÚ__str__»szMessage.__str__TcKstƒ}|jd|jƒ|jdtjjtjj|jƒƒƒtjj|j|j ƒ}|jdtjj|ƒƒ|jdtjj|jƒƒ|j dkrÂ|jd|j ƒ|j dkr²|jdtjj |j ƒƒ|jd|j ƒtjj |jƒ}|rà|jd ƒn |jd ƒx.|jD]$}|j|j||f|Žƒ|jd ƒqòW|�r,|jd ƒn |jd ƒx0|jD]&}|j|j||f|Žƒ|jd ƒ�q>W|�rz|jdƒn |jdƒx0|jD]&}|j|j||f|Žƒ|jd ƒ�qŒW|jdƒx0|jD]&}|j|j||f|Žƒ|jd ƒ�qÈW|jƒdd…S)z¶Convert the message to text. The I{origin}, I{relativize}, and any other keyword arguments are passed to the rrset to_wire() method. @rtype: string zid %d z opcode %s z rcode %s z flags %s rzedns %s z eflags %s z payload %d z;ZONE z ;QUESTION Ú z;PREREQ z;ANSWER z;UPDATE z ;AUTHORITY z ;ADDITIONAL Nrr)rÚwriterrÚopcoder:Ú from_flagsrÚrcoderrZ edns_to_textr Ú is_updaterrrrÚgetvalue)r5r/Ú relativizeÚkwÚsZrcrAÚrrsetr r rr:¾sJ              zMessage.to_textcCsæt|tƒsdS|j|jkrdS|j|jkr.dSx|jD]}||jkr6dSq6Wx|jD]}||jkrTdSqTWx|jD]}||jkrrdSqrWx|jD]}||jkr�dSq�Wx|jD]}||jkr®dSq®Wx|jD]}||jkrÌdSqÌWdS)zŠTwo messages are equal if they have the same content in the header, question, answer, and authority sections. @rtype: boolFT)Ú isinstancerrrrrr)r5ÚotherÚnr r rÚ__eq__õs2               zMessage.__eq__cCs |j|ƒ S)z0Are two messages not equal? @rtype: bool)rJ)r5rHr r rÚ__ne__szMessage.__ne__cCs®|jtjj@dks:|j|jks:tjj|jƒtjj|jƒkr>dStjj|j|jƒtjjkr\dStjj |jƒrndSx|j D]}||j krvdSqvWx|j D]}||j kr”dSq”WdS)z1Is other a response to self? @rtype: boolrFT) rrÚQRrr>r?r@rZNOERRORrAr)r5rHrIr r rÚ is_responses"       zMessage.is_responsecCsD||jkrdS||jkrdS||jkr*dS||jkr8dStdƒ‚dS)Nrréézunknown section)rrrrÚ ValueError)r5Úsectionr r rÚsection_number-s    zMessage.section_numberFc Cs |j|ƒ|||||f} |sb|jdk r>|jj| ƒ} | dk rb| Sn$x"|D]} | j|||||ƒrD| SqDW|sjt‚tjj|||||ƒ} |j| ƒ|jdk rœ| |j| <| S)aFind the RRset with the given attributes in the specified section. @param section: the section of the message to look in, e.g. self.answer. @type section: list of dns.rrset.RRset objects @param name: the name of the RRset @type name: dns.name.Name object @param rdclass: the class of the RRset @type rdclass: int @param rdtype: the type of the RRset @type rdtype: int @param covers: the covers value of the RRset @type covers: int @param deleting: the deleting value of the RRset @type deleting: int @param create: If True, create the RRset if it is not found. The created RRset is appended to I{section}. @type create: bool @param force_unique: If True and create is also True, create a new RRset regardless of whether a matching RRset exists already. @type force_unique: bool @raises KeyError: the RRset was not found and create was False @rtype: dns.rrset.RRset objectN) rRr4ÚgetÚmatchÚKeyErrorrrFZRRsetÚappend) r5rQÚnameÚrdclassÚrdtypeÚcoversÚdeletingÚcreateÚ force_uniqueÚkeyrFr r rÚ find_rrset9s"      zMessage.find_rrsetc Cs:y|j||||||||ƒ} Wntk r4d} YnX| S)aGet the RRset with the given attributes in the specified section. If the RRset is not found, None is returned. @param section: the section of the message to look in, e.g. self.answer. @type section: list of dns.rrset.RRset objects @param name: the name of the RRset @type name: dns.name.Name object @param rdclass: the class of the RRset @type rdclass: int @param rdtype: the type of the RRset @type rdtype: int @param covers: the covers value of the RRset @type covers: int @param deleting: the deleting value of the RRset @type deleting: int @param create: If True, create the RRset if it is not found. The created RRset is appended to I{section}. @type create: bool @param force_unique: If True and create is also True, create a new RRset regardless of whether a matching RRset exists already. @type force_unique: bool @rtype: dns.rrset.RRset object or NoneN)r_rU) r5rQrWrXrYrZr[r\r]rFr r rÚ get_rrsetgs  zMessage.get_rrsetrc KsR|dkr|jdkr|j}nd}|dkr,d}n |dkr8d}tjj|j|j||ƒ}x"|jD]}|j|j|j |j ƒqVWx"|j D]}|j tjj |f|ŽqzWx"|jD]}|j tjj|f|ŽqžW|jdkrÜ|j|j|j|j|jƒx"|jD]}|j tjj|f|ŽqäW|jƒ|jdk �rJ|j|j|j|j|j|j|j|j|j|j ƒ|j!|_!|j"ƒS)a7Return a string containing the message in DNS compressed wire format. Additional keyword arguments are passed to the rrset to_wire() method. @param origin: The origin to be appended to any relative names. @type origin: dns.name.Name object @param max_size: The maximum size of the wire format output; default is 0, which means 'the message's request payload, if nonzero, or 65536'. @type max_size: int @raises dns.exception.TooBig: max_size was exceeded @rtype: string riÿÿiN)#r"rZrendererZRendererrrrZ add_questionrWrYrXrZ add_rrsetÚANSWERrÚ AUTHORITYrZadd_ednsrr r!rÚ ADDITIONALZ write_headerr$Zadd_tsigr#r+r,r*r)r(r'r-Zget_wire)r5r/Zmax_sizerDÚrrFr r rÚto_wireŠs6        zMessage.to_wirei,rcCst||_|dkr$t|jjƒƒd|_nt|tƒr:tjj|ƒ}||_||_ ||_ |dkr^|j |_ n||_ ||_ ||_dS)awWhen sending, a TSIG signature using the specified keyring and keyname should be added. @param keyring: The TSIG keyring to use; defaults to None. @type keyring: dict @param keyname: The name of the TSIG key to use; defaults to None. The key must be defined in the keyring. 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. @type keyname: dns.name.Name or string @param fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @param original_id: TSIG original id; defaults to the message's id @type original_id: int @param tsig_error: TSIG error code; default is 0. @type tsig_error: int @param other_data: TSIG other data. @type other_data: string @param algorithm: The TSIG algorithm to use; defaults to dns.tsig.default_algorithm Nr)r#ÚlistÚkeysr$rGrrrWÚ from_textr'r+rr,r*r))r5r#r$r+r,r*r)Ú algorithmr r rÚuse_tsig¸s   zMessage.use_tsigécCsŒ|dks|dkrd}|dkr d}|dkr,|}|dkrFd}d}d}g}n$|tdƒM}||d>O}|dkrjg}||_||_||_||_||_dS) a_Configure EDNS behavior. @param edns: 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'. @type edns: int or bool or None @param ednsflags: EDNS flag values. @type ednsflags: int @param payload: The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle. @type payload: int @param request_payload: The EDNS payload size to use when sending this message. If not specified, defaults to the value of payload. @type request_payload: int or None @param options: The EDNS options @type options: None or list of dns.edns.Option objects @see: RFC 2671 NFrTrlÿ~ér)rrrr r!r")r5rrr r"r!r r rÚuse_ednsãs(  zMessage.use_ednscCsL|r*|jdkr|jƒ|jtjjO_n|jdkrH|jtjjM_dS)a Enable or disable 'DNSSEC desired' flag in requests. @param wanted: Is DNSSEC desired? If True, EDNS is enabled if required, and then the DO bit is set. If False, the DO bit is cleared if EDNS is enabled. @type wanted: bool rN)rrmrrrZDO)r5Zwantedr r rÚ want_dnssecs   zMessage.want_dnsseccCstjj|j|jƒS)z.Return the rcode. @rtype: int )rr@r?rr)r5r r rr@sz Message.rcodecCsjtjj|ƒ\}}|jdM_|j|O_|jtdƒM_|j|O_|jdkrf|jdkrfd|_dS)zPSet the rcode. @param rcode: the rcode @type rcode: int iðÿiÿÿÿrN)rr@Úto_flagsrrrr)r5r@ÚvalueZevaluer r rÚ set_rcode"szMessage.set_rcodecCstjj|jƒS)z/Return the opcode. @rtype: int )rr>r?r)r5r r rr>/szMessage.opcodecCs(|jdM_|jtjj|ƒO_dS)zTSet the opcode. @param opcode: the opcode @type opcode: int iÿ‡N)rrr>ro)r5r>r r rÚ set_opcode5szMessage.set_opcode)N)NT)Nr)rrrkNN)T)r r r r r6r9r;r:rJrKrMrRrÚ rdatatypeÚNONEr_r`rer%r&rjrmrnr@rqr>rrr r r rrKs0K  7  -  ! .) *  rc@s2eZdZdZd dd„Zdd„Zdd„Zd d „Zd S) Ú _WireReaderaþWire format reader. @ivar wire: the wire-format message. @type wire: string @ivar message: The message object being built @type message: dns.message.Message object @ivar current: When building a message object from wire format, this variable contains the offset from the beginning of wire of the next octet to be read. @type current: int @ivar updating: Is the message a dynamic update? @type updating: bool @ivar one_rr_per_rrset: Put each RR into its own RRset? @type one_rr_per_rrset: bool @ivar ignore_trailing: Ignore trailing junk at end of request? @type ignore_trailing: bool @ivar zone_rdclass: The class of the zone in messages which are DNS dynamic updates. @type zone_rdclass: int FcCs@tjj|ƒ|_||_d|_d|_tjj|_ ||_ ||_ ||_ dS)NrF) rZwiredataZ maybe_wrapÚwireÚmessageÚcurrentÚupdatingÚ rdataclassÚINÚ zone_rdclassÚ question_onlyÚone_rr_per_rrsetÚignore_trailing)r5rvrwr}r~rr r rr6Us z_WireReader.__init__c CsÀ|jr|dkrtjj‚x¤td|ƒD]–}tjj|j|jƒ\}}|j j dk rV|j |j j ƒ}|j||_t j d|j|j|jd…ƒ\}}|jd|_|j j|j j|||ddd�|jr"||_q"WdS)z¸Read the next I{qcount} records from the wire data and add them to the question section. @param qcount: the number of questions in the message @type qcount: intrrNz!HHéT)r\r])ryrÚ exceptionÚ FormErrorrrWÚ from_wirervrxrwr/rCÚstructÚunpackr_rr|)r5ÚqcountÚiÚqnameÚusedrYrXr r rÚ _get_question`s   z_WireReader._get_questionc CsH|js |jrd}nd}d}�x&td|ƒD�]}|j}tjj|j|jƒ\}}|} |jj dk rh|j |jj ƒ}|j||_t j d|j|j|jd…ƒ\} } } } |jd|_| tj jk�rn||jjk sÄ|rÈt‚| |j_| |j_| d@d?|j_g|j_|j}| }xj|dk�rdt j d |j||d …ƒ\}}|d }tjj||j||ƒ}|jjj|ƒ||}|d |}qüWd}�nÆ| tj jk�rH||jjk�o”||d k�sœt‚|jjdk�r²td ƒ‚|jjj| ƒ}|dk�rÖtd |ƒ‚| |j_tjj|j|j| ƒ\|j_|j_ tjj!|j| |t"t#j#ƒƒ|jj$||j| |jj%|jj&|jj'ƒ |j_%d|j_(nì| dk�rVd} |j�r†| tj)j*k�sz| tj)j+k�r†| }|j,} nd}|tj)j*k�s´|tj)j+k�rÂ||jj-k�rÂtj j+}d}n&tj.j| | |j|j| |jj ƒ}|j/ƒ}|jj0�r| tj j1k�rd}|jj2||| | ||d|ƒ}|dk �r4|j3|| ƒ|j| |_q(WdS)a/Read the next I{count} records from the wire data and add them to the specified section. @param section: the section of the message to which to add records @type section: list of dns.rrset.RRset objects @param count: the number of records to read @type count: intTFrNz!HHIHé iÿrlz!HHr€rz"got signed message without keyringzkey '%s' unknown)4ryr~rrxrrWrƒrvrwr/rCr„r…rsÚOPTrrr rrr!Zoption_from_wirerVZTSIGrr#rrSr$r%Zget_algorithm_and_macr'r-ZvalidateÚintÚtimer(r0r2r3r1rzÚANYrtr|rÚrdatarZr.ZSOAr_Úadd)r5rQÚcountr]Zseen_optr‡Zrr_startrWr‰Z absolute_namerYrXÚttlZrdlenrxZoptslenZotypeZolenÚoptZsecretr[rZÚrdrFr r rÚ _get_sectionxs¤                 z_WireReader._get_sectioncCsät|jƒ}|dkrt‚tjd|jdd…ƒ\|j_|j_}}}}d|_t j j |jjƒr\d|_ |j |ƒ|jrpdS|j|jj|ƒ|j|jj|ƒ|j|jj|ƒ|j r¶|j|kr¶t‚|jjrà|jjrà|jj rà|jjj|jƒdS)zNRead a wire format DNS message and build a dns.message.Message object.é z!HHHHHHNT)Úlenrvrr„r…rwrrrxrr>rAryrŠr}r–rrrrrr2r0r1Úupdate)r5Úlr†ZancountZaucountZadcountr r rÚreadÛs$ *  z_WireReader.readN)FFF)r r r r r6rŠr–r›r r r rru>s  crurFTc CsPtdd�} || _|| _|| _|| _|| _|| _|| _t|| || | ƒ} | j ƒ| S)a)Convert a DNS wire format message into a message object. @param keyring: The keyring to use if the message is signed. @type keyring: dict @param request_mac: If the message is a response to a TSIG-signed request, I{request_mac} should be set to the MAC of that request. @type request_mac: string @param xfr: Is this message part of a zone transfer? @type xfr: bool @param origin: If the message is part of a zone transfer, I{origin} should be the origin name of the zone. @type origin: dns.name.Name object @param tsig_ctx: The ongoing TSIG context, used when validating zone transfers. @type tsig_ctx: hmac.HMAC object @param multi: Is this message part of a multiple message sequence? @type multi: bool @param first: Is this message standalone, or the first of a multi message sequence? @type first: bool @param question_only: Read only up to the end of the question section? @type question_only: bool @param one_rr_per_rrset: Put each RR into its own RRset @type one_rr_per_rrset: bool @param ignore_trailing: Ignore trailing junk at end of request? @type ignore_trailing: bool @raises ShortHeader: The message is less than 12 octets long. @raises TrailingJunk: There were octets in the message past the end of the proper DNS message. @raises BadEDNS: An OPT record was in the wrong section, or occurred more than once. @raises BadTSIG: A TSIG record was not the last record of the additional data section. @rtype: dns.message.Message objectr)r) rr#r(r.r/r0r2r3rur›) rvr#r(r.r/r0r2r3r}r~rÚmÚreaderr r rrƒôs(  rƒc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú _TextReaderaText format reader. @ivar tok: the tokenizer @type tok: dns.tokenizer.Tokenizer object @ivar message: The message object being built @type message: dns.message.Message object @ivar updating: Is the message a dynamic update? @type updating: bool @ivar zone_rdclass: The class of the zone in messages which are DNS dynamic updates. @type zone_rdclass: int @ivar last_name: The most recently read name when building a message object from text format. @type last_name: dns.name.Name object cCs.||_tjj|ƒ|_d|_tjj|_d|_ dS)NF) rwrZ tokenizerÚ TokenizerÚtokÚ last_namerzr{r|ry)r5Útextrwr r rr6>s  z_TextReader.__init__cCsÀ|jjƒ}|j}|dkr*|jjƒ|j_�nˆ|dkrŒx>|jjƒ}|jƒsT|jj|ƒP|jjt jj |jƒB|j_q4Wt j j |jjƒrˆd|_ �n&|dkr¼|jjƒ|j_|jj|jjd>B|j_nö|dk�r|jjdkrÚd|j_xÖ|jjƒ}|jƒ�sþ|jj|ƒP|jjt jj|jƒB|j_qÜWn”|dk�rN|jjƒ|j_|jjdk�r²d|j_nd|d k�r„|jjƒ}|jjt j jt j j |ƒƒB|j_n.|d k�r®|jjƒ}|jjt jj |ƒƒnt‚|jjƒd S) z5Process one line from the text format header section.rrTrrlZeflagsrr r>r@N)r rSrpZget_intrwrÚ is_identifierÚungetrrrhr>rAryrrZedns_from_textr Z get_stringrorqr@rÚget_eol)r5rQÚtokenZwhatr¢r r rÚ _header_lineEsR               z_TextReader._header_linecCsô|jjdd�}|jƒs(tjj|jdƒ|_|j}|jjƒ}|jƒsHtj j ‚y,tj j|jƒ}|jjƒ}|jƒsrtj j ‚Wn:tj j k r”tj j ‚Ynt k r®tj j }YnXtjj|jƒ}|jj|jj|||ddd�|jræ||_|jjƒdS)z7Process one line from the text format question section.T)Ú want_leadingN)r\r])r rSÚ is_whitespacerrWrhrpr¡r£r�Ú SyntaxErrorrzÚ Exceptionr{rsrwr_rryr|r¥)r5rQr¦rWrXrYr r rÚ_question_liness.    z_TextReader._question_linec CsÌd}|jjdd�}|jƒs,tjj|jdƒ|_|j}|jjƒ}|jƒsLtj j ‚y*t |jdƒ}|jjƒ}|jƒsttj j ‚Wn6tj j k r–tj j ‚Ynt k r¬d}YnXyPtj j|jƒ}|jjƒ}|jƒsØtj j ‚|tj jksò|tj jk�rü|}|j}Wn>tj j k �r tj j ‚Ynt k �r<tj j}YnXtjj|jƒ}|jjƒ}|jƒ�sŠ|jj|ƒtjj|||jdƒ}|jƒ} n d}tjj} |jj||||| |d|jƒ} |dk �rÈ| j||ƒdS)zfProcess one line from the text format answer, authority, or additional data sections. NT)r¨r)r rSr©rrWrhrpr¡r£r�rªr�r«rzr�rtr|r{rsÚ is_eol_or_eofr¤r�rZrwr_ryr‘) r5rQr[r¦rWr“rXrYr•rZrFr r rÚ_rr_line�sT                z_TextReader._rr_linecCsä|j}d}xÔ|jjddƒ}|jƒr$P|jƒrÈ|jjƒ}|dkrF|j}nv|dksV|dkrf|j}|jj }nV|dksv|dkr†|j }|jj }n6|dks–|d kr¦|j }|jj }n|d kr¼|j }|jj }|jjƒq |jj|ƒ||ƒq WdS) zNRead a text format DNS message and build a dns.message.Message object.NTZHEADERZQUESTIONZZONEraZPREREQrbZUPDATErc)r§r rSr­Z is_commentrpÚupperr¬rwrr®rrrr¥r¤)r5Z line_methodrQr¦Úur r rr›Ås4      z_TextReader.readN) r r r r r6r§r¬r®r›r r r rrž,s .5ržcCstƒ}t||ƒ}|jƒ|S)zæConvert the text format message into a message object. @param text: The text format message. @type text: string @raises UnknownHeaderField: @raises dns.exception.SyntaxError: @rtype: dns.message.Message object)rržr›)r¢rœr�r r rrhås  rhc CsFt}d}t||ƒr"t||ƒ}d}nd}z t|ƒ}Wd|r@|jƒX|S)aRead the next text format message from the specified file. @param f: file or string. If I{f} is a string, it is treated as the name of a file to open. @raises UnknownHeaderField: @raises dns.exception.SyntaxError: @rtype: dns.message.Message objectZrUTFN)rrGÚopenrhÚclose)ÚfZstr_typeZoptsZ want_closerœr r rÚ from_fileús     r´c Cst|tƒrtjj|ƒ}t|tƒr,tjj|ƒ}t|tƒrBtjj|ƒ}tƒ} | jtjj O_| j | j |||ddd�i} |dk r’|| d<|dkr’d}|dk r®|| d<|dkr®d}|dk rÊ|| d<|dkrÊd}|dk ræ|| d<|dkræd}|| d <| j f| Ž| j |ƒ| S) aVMake 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. @param qname: The query name. @type qname: dns.name.Name object or string @param rdtype: The desired rdata type. @type rdtype: int @param rdclass: The desired rdata class; the default is class IN. @type rdclass: int @param use_edns: The EDNS level to use; the default is None (no EDNS). See the description of dns.message.Message.use_edns() for the possible values for use_edns and their meanings. @type use_edns: int or bool or None @param want_dnssec: Should the query indicate that DNSSEC is desired? @type want_dnssec: bool @param ednsflags: EDNS flag values. @type ednsflags: int @param payload: The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle. @type payload: int @param request_payload: The EDNS payload size to use when sending this message. If not specified, defaults to the value of payload. @type request_payload: int or None @param options: The EDNS options @type options: None or list of dns.edns.Option objects @see: RFC 2671 @rtype: dns.message.Message objectT)r\r]Nrrr r"r!r)rGrrrWrhrsrzrrÚRDr_rrmrn) rˆrYrXrmrnrr r"r!rœÚkwargsr r rÚ make_querys>$        r·é é,cCsº|jtjj@rtjjdƒ‚tjj|jƒ}tjj|jtjj@B|_|rV|jtjj O_|j |j ƒƒt |j ƒ|_ |jdkrŒ|jdd||jƒ|jr¶|j|j|j|ddd|jƒ|j|_|S)a Make 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. @param query: the query to respond to @type query: dns.message.Message object @param recursion_available: should RA be set in the response? @type recursion_available: bool @param our_payload: payload size to advertise in EDNS responses; default is 8192. @type our_payload: int @param fudge: TSIG time fudge; default is 300 seconds. @type fudge: int @rtype: dns.message.Message objectz&specified query message is not a queryrNr)rrrLr�r‚rwrrrµZRArrr>rfrrrmr r1rjr#r$r'r-r()ZqueryZrecursion_availableZ our_payloadr+Zresponser r rÚ make_response\s   rº) NrFNNFTFFF)Fr¸r¹).r Z __future__rÚiorr„rŽZdns.ednsrZ dns.exceptionZ dns.flagsZdns.nameZ dns.opcodeZ dns.entropyZ dns.rcodeZ dns.rdataZdns.rdataclassZ dns.rdatatypeZ dns.rrsetZ dns.rendererZdns.tsigZ dns.wiredataZ_compatrrrr�r‚rrZ DNSExceptionrrrrÚobjectrrurƒržrhr´rzr{r·rºr r r rÚsX  v7 5:F