o ¯b¥‚ã@sÐdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z ddl mZmZmZddlmZmZddlmZdd lmZmZmZmZdd lmZmZmZgd ¢Z ej!Z!d d „Z"dd„Z#dd„Z$dd„Z%dZ&e'ddƒ\Z(Z)Z*Z+Z,Z-Z.Z/Z0Z1Z2Z3Z4Z5Z6Z7Z8Z9dZ:dZ;dZdZ?dZ@dZAdZBd ZCie(d!“e)d"“e*d#“e+d$“e,d%“e-d&“e.d'“e/d(“e0d)“e1d*“e2d+“e3d,“e4d-“e5d.“e6d/“e7d0“e8d1“e9d2e:d3e;d4ed7e?d8e@d9eAd:eBd;eCdƒ\ZEZFZGZHZIeEd?eFd@eGdAeHdBeIdCiZJdDdE„eeD K¡eJ K¡ƒDƒZLe'ddFƒ\ZMZNZOZPdGZQeMdHeNdIeOdJePdKeQdLiZRdMdE„eR K¡DƒZSe'dNƒ\ZTZUZVdOZWdFZXe'dPƒ\ZYZZZ[Z\Z]Z^dQZ_e'dQdƒ\Z`ZaZbGdRdS„dSeƒZcddTldmeZemfZfmgZgdUdV„ZhdWdX„ZidYdZ„Zjd[d\„Zkd]d^„ZlGd_d`„d`eƒZmGdadb„dbemecƒZneemƒGdcdd„ddƒƒZoeemƒGdedf„dfƒƒZpeeemƒGdgdh„dhƒƒƒZqeemƒGdidj„djejrejsƒƒZteemƒGdkdl„dlejrejsƒƒZueemƒGdmdn„dnejsƒƒZveenƒGdodp„dpejrejsƒƒZwGdqdr„drewƒZxGdsdt„dtewƒZyGdudv„dvewƒZzGdwdx„dxewƒZ{Gdydz„dzewƒZ|Gd{d|„d|ewƒZ}Gd}d~„d~ewƒZ~Gdd€„d€ewƒZGdd‚„d‚ewƒZ€eenƒGdƒd„„d„ejsƒƒZeenƒGd…d†„d†ejsejrƒƒZ‚eenƒGd‡dˆ„dˆejrejsƒƒZƒeenƒGd‰dŠ„dŠejsejrƒƒZ„eenƒGd‹dŒ„dŒejsejrƒƒZ…eenƒGddŽ„dŽejrejsƒƒZ†eenƒGdd„dejsejrƒƒZ‡eenƒGd‘d’„d’ejsejrƒƒZˆeenƒGd“d”„d”ejrejsƒƒZ‰eenƒGd•d–„d–ejsejrƒƒZŠeenƒGd—d˜„d˜ejrejsƒƒZ‹eenƒGd™dš„dšejsejrƒƒZŒeenƒGd›dœ„dœejrejsƒƒZeenƒGddž„džejsejrƒƒZŽeenƒGdŸd „d ejsejrƒƒZeenƒGd¡d¢„d¢ejsejrƒƒZGd£d¤„d¤eƒZ‘eenƒGd¥d¦„d¦ejsejrƒƒZ’d§d¨„Z“d©dª„Z” d·d«d¬„Z•Gd­d®„d®ejsƒZ–Gd¯d°„d°ejsƒZ—Gd±d²„d²ƒZ˜Gd³d´„d´e˜ej™ƒZšGdµd¶„d¶e˜ej›ƒZœdS)¸zU DNS protocol implementation. Future Plans: - Get rid of some toplevels, maybe. éN)ÚBytesIO)Úchain)ÚOptionalÚ SupportsIntÚUnion)Ú AttributeÚ InterfaceÚ implementer)ÚdeferÚprotocol)ÚCannotListenError)ÚfailureÚlogÚ randbytesÚutil)ÚcmpÚ comparableÚ nativeString)dÚ IEncodableÚIRecordÚIEncodableRecordÚAÚA6ÚAAAAÚAFSDBÚCNAMEÚDNAMEÚHINFOÚMAILAÚMAILBÚMBÚMDÚMFÚMGÚMINFOÚMRÚMXÚNAPTRÚNSÚNULLÚOPTÚPTRÚRPÚSOAÚSPFÚSRVÚTXTÚSSHFPÚTSIGÚWKSÚANYÚCHÚCSÚHSÚINÚ ALL_RECORDSÚAXFRÚIXFRÚEFORMATÚENAMEÚENOTIMPÚEREFUSEDÚESERVERÚ EBADVERSIONÚEBADSIGÚEBADKEYÚEBADTIMEÚRecord_AÚ Record_A6Ú Record_AAAAÚ Record_AFSDBÚ Record_CNAMEÚ Record_DNAMEÚ Record_HINFOÚ Record_MBÚ Record_MDÚ Record_MFÚ Record_MGÚ Record_MINFOÚ Record_MRÚ Record_MXÚ Record_NAPTRÚ Record_NSÚ Record_NULLÚ Record_PTRÚ Record_RPÚ Record_SOAÚ Record_SPFÚ Record_SRVÚ Record_SSHFPÚ Record_TSIGÚ Record_TXTÚ Record_WKSÚ UnknownRecordÚ QUERY_CLASSESÚ QUERY_TYPESÚ REV_CLASSESÚ REV_TYPESÚ EXT_QUERIESÚCharstrÚMessageÚNameÚQueryÚRRHeaderÚ SimpleRecordÚDNSDatagramProtocolÚDNSMixinÚ DNSProtocolÚOKÚ OP_INVERSEÚ OP_NOTIFYÚOP_QUERYÚ OP_STATUSÚ OP_UPDATEÚPORTÚAuthoritativeDomainErrorÚDNSQueryTimeoutErrorÚ DomainErrorcCs t|gƒS)z Construct a bytes object representing a single byte with the given ordinal value. @type ordinal: L{int} @rtype: L{bytes} ©Úbytes)Úordinal©r{ú3/usr/lib/python3/dist-packages/twisted/names/dns.pyÚ _ord2bytesˆs r}cCst|ƒdd…S)z¦ Represent a mostly textful bytes object in a way suitable for presentation to an end user. @param bytes: The bytes to represent. @rtype: L{str} éN)Úreprrxr{r{r|Ú _nicebytes“sr€cCsd d dd„|Dƒ¡¡S)z¶ Represent a list of mostly textful bytes objects in a way suitable for presentation to an end user. @param list: The list of bytes to represent. @rtype: L{str} z[{}]ú, cSsg|]}t|ƒ‘qSr{)r€)Ú.0Úbr{r{r|Ú ¦sz"_nicebyteslist..)ÚformatÚjoin)Úlistr{r{r|Ú_nicebyteslistžsrˆcCst dtjddd¡dS)zƒ Wrapper around L{twisted.python.randbytes.RandomFactory.secureRandom} to return 2 random bytes. @rtype: L{bytes} ÚHéT)Úfallbackr)ÚstructÚunpackrÚ secureRandomr{r{r{r|Ú randomSource©sré5r~ééé!é#é&é'é)é,écéùéúrr(r!r"rr-r r#r%r)r3r+rr$r&r0r,rrr/r'rrr*r1r.ÚTKEYr2éûér;r:rrr9cCói|]\}}||“qSr{r{©r‚ÚkÚvr{r{r|Ú ór£ééÿr8r6r5r7r4cCrŸr{r{r r{r{r|r£r¤ééééc@seZdZdZedƒZdS)rz0 A single entry in a zone of authority. z,An indicator of what kind of record this is.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚTYPEr{r{r{r|rs r)rurvrwcCs2|dvrdgS| d¡}|ddkr| d¡|S)a2 Split a domain name into its constituent labels. @type name: L{bytes} @param name: A fully qualified domain name (with or without a trailing dot). @return: A L{list} of labels ending with an empty label representing the DNS root zone. @rtype: L{list} of L{bytes} )óó.r°r±éÿÿÿÿ)ÚsplitÚappend)ÚnameÚlabelsr{r{r|Ú _nameToLabels*s     r·cCs>t|tƒr | d¡}t|tƒstd tjtj|t|ƒ¡ƒ‚|S)aÚ Coerce a domain name string to bytes. L{twisted.names} represents domain names as L{bytes}, but many interfaces accept L{bytes} or a text string (L{unicode} on Python 2, L{str} on Python 3). This function coerces text strings using IDNA encoding --- see L{encodings.idna}. Note that DNS is I{case insensitive} but I{case preserving}. This function doesn't normalize case, so you'll still need to do that whenever comparing the strings it returns. @param domain: A domain name. If passed as a text string it will be C{idna} encoded. @type domain: L{bytes} or L{str} @returns: L{bytes} suitable for network transmission. @rtype: L{bytes} @since: Twisted 20.3.0 Úidnaz+Expected {} or {} but found {!r} of type {})Ú isinstanceÚstrÚencoderyÚ TypeErrorr…r«Útype)Údomainr{r{r|Ú domainString>s   ÿÿr¿cCs.t| ¡ƒ}t| ¡ƒ}|t|ƒ d…|kS)a) Test whether C{descendantName} is equal to or is a I{subdomain} of C{ancestorName}. The names are compared case-insensitively. The names are treated as byte strings containing one or more DNS labels separated by B{.}. C{descendantName} is considered equal if its sequence of labels exactly matches the labels of C{ancestorName}. C{descendantName} is considered a I{subdomain} if its sequence of labels ends with the labels of C{ancestorName}. @type descendantName: L{bytes} @param descendantName: The DNS subdomain name. @type ancestorName: L{bytes} @param ancestorName: The DNS parent or ancestor domain name. @return: C{True} if C{descendantName} is equal to or if it is a subdomain of C{ancestorName}. Otherwise returns C{False}. N)r·ÚlowerÚlen)ÚdescendantNameÚ ancestorNameÚdescendantLabelsÚancestorLabelsr{r{r|Ú_isSubdomainOf_s  rÆcCsd}t|tƒr | d¡}t|tƒrF| ¡ ¡}|D]\}}| |¡r0tt|dd…ƒ|ƒSqzt|ƒ}W|St yEt d|ƒ‚w|S)aE Parse a string description of an interval into an integer number of seconds. @param s: An interval definition constructed as an interval duration followed by an interval unit. An interval duration is a base ten representation of an integer. An interval unit is one of the following letters: S (seconds), M (minutes), H (hours), D (days), W (weeks), or Y (years). For example: C{"3S"} indicates an interval of three seconds; C{"5D"} indicates an interval of five days. Alternatively, C{s} may be any non-string and it will be returned unmodified. @type s: text string (L{bytes} or L{str}) for parsing; anything else for passthrough. @return: an L{int} giving the interval represented by the string C{s}, or whatever C{s} is if it is not a string. ))ÚSr~)ÚMé<)r‰i)ÚDi€Q)ÚWi€: )ÚYi€3áÚasciiNr²z!Invalid time interval specifier: ) r¹ryÚdecoderºÚupperÚstripÚendswithÚintÚfloatÚ ValueError)ÚsÚsuffixesÚsuffÚmultr{r{r|Ústr2time}s       ÿ  þ ÿrÙcCs| |¡}t|ƒ|kr t‚|S©N)ÚreadrÁÚEOFError)ÚfileÚlÚbuffr{r{r|Ú readPrecisely¥s  ràc@s$eZdZdZddd„Zddd„ZdS)rzË Interface for something which can be encoded to and decoded to the DNS wire format. A binary-mode file object (such as L{io.BytesIO}) is used as a buffer when encoding or decoding. NcCódS)aô Write a representation of this object to the given file object. @type strio: File-like object @param strio: The buffer to write to. It must have a C{tell()} method. @type compDict: L{dict} of L{bytes} to L{int} r L{None} @param compDict: A mapping of names to byte offsets that have already been written to the buffer, which may be used for compression (see RFC 1035 section 4.1.4). When L{None}, encode without compression. Nr{)ÚstrioÚcompDictr{r{r|r»µózIEncodable.encodecCrá)aê Reconstruct an object from data read from the given file object. @type strio: File-like object @param strio: A seekable buffer from which bytes may be read. @type length: L{int} or L{None} @param length: The number of bytes in this RDATA field. Most implementations can ignore this value. Only in the case of records similar to TXT where the total length is in no way encoded in the data is it necessary. Nr{)râÚlengthr{r{r|rÎÃräzIEncodable.decoderÚ)r«r¬r­r®r»rÎr{r{r{r|r¬s rc@seZdZdZdS)rz` Interface for DNS records that can be encoded and decoded. @since: Twisted 21.2.0 N)r«r¬r­r®r{r{r{r|rÓsrc@sReZdZddd„Zddd„Zddd„Zd ed efd d „Zd d„Z d e fdd„Z dS)rer°cCs"t|tƒs t|›dƒ‚||_dS)Nz is not a byte string)r¹ryrÔÚstring)Úselfrær{r{r|Ú__init__Ýs  zCharstr.__init__NcCs*|j}t|ƒ}| t|ƒ¡| |¡dS)zÓ Encode this Character string into the appropriate byte format. @type strio: file @param strio: The byte representation of this Charstr will be written to this file. N)rærÁÚwriter})rçrârãræÚindr{r{r|r»âszCharstr.encodecCs$d|_tt|dƒƒ}t||ƒ|_dS)a  Decode a byte string into this Charstr. @type strio: file @param strio: Bytes will be read from this file until the full string is decoded. @raise EOFError: Raised when there are not enough bytes available from C{strio}. r°r~N)ræÚordrà)rçrârårÞr{r{r|rÎïs zCharstr.decodeÚotherÚreturncCst|tƒr |j|jkStSrÚ)r¹reræÚNotImplemented©rçrìr{r{r|Ú__eq__þs  zCharstr.__eq__cCó t|jƒSrÚ)Úhashræ©rçr{r{r|Ú__hash__ó zCharstr.__hash__cCrñ)zI Represent this L{Charstr} instance by its string value. )rrærór{r{r|Ú__str__ó zCharstr.__str__©r°rÚ) r«r¬r­rèr»rÎÚobjectÚboolrðrôrºrör{r{r{r|reÛs   rec@sVeZdZdZddd„Zddd„Zddd „Zd ed efd d „Z dd„Z d e fdd„Z dS)rgz¸ A name in the domain name system, made up of multiple labels. For example, I{twistedmatrix.com}. @ivar name: A byte string giving the name. @type name: L{bytes} r°cCst|ƒ|_dS)zM @param name: A name. @type name: L{bytes} or L{str} N)r¿rµ)rçrµr{r{r|rèsz Name.__init__NcCs¶|j}|rT|dur%||vr| t dd||B¡¡dS| ¡tj||<| d¡}|dkr>|d|…||dd…}}n|}d}t|ƒ}| t |ƒ¡| |¡|s| d¡dS)a¡ Encode this Name into the appropriate byte format. @type strio: file @param strio: The byte representation of this Name will be written to this file. @type compDict: dict @param compDict: dictionary of Names that have already been encoded and whose addresses may be backreferenced by this Name (for the purpose of reducing the message size). Nú!HiÀr±rr~ó) rµrérŒÚpackÚtellrfÚ headerSizeÚfindrÁr})rçrârãrµrêÚlabelr{r{r|r»s"    ðz Name.encodecCsÈtƒ}d|_d} tt|dƒƒ}|dkr|dkr| |¡dS|d?dkrM|d@d>tt|dƒƒB}||vr:td ƒ‚| |¡|dkrG| ¡}| |¡qt||ƒ}|jdkr[||_n|jd ||_q ) a Decode a byte string into this Name. @type strio: file @param strio: Bytes will be read from this file until the full Name is decoded. @raise EOFError: Raised when there are not enough bytes available from C{strio}. @raise ValueError: Raised when the name cannot be decoded (for example, because it contains a loop). r°rr~Nr©r§é?éz Compression loop in encoded namer±)ÚsetrµrëràÚseekrÔÚaddrþ)rçrâråÚvisitedÚoffrÞÚnew_offrr{r{r|rÎ?s.      íz Name.decoderìrícCs"t|tƒr|j ¡|j ¡kStSrÚ)r¹rgrµrÀrîrïr{r{r|rðes z Name.__eq__cCrñrÚ©ròrµrór{r{r|rôjrõz Name.__hash__cCrñ)zE Represent this L{Name} instance by its string name. ©rrµrór{r{r|römr÷z Name.__str__rørÚ) r«r¬r­r®rèr»rÎrùrúrðrôrºrör{r{r{r|rg s   !&rgc@sveZdZdZdeefdeeefde de fdd„Z dd d „Z dd d „Z d d„Z dd„Zdefdd„Zdefdd„ZdS)rhzú Represent a single DNS query. @ivar name: The name about which this query is requesting information. @type name: L{Name} @ivar type: The query type. @type type: L{int} @ivar cls: The query class. @type cls: L{int} r°rµr½ÚclscCst|ƒ|_||_||_dS)zØ @type name: L{bytes} or L{str} @param name: See L{Query.name} @type type: L{int} @param type: The query type. @type cls: L{int} @param cls: The query class. N)rgrµr½r ©rçrµr½r r{r{r|rè„s  zQuery.__init__NcCs*|j ||¡| t d|j|j¡¡dS©Nú!HH)rµr»rérŒrýr½r ©rçrârãr{r{r|r»“sz Query.encodecCs.|j |¡t|dƒ}t d|¡\|_|_dS)Nr¨r)rµrÎràrŒrr½r )rçrârårßr{r{r|rΗs  z Query.decodecCst|jj ¡|j|jfƒSrÚ)ròrµrÀr½r rór{r{r|rôœszQuery.__hash__cCs<t|tƒrt|jj ¡|j|jf|jj ¡|j|jfƒStSrÚ)r¹rhrrµrÀr½r rîrïr{r{r|Ú__cmp__Ÿs þz Query.__cmp__rícCsLt |jt |jd|j¡¡}t |jd|j¡}d|j›d|›d|›dS)Nú UNKNOWN (%d)z)raÚgetr½rdr`r rµ©rçÚtÚcr{r{r|rö§s ÿz Query.__str__cCs d|jj›d|j›d|j›dS)NzQuery(rú))rµr½r rór{r{r|Ú__repr__®ó zQuery.__repr__rÚ)r«r¬r­r®rr8rryrºrÒrèr»rÎrôrrörr{r{r{r|rhts&  rhc@szeZdZdZddd„fddddd d fZd Z  ddd„Zedd„ƒZedd„ƒZ ddd„Z ddd„Z e dd„ƒZ dS)Ú _OPTHeaderaZ An OPT record header. @ivar name: The DNS name associated with this record. Since this is a pseudo record, the name is always an L{Name} instance with value b'', which represents the DNS root zone. This attribute is a readonly property. @ivar type: The DNS record type. This is a fixed value of 41 C{dns.OPT} for OPT Record. This attribute is a readonly property. @see: L{_OPTHeader.__init__} for documentation of other public instance attributes. @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.2} @since: 13.2 rµcCrñrÚr )Únr{r{r|ÚÉs z_OPTHeader.r½ÚudpPayloadSizeÚ extendedRCODEÚversionÚdnssecOKÚoptions)rµr½rr r!r"r#érFNcCs.||_||_||_||_|durg}||_dS)a° @type udpPayloadSize: L{int} @param udpPayloadSize: The number of octets of the largest UDP payload that can be reassembled and delivered in the requestor's network stack. @type extendedRCODE: L{int} @param extendedRCODE: Forms the upper 8 bits of extended 12-bit RCODE (together with the 4 bits defined in [RFC1035]. Note that EXTENDED-RCODE value 0 indicates that an unextended RCODE is in use (values 0 through 15). @type version: L{int} @param version: Indicates the implementation level of the setter. Full conformance with this specification is indicated by version C{0}. @type dnssecOK: L{bool} @param dnssecOK: DNSSEC OK bit as defined by [RFC3225]. @type options: L{list} @param options: A L{list} of 0 or more L{_OPTVariableOption} instances. N©rr r!r"r#)rçrr r!r"r#r{r{r|rèÜs  z_OPTHeader.__init__cCstdƒS)a/ A readonly property for accessing the C{name} attribute of this record. @return: The DNS name associated with this record. Since this is a pseudo record, the name is always an L{Name} instance with value b'', which represents the DNS root zone. r°)rgrór{r{r|rµs z_OPTHeader.namecCstS)zÌ A readonly property for accessing the C{type} attribute of this record. @return: The DNS record type. This is a fixed value of 41 (C{dns.OPT} for OPT Record. )r*rór{r{r|r½s z_OPTHeader.typecCshtƒ}|jD]}| |¡q| ¡}t|jj|j|j|jd>|j d>B|j d>Bt |ƒd ||¡dS)a© Encode this L{_OPTHeader} instance to bytes. @type strio: file @param strio: the byte representation of this L{_OPTHeader} will be written to this file. @type compDict: L{dict} or L{None} @param compDict: A dictionary of backreference addresses that have already been written to this stream and that may be used for DNS name compression. érªé)rµr½r ÚttlÚpayloadN) rr#r»Úgetvaluerirµr½rr r!r"r_)rçrârãrƒÚoÚ optionBytesr{r{r|r»s  ûz_OPTHeader.encodecCsXtƒ}| ||¡tt||jƒƒ|_| |¡}|jD]}|dvr)t||t ||ƒƒqdS)a Decode bytes into an L{_OPTHeader} instance. @type strio: file @param strio: Bytes will be read from this file until the full L{_OPTHeader} is decoded. @type length: L{int} or L{None} @param length: Not used. )rµr½N) rirÎr_ràÚrdlengthr)Ú fromRRHeaderÚcompareAttributesÚsetattrÚgetattr)rçrâråÚhÚ newOptHeaderÚattrNamer{r{r|rÎ6s   €þz_OPTHeader.decodecCsŠd}|jdur.g}t|jjƒ}t|jjƒ}| ¡|kr.tƒ}| |¡| |¡| ¡|ks||j|j d?|j d?d@|j d@d?|dS)ai A classmethod for constructing a new L{_OPTHeader} from the attributes and payload of an existing L{RRHeader} instance. @type rrHeader: L{RRHeader} @param rrHeader: An L{RRHeader} instance containing an L{UnknownRecord} payload. @return: An instance of L{_OPTHeader}. @rtype: L{_OPTHeader} Nr&rªr¦iÿÿr'r%) r)rÚdatarÁrþÚ_OPTVariableOptionrÎr´r r()r ÚrrHeaderr#Ú optionsBytesÚoptionsBytesLengthr+r{r{r|r.Ls"       ý  ûz_OPTHeader.fromRRHeader)r$rrFNrÚ)r«r¬r­r®ÚshowAttributesr/rèÚpropertyrµr½r»rÎÚ classmethodr.r{r{r{r|r²s2 ù   ú)   rc@sBeZdZdZddeffZdZdZddd „Zdd d „Z dd d„Z d S)r6zð A class to represent OPT record variable options. @see: L{_OPTVariableOption.__init__} for documentation of public instance attributes. @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.2} @since: 13.2 Úcoder5©r=r5rrr°cCs||_||_dS)zŒ @type code: L{int} @param code: The option code @type data: L{bytes} @param data: The option data Nr>)rçr=r5r{r{r|rès z_OPTVariableOption.__init__NcCs(| t |j|jt|jƒ¡|j¡dS)a° Encode this L{_OPTVariableOption} to bytes. @type strio: file @param strio: the byte representation of this L{_OPTVariableOption} will be written to this file. @type compDict: L{dict} or L{None} @param compDict: A dictionary of backreference addresses that have already been written to this stream and that may be used for DNS name compression. N)rérŒrýÚ_fmtr=rÁr5rr{r{r|r»Šs( z_OPTVariableOption.encodecCs:t |j¡}t||ƒ}t |j|¡\|_}t||ƒ|_dS)a  Decode bytes into an L{_OPTVariableOption} instance. @type strio: file @param strio: Bytes will be read from this file until the full L{_OPTVariableOption} is decoded. @type length: L{int} or L{None} @param length: Not used. N)rŒÚcalcsizer?ràrr=r5)rçrârårÞrßr{r{r|rΙs z_OPTVariableOption.decode)rr°rÚ) r«r¬r­r®rr:r/r?rèr»rÎr{r{r{r|r6ms   r6c @sŠeZdZdZdZdZdZdZdee dddfde e e fd e d e d ed eed ef dd„Zddd„Zddd„Zdd„Zde fdd„ZeZdS)riak A resource record header. @cvar fmt: L{str} specifying the byte format of an RR. @ivar name: The name about which this reply contains information. @type name: L{Name} @ivar type: The query type of the original request. @type type: L{int} @ivar cls: The query class of the original request. @ivar ttl: The time-to-live for this record. @type ttl: L{int} @ivar payload: The record described by this header. @type payload: L{IEncodableRecord} or L{None} @ivar auth: A L{bool} indicating whether this C{RRHeader} was parsed from an authoritative message. )rµr½r r(r)Úauthz!HHIHNr°rFrµr½r r(r)rAc Cs†|durdn|j}|dur!||kr!tdt ||¡t ||¡fƒ‚t|ƒ}|dkr-tdƒ‚t|ƒ|_||_||_||_ ||_ ||_ dS)aÅ @type name: L{bytes} or L{str} @param name: See L{RRHeader.name} @type type: L{int} @param type: The query type. @type cls: L{int} @param cls: The query class. @type ttl: L{int} @param ttl: Time to live for this record. This will be converted to an L{int}. @type payload: L{IEncodableRecord} or L{None} @param payload: An optional Query Type specific data object. @raises TypeError: if the ttl cannot be converted to an L{int}. @raises ValueError: if the ttl is negative. @raises ValueError: if the payload type is not equal to the C{type} argument. Nz0Payload type (%s) does not match given type (%s)rzTTL cannot be negative) r¯rÔrarrÒrgrµr½r r(r)rA) rçrµr½r r(r)rAÚ payloadTypeÚ integralTTLr{r{r|rèËs$  þÿÿ  zRRHeader.__init__c CsŒ|j ||¡| t |j|j|j|jd¡¡|j rD|  ¡}|j  ||¡|  ¡}|  |dd¡| t d||¡¡|  |d¡dSdS)NrrŠrû) rµr»rérŒrýÚfmtr½r r(r)rþr)rçrârãÚprefixÚaftr{r{r|r»s úzRRHeader.encodecCsH|j |¡t |j¡}t||ƒ}t |j|¡}|\|_|_|_ |_ dSrÚ) rµrÎrŒr@rDràrr½r r(r-)rçrârårÞrßÚrr{r{r|rÎ s   zRRHeader.decodecCs|jSrÚ©rArór{r{r|ÚisAuthoritativeszRRHeader.isAuthoritativerícCsRt |jt |jd|j¡¡}t |jd|j¡}d|j|||j|jr%dp&dfS)Nrz-ÚTrueÚFalse) rarr½rdr`r rµr(rArr{r{r|rösÿ ûzRRHeader.__str__rÚ)r«r¬r­r®r/rDr-ÚcachedResponserr8rryrºrÒrrrrúrèr»rÎrIrörr{r{r{r|riªs<ù þýüûú ù 5  ric@sTeZdZUdZdZdZdZeee d<dZ ddd„Z dd d „Z dd d „Z d d„ZdS)rja  A Resource Record which consists of a single RFC 1035 domain-name. @type name: L{Name} @ivar name: The name associated with this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. )©rµrµú%sr()rµr(Nr¯r°cCst|ƒ|_t|ƒ|_dS)z^ @param name: See L{SimpleRecord.name} @type name: L{bytes} or L{str} N)rgrµrÙr()rçrµr(r{r{r|rè8s zSimpleRecord.__init__cCs|j ||¡dSrÚ)rµr»rr{r{r|r»@szSimpleRecord.encodecCstƒ|_|j |¡dSrÚ)rgrµrΩrçrârår{r{r|rÎCszSimpleRecord.decodecCrñrÚr rór{r{r|rôGrõzSimpleRecord.__hash__©r°NrÚ)r«r¬r­r®r:r/r¯rrÒÚ__annotations__rµrèr»rÎrôr{r{r{r|rj%s      rjc@óeZdZdZeZdZdS)rTz& An authoritative nameserver. r(N)r«r¬r­r®r(r¯Ú fancybasenamer{r{r{r|rTLórTc@rR)rMzX A mail destination. This record type is obsolete. @see: L{Record_MX} r!N)r«r¬r­r®r!r¯rSr{r{r{r|rMUórMc@rR)rNzV A mail forwarder. This record type is obsolete. @see: L{Record_MX} r"N)r«r¬r­r®r"r¯rSr{r{r{r|rNbrUrNc@rR)rIz* The canonical name for an alias. rN)r«r¬r­r®rr¯rSr{r{r{r|rIorTrIc@rR)rLzJ A mailbox domain name. This is an experimental record type. r N)r«r¬r­r®r r¯rSr{r{r{r|rLxórLc@rR)rOzH A mail group member. This is an experimental record type. r#N)r«r¬r­r®r#r¯rSr{r{r{r|rOƒrVrOc@rR)rQzN A mail rename domain name. This is an experimental record type. r%N)r«r¬r­r®r%r¯rSr{r{r{r|rQŽrVrQc@rR)rVz A domain name pointer. r+N)r«r¬r­r®r+r¯rSr{r{r{r|rV™rTrVc@rR)rJa[ A non-terminal DNS name redirection. This record type provides the capability to map an entire subtree of the DNS name space to another domain. It differs from the CNAME record which maps a single node of the name space. @see: U{http://www.faqs.org/rfcs/rfc2672.html} @see: U{http://www.faqs.org/rfcs/rfc3363.html} rN)r«r¬r­r®rr¯rSr{r{r{r|rJ¢s rJc@s\eZdZdZdZeZdZddd„Zddd„Z dd d „Z d d „Z d e fdd„Z e Zdd„ZdS)rEa  An IPv4 host address. @type address: L{bytes} @ivar address: The packed network-order representation of the IPv4 address associated with this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. ©Úaddressr(Nú0.0.0.0cCs2t|tƒr | d¡}t |¡}||_t|ƒ|_dS)úž @type address: L{bytes} or L{str} @param address: The IPv4 address associated with this record, in quad-dotted notation. rÍN)r¹ryrÎÚsocketÚ inet_atonrXrÙr(©rçrXr(r{r{r|rèÅs   zRecord_A.__init__cCó| |j¡dSrÚ©rérXrr{r{r|r»ÒózRecord_A.encodecCót|dƒ|_dS)Nr¨©ràrXrOr{r{r|rÎÕr`zRecord_A.decodecCrñrÚ©ròrXrór{r{r|rôØrõzRecord_A.__hash__rícCsd| ¡›d|j›dS)Nz )rEr[r~rr„r…r(rór{r{r|rö9s  üzRecord_A6.__str__)rrr°NrÚ)r«r¬r­r®rr¯rSr:r/r;rƒrèr»rÎrùrúrðrôrºrör{r{r{r|rFäs     rFc@óFeZdZdZeZdZdZdZddd „Z dd d „Z dd d „Z dd„Z dS)rZa: The location of the server(s) for a specific protocol and domain. This is an experimental record type. @type priority: L{int} @ivar priority: The priority of this target host. A client MUST attempt to contact the target host with the lowest-numbered priority it can reach; target hosts with the same priority SHOULD be tried in an order defined by the weight field. @type weight: L{int} @ivar weight: Specifies a relative weight for entries with the same priority. Larger weights SHOULD be given a proportionately higher probability of being selected. @type port: L{int} @ivar port: The port on this target host of this service. @type target: L{Name} @ivar target: The domain name of the target host. There MUST be one or more address records for this name, the name MUST NOT be an alias (in the sense of RFC 1034 or RFC 2181). Implementors are urged, but not required, to return the address record(s) in the Additional Data section. Unless and until permitted by future standards action, name compression is not to be used for this field. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @see: U{http://www.faqs.org/rfcs/rfc2782.html} r/)ÚpriorityÚweightÚtargetÚportr()r‰rŠ)r‹r‹rNrŒr(rr°NcCs6t|ƒ|_t|ƒ|_t|ƒ|_t|ƒ|_t|ƒ|_dS)zb @param target: See L{Record_SRV.target} @type target: L{bytes} or L{str} N)rÒr‰rŠrŒrgr‹rÙr()rçr‰rŠrŒr‹r(r{r{r|rèls    zRecord_SRV.__init__cCs.| t d|j|j|j¡¡|j |d¡dS©Nú!HHH)rérŒrýr‰rŠrŒr‹r»rr{r{r|r»wszRecord_SRV.encodecCs@t dt|t d¡ƒ¡}|\|_|_|_tƒ|_|j  |¡dSr) rŒrràr@r‰rŠrŒrgr‹rÎrrr{r{r|rÎ|szRecord_SRV.decodecCót|j|j|j|jfƒSrÚ)ròr‰rŠrŒr‹rór{r{r|rô‚rezRecord_SRV.__hash__)rrrr°NrÚ) r«r¬r­r®r/r¯rSr/r:rèr»rÎrôr{r{r{r|rZBs"   rZc@sTeZdZdZeZdZdZdZ       ddd „Z dd d „Z dd d „Z dd„Z dS)rSa The location of the server(s) for a specific protocol and domain. @type order: L{int} @ivar order: An integer specifying the order in which the NAPTR records MUST be processed to ensure the correct ordering of rules. Low numbers are processed before high numbers. @type preference: L{int} @ivar preference: An integer that specifies the order in which NAPTR records with equal "order" values SHOULD be processed, low numbers being processed before high numbers. @type flag: L{Charstr} @ivar flag: A containing flags to control aspects of the rewriting and interpretation of the fields in the record. Flags are single characters from the set [A-Z0-9]. The case of the alphabetic characters is not significant. At this time only four flags, "S", "A", "U", and "P", are defined. @type service: L{Charstr} @ivar service: Specifies the service(s) available down this rewrite path. It may also specify the particular protocol that is used to talk with a service. A protocol MUST be specified if the flags field states that the NAPTR is terminal. @type regexp: L{Charstr} @ivar regexp: A STRING containing a substitution expression that is applied to the original string held by the client in order to construct the next domain name to lookup. @type replacement: L{Name} @ivar replacement: The next NAME to query for NAPTR, SRV, or address records depending on the value of the flags field. This MUST be a fully qualified domain-name. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @see: U{http://www.faqs.org/rfcs/rfc2915.html} )ÚorderÚ preferenceÚflagsÚserviceÚregexpÚ replacementr')rr‘)r’r’rN)r“r“rN)r”r”rN)r•r•rNr(rr°NcCsJt|ƒ|_t|ƒ|_t|ƒ|_t|ƒ|_t|ƒ|_t|ƒ|_t |ƒ|_ dS)zs @param replacement: See L{Record_NAPTR.replacement} @type replacement: L{bytes} or L{str} N) rÒrr‘rer’r“r”rgr•rÙr()rçrr‘r’r“r”r•r(r{r{r|rèÊs      zRecord_NAPTR.__init__cCsT| t d|j|j¡¡|j |d¡|j |d¡|j |d¡|j  |d¡dSr) rérŒrýrr‘r’r»r“r”r•rr{r{r|r»às zRecord_NAPTR.encodecCsxt dt|t d¡ƒ¡}|\|_|_tƒ|_tƒ|_tƒ|_ t ƒ|_ |j  |¡|j  |¡|j   |¡|j   |¡dSr) rŒrràr@rr‘rer’r“r”rgr•rÎrrr{r{r|rÎès    zRecord_NAPTR.decodecCrsrÚ)ròrr‘r’r“r”r•rór{r{r|rôôsúÿzRecord_NAPTR.__hash__)rrr°r°r°r°NrÚ) r«r¬r­r®r'r¯r/rSr:rèr»rÎrôr{r{r{r|rS†s",  ø   rSc@rˆ)rHa­ Map from a domain name to the name of an AFS cell database server. @type subtype: L{int} @ivar subtype: In the case of subtype 1, the host has an AFS version 3.0 Volume Location Server for the named AFS cell. In the case of subtype 2, the host has an authenticated name server holding the cell-root directory node for the named DCE/NCA cell. @type hostname: L{Name} @ivar hostname: The domain name of a host that has a server for the cell named by this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @see: U{http://www.faqs.org/rfcs/rfc1183.html} r)ÚsubtypeÚhostnamer()r–)r—r—rNr(rr°NcCs"t|ƒ|_t|ƒ|_t|ƒ|_dS)zj @param hostname: See L{Record_AFSDB.hostname} @type hostname: L{bytes} or L{str} N)rÒr–rgr—rÙr()rçr–r—r(r{r{r|rès  zRecord_AFSDB.__init__cCó&| t d|j¡¡|j ||¡dS©Nrû)rérŒrýr–r—r»rr{r{r|r»&ózRecord_AFSDB.encodecCs0t dt|t d¡ƒ¡}|\|_|j |¡dSr™)rŒrràr@r–r—rÎrrr{r{r|rÎ*ózRecord_AFSDB.decodecCót|j|jfƒSrÚ)ròr–r—rór{r{r|rô/r`zRecord_AFSDB.__hash__©rr°NrÚ) r«r¬r­r®rr¯rSr/r:rèr»rÎrôr{r{r{r|rHs   rHc@sFeZdZdZeZdZdZdZddd„Z dd d „Z dd d „Z d d„Z dS)rWaû The responsible person for a domain. @type mbox: L{Name} @ivar mbox: A domain name that specifies the mailbox for the responsible person. @type txt: L{Name} @ivar txt: A domain name for which TXT RR's exist (indirection through which allows information sharing about the contents of this RP record). @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @see: U{http://www.faqs.org/rfcs/rfc1183.html} r,)ÚmboxÚtxtr())ržržrN)rŸrŸrNr(r°NcCs"t|ƒ|_t|ƒ|_t|ƒ|_dS)z¬ @param mbox: See L{Record_RP.mbox}. @type mbox: L{bytes} or L{str} @param txt: See L{Record_RP.txt} @type txt: L{bytes} or L{str} N)rgržrŸrÙr()rçržrŸr(r{r{r|rèMs  zRecord_RP.__init__cCó |j ||¡|j ||¡dSrÚ)ržr»rŸrr{r{r|r»YózRecord_RP.encodecCs,tƒ|_tƒ|_|j |¡|j |¡dSrÚ)rgržrŸrÎrOr{r{r|rÎ]s zRecord_RP.decodecCrœrÚ)ròržrŸrór{r{r|rôcr`zRecord_RP.__hash__©r°r°NrÚ) r«r¬r­r®r,r¯rSr/r:rèr»rÎrôr{r{r{r|rW3s   rWc@sfeZdZdZeZdZdefdefdfZdZ dd d „Z dd d „Z dd d„Z de defdd„Zdd„ZdS)rKa Host information. @type cpu: L{bytes} @ivar cpu: Specifies the CPU type. @type os: L{bytes} @ivar os: Specifies the OS. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. rÚcpuÚosr()r£r¤r(r°NcCs|||_|_t|ƒ|_dSrÚ)r£r¤rÙr()rçr£r¤r(r{r{r|rè}szRecord_HINFO.__init__cCs@| t dt|jƒ¡|j¡| t dt|jƒ¡|j¡dSry)rérŒrýrÁr£r¤rr{r{r|r»s"zRecord_HINFO.encodecCsHt dt|dƒ¡d}t||ƒ|_t dt|dƒ¡d}t||ƒ|_dS)Nrzr~r)rŒrràr£r¤)rçrârår£r¤r{r{r|rÎ…s zRecord_HINFO.decoderìrícCsBt|tƒr|j ¡|j ¡ko|j ¡|j ¡ko|j|jkStSrÚ)r¹rKr¤rÀr£r(rîrïr{r{r|rð‹s ÿ ýzRecord_HINFO.__eq__cCst|j ¡|j ¡fƒSrÚ)ròr¤rÀr£rór{r{r|rô”rezRecord_HINFO.__hash__r¢rÚ)r«r¬r­r®rr¯rSr€r:r/rèr»rÎrùrúrðrôr{r{r{r|rKgs    rKc@sNeZdZdZeZdZdZdZdZ dZ ddd„Z dd d „Z dd d „Z d d„ZdS)rPaþ Mailbox or mail list information. This is an experimental record type. @type rmailbx: L{Name} @ivar rmailbx: A domain-name which specifies a mailbox which is responsible for the mailing list or mailbox. If this domain name names the root, the owner of the MINFO RR is responsible for itself. @type emailbx: L{Name} @ivar emailbx: A domain-name which specifies a mailbox which is to receive error messages related to the mailing list or mailbox specified by the owner of the MINFO record. If this domain name names the root, errors should be returned to the sender of the message. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. Nr$)ÚrmailbxÚemailbxr())r¥ÚresponsibilityrN)r¦ÚerrorsrNr(r°cCs$t|ƒt|ƒ|_|_t|ƒ|_dS)zÈ @param rmailbx: See L{Record_MINFO.rmailbx}. @type rmailbx: L{bytes} or L{str} @param emailbx: See L{Record_MINFO.rmailbx}. @type emailbx: L{bytes} or L{str} N)rgr¥r¦rÙr()rçr¥r¦r(r{r{r|rè¼szRecord_MINFO.__init__cCr rÚ)r¥r»r¦rr{r{r|r»Çr¡zRecord_MINFO.encodecCs.tƒtƒ|_|_|j |¡|j |¡dSrÚ)rgr¥r¦rÎrOr{r{r|rÎËs zRecord_MINFO.decodecCrœrÚ)ròr¥r¦rór{r{r|rôÐr`zRecord_MINFO.__hash__r¢rÚ)r«r¬r­r®r$r¯r¥r¦rSr/r:rèr»rÎrôr{r{r{r|rP˜s   rPc@rˆ)rRa¤ Mail exchange. @type preference: L{int} @ivar preference: Specifies the preference given to this RR among others at the same owner. Lower values are preferred. @type name: L{Name} @ivar name: A domain-name which specifies a host willing to act as a mail exchange. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. r&)r‘rµr()r‘rMr(rr°NcKs*t|ƒ|_t| d|¡ƒ|_t|ƒ|_dS)z\ @param name: See L{Record_MX.name}. @type name: L{bytes} or L{str} ÚexchangeN)rÒr‘rgrrµrÙr()rçr‘rµr(Úkwargsr{r{r|rèìs zRecord_MX.__init__cCr˜r™)rérŒrýr‘rµr»rr{r{r|r»õršzRecord_MX.encodecCs0t dt|dƒ¡d|_tƒ|_|j |¡dS)NrûrŠr)rŒrràr‘rgrµrÎrOr{r{r|rÎùr›zRecord_MX.decodecCrœrÚ)ròr‘rµrór{r{r|rôþr`zRecord_MX.__hash__rrÚ) r«r¬r­r®r&r¯rSr/r:rèr»rÎrôr{r{r{r|rRÔs   rRc@s^eZdZdZdZdZdZeZdZ dZ dZ dZ dZ dZdd d „Zddd„Zddd„Zdd„Zd S)r[ab A record containing the fingerprint of an SSH key. @type algorithm: L{int} @ivar algorithm: The SSH key's algorithm, such as L{ALGORITHM_RSA}. Note that the numbering used for SSH key algorithms is specific to the SSHFP record, and is not the same as the numbering used for KEY or SIG records. @type fingerprintType: L{int} @ivar fingerprintType: The fingerprint type, such as L{FINGERPRINT_TYPE_SHA256}. @type fingerprint: L{bytes} @ivar fingerprint: The key's fingerprint, e.g. a 32-byte SHA-256 digest. @cvar ALGORITHM_RSA: The algorithm value for C{ssh-rsa} keys. @cvar ALGORITHM_DSS: The algorithm value for C{ssh-dss} keys. @cvar ALGORITHM_ECDSA: The algorithm value for C{ecdsa-sha2-*} keys. @cvar ALGORITHM_Ed25519: The algorithm value for C{ed25519} keys. @cvar FINGERPRINT_TYPE_SHA1: The type for SHA-1 fingerprints. @cvar FINGERPRINT_TYPE_SHA256: The type for SHA-256 fingerprints. @see: U{RFC 4255 } and U{RFC 6594 } r1©Ú algorithmÚfingerprintTypeÚ fingerprintr()r¬r­r®r~rŠr§r¨rr°cCs||_||_||_||_dSrÚr«)rçr¬r­r®r(r{r{r|rè/s zRecord_SSHFP.__init__NcCs(| t d|j|j¡¡| |j¡dS)Nú!BB)rérŒrýr¬r­r®rr{r{r|r»5szRecord_SSHFP.encodecCs2t dt|dƒ¡}|\|_|_t||dƒ|_dS)Nr¯rŠ)rŒrràr¬r­r®rrr{r{r|rÎ9s zRecord_SSHFP.decodecCr{rÚ)ròr¬r­r®rór{r{r|rô>r|zRecord_SSHFP.__hash__)rrr°rrÚ)r«r¬r­r®rSr/r:r1r¯Ú ALGORITHM_RSAÚ ALGORITHM_DSSÚALGORITHM_ECDSAÚALGORITHM_Ed25519ÚFINGERPRINT_TYPE_SHA1ÚFINGERPRINT_TYPE_SHA256rèr»rÎrôr{r{r{r|r[s     r[c@sLeZdZdZeZdZdefdfZdZ dd„Z dd d „Z dd d „Z d d„Z dS)r]zß Freeform text. @type data: L{list} of L{bytes} @ivar data: Freeform text which makes up this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. r0r5r(©r5r(cOs t|ƒ|_t| dd¡ƒ|_dS)Nr()r‡r5rÙrr()rçr5Úkwr{r{r|rèTs zRecord_TXT.__init__NcCs*|jD]}| t dt|ƒ¡|¡qdSry)r5rérŒrýrÁ)rçrârãÚdr{r{r|r»Ys ÿzRecord_TXT.encodecCstd}g|_||kr't dt|dƒ¡d}|j t||ƒ¡||d7}||ks ||kr8t d||j|f¡dSdS)Nrrzr~z1Decoded %d bytes in %s record, but rdlength is %d)r5rŒrràr´rÚmsgrS)rçrâråÚsoFarÚLr{r{r|rÎ]s ý ÿÿÿzRecord_TXT.decodecCstt|jƒƒSrÚ)ròÚtupler5rór{r{r|rôjszRecord_TXT.__hash__rÚ)r«r¬r­r®r0r¯rSrˆr:r/rèr»rÎrôr{r{r{r|r]Bs     r]c@sNeZdZdZdZdZdZdefdfZddd „Z dd d „Z dd d „Z dd„Z dS)r_a> Encapsulate the wire data for unknown record types so that they can pass through the system unchanged. @type data: L{bytes} @ivar data: Wire data which makes up this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @since: 11.1 NÚUNKNOWNr¶r5r(r°cCrtrÚ)r5rÙr()rçr5r(r{r{r|rèƒruzUnknownRecord.__init__cCs| |j¡dS)zc Write the raw bytes corresponding to this record's payload to the stream. N)rér5rr{r{r|r»‡ózUnknownRecord.encodecCs |durtdƒ‚t||ƒ|_dS)z~ Load the bytes which are part of this record from the stream and store them unparsed and unmodified. Nz)must know length for unknown record types)Ú Exceptionràr5rOr{r{r|rÎŽszUnknownRecord.decodecCrœrÚ)ròr5r(rór{r{r|rô—r`zUnknownRecord.__hash__rPrÚ) r«r¬r­r®r¯rSr/r€r:rèr»rÎrôr{r{r{r|r_ns      r_c@rR)rYao Structurally, freeform text. Semantically, a policy definition, formatted as defined in U{rfc 4408}. @type data: L{list} of L{bytes} @ivar data: Freeform text which makes up this record. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. r.N)r«r¬r­r®r.r¯rSr{r{r{r|rY›s rYc@sZeZdZdZdZdZgd¢ZeZddddde ddfd d „Z dd d „Z dd d„Z dd„Z dS)r\aé A transaction signature, encapsulated in a RR, as described in U{RFC 2845 }. @type algorithm: L{Name} @ivar algorithm: The name of the signature or MAC algorithm. @type timeSigned: L{int} @ivar timeSigned: Signing time, as seconds from the POSIX epoch. @type fudge: L{int} @ivar fudge: Allowable time skew, in seconds. @type MAC: L{bytes} @ivar MAC: The message digest or signature. @type originalID: L{int} @ivar originalID: A message ID. @type error: L{int} @ivar error: An error code (extended C{RCODE}) carried in exceptional cases. @type otherData: L{bytes} @ivar otherData: Other data carried in exceptional cases. r2)r¬Ú timeSignedÚfudgeÚMACÚ originalIDÚerrorÚ otherDatar()r¬rÀrÂrÄrÅNr¥rr°c CsH|durdnt|ƒ|_||_t|ƒ|_||_||_||_||_||_ dSrÚ) rgr¬rÀrÙrÁrÂrÃrÄrÅr() rçr¬rÀrÁrÂrÃrÄrÅr(r{r{r|rèÙs  zRecord_TSIG.__init__c Cs‚|j ||¡| t d|j¡dd…¡| t d|jt|jƒ¡¡| |j¡| t d|j |j t|j ƒ¡¡| |j ¡dS)Nz!QrŠrrŽ) r¬r»rérŒrýrÀrÁrÁrÂrÃrÄrÅrr{r{r|r»òs ÿzRecord_TSIG.encodecCsvtƒ}| |¡||_t ddt|dƒ¡}|\|_|_}t||ƒ|_t dt|dƒ¡}|\|_ |_ }t||ƒ|_ dS)Nz!QHHsé rŽr©) rgrÎr¬rŒrràrÀrÁrÂrÃrÄrÅ)rçrârår¬ÚfieldsÚ macLengthÚ otherLengthr{r{r|rÎüs  zRecord_TSIG.decodecCrrÚ)ròr¬rÀrÂrÃrór{r{r|rô rezRecord_TSIG.__hash__rÚ)r«r¬r­r®rSr/r:r2r¯rnrèr»rÎrôr{r{r{r|r\¬s$  ÷  r\cKs*|d|jddœ|¤Ž}|jdd…|_|S)a² Generate a L{Message} like instance suitable for use as the response to C{message}. The C{queries}, C{id} attributes will be copied from C{message} and the C{answer} flag will be set to L{True}. @param responseConstructor: A response message constructor with an initializer signature matching L{dns.Message.__init__}. @type responseConstructor: C{callable} @param message: A request message. @type message: L{Message} @param kwargs: Keyword arguments which will be passed to the initialiser of the response message. @type kwargs: L{dict} @return: A L{Message} like response instance. @rtype: C{responseConstructor} T)ÚidÚanswerNr{)rÊÚqueries)ÚresponseConstructorÚmessagerªÚresponser{r{r|Ú_responseFromMessage srÐcCs^g}t |jj¡}|D]!}|j|j}t|||ƒ}||vs!||kr,| d|›d|›¡q |S)aä Inspect the function signature of C{obj}'s constructor, and get a list of which arguments should be displayed. This is a helper function for C{_compactRepr}. @param obj: The instance whose repr is being generated. @param alwaysShow: A L{list} of field names which should always be shown. @param fieldNames: A L{list} of field attribute names which should be shown if they have non-default values. @return: A L{list} of displayable arguments. rú=)ÚinspectÚ signatureÚ __class__rèÚ parametersÚdefaultr1r´)ÚobjÚ alwaysShowÚ fieldNamesÚdisplayableArgsrÓrµÚ defaultValueÚ fieldValuer{r{r|Ú_getDisplayableArguments& s   €rÝc CsÚ|durg}|dur g}|durg}|durg}g}|D]}||vs*t||dƒdkr/| |¡qt|||ƒ}d|jjg|}|rK| d d |¡¡¡|D]}t||gƒ} | rb| d|›d| ›¡qM| d ¡d  |¡S) aÍ Return a L{str} representation of C{obj} which only shows fields with non-default values, flags which are True and sections which have been explicitly set. @param obj: The instance whose repr is being generated. @param alwaysShow: A L{list} of field names which should always be shown. @param flagNames: A L{list} of flag attribute names which should be shown if they are L{True}. @param fieldNames: A L{list} of field attribute names which should be shown if they have non-default values. @param sectionNames: A L{list} of section attribute names which should be shown if they have been assigned a value. @return: A L{str} representation of C{obj}. NFTú s0 €  €  ræc @sÒeZdZdZdZdZe e¡ZdZ Z Z Z dddddde ddddf dd„Zd efd d „Zeefd d „Zdd„Zddd„Zdd„ZiZeƒD]Ze d¡rYeƒeeeƒej<qG[dd„Zdd„Zdd„ZdS)rfah L{Message} contains all the information represented by a single DNS request or response. @ivar id: See L{__init__} @ivar answer: See L{__init__} @ivar opCode: See L{__init__} @ivar recDes: See L{__init__} @ivar recAv: See L{__init__} @ivar auth: See L{__init__} @ivar rCode: See L{__init__} @ivar trunc: See L{__init__} @ivar maxSize: See L{__init__} @ivar authenticData: See L{__init__} @ivar checkingDisabled: See L{__init__} @ivar queries: The queries which are being asked of or answered by DNS server. @type queries: L{list} of L{Query} @ivar answers: Records containing the answers to C{queries} if this is a response message. @type answers: L{list} of L{RRHeader} @ivar authority: Records containing information about the authoritative DNS servers for the names in C{queries}. @type authority: L{list} of L{RRHeader} @ivar additional: Records containing IP addresses of host names in C{answers} and C{authority}. @type additional: L{list} of L{RRHeader} @ivar _flagNames: The names of attributes representing the flag header fields. @ivar _fieldNames: The names of attributes representing non-flag fixed header fields. @ivar _sectionNames: The names of attributes representing the record sections of this message. )rÊrËÚopCodeÚrecDesÚrecAvrAÚrCodeÚtruncÚmaxSizeÚ authenticDataÚcheckingDisabledrÌÚanswersÚ authorityÚ additionalz!H2B4HNréc Cs^| |_||_||_||_||_||_||_||_||_| |_ | |_ g|_ g|_ g|_ g|_dS)a› @param id: A 16 bit identifier assigned by the program that generates any kind of query. This identifier is copied to the corresponding reply and can be used by the requester to match up replies to outstanding queries. @type id: L{int} @param answer: A one bit field that specifies whether this message is a query (0), or a response (1). @type answer: L{int} @param opCode: A four bit field that specifies kind of query in this message. This value is set by the originator of a query and copied into the response. @type opCode: L{int} @param recDes: Recursion Desired - this bit may be set in a query and is copied into the response. If RD is set, it directs the name server to pursue the query recursively. Recursive query support is optional. @type recDes: L{int} @param recAv: Recursion Available - this bit is set or cleared in a response and denotes whether recursive query support is available in the name server. @type recAv: L{int} @param auth: Authoritative Answer - this bit is valid in responses and specifies that the responding name server is an authority for the domain name in question section. @type auth: L{int} @ivar rCode: A response code, used to indicate success or failure in a message which is a response from a server to a client request. @type rCode: C{0 <= int < 16} @param trunc: A flag indicating that this message was truncated due to length greater than that permitted on the transmission channel. @type trunc: L{int} @param maxSize: The requestor's UDP payload size is the number of octets of the largest UDP payload that can be reassembled and delivered in the requestor's network stack. @type maxSize: L{int} @param authenticData: A flag indicating in a response that all the data included in the answer and authority portion of the response has been authenticated by the server according to the policies of that server. See U{RFC2535 section-6.1}. @type authenticData: L{int} @param checkingDisabled: A flag indicating in a query that pending (non-authenticated) data is acceptable to the resolver sending the query. See U{RFC2535 section-6.1}. @type authenticData: L{int} N)rìrÊrËrçrArërèrérêrírîrÌrïrðrñ) rçrÊrËrçrèrérArêrërìrírîr{r{r|rè³ sJ zMessage.__init__rícCót|dddddS)zä Generate a repr of this L{Message}. Only includes the non-default fields and sections and only includes flags which are set. The C{id} is always shown. @return: The native string repr. )rËrArërèrérírî)rÊrçrêrì©rÌrïrðrñ©rÊ©rárÙrârØ©rærór{r{r|r s  ózMessage.__repr__cCs|j t|||ƒ¡dS)zñ Add another query to this Message. @type name: L{bytes} @param name: The name to query. @type type: L{int} @param type: Query type @type cls: L{int} @param cls: Query class N)rÌr´rhr r{r{r|ÚaddQuery' s zMessage.addQueryc Cshi}tƒ}|jD]}| ||¡q|jD]}| ||¡q|jD]}| ||¡q |jD]}| ||¡q,| ¡}t|ƒ|j}|j rU||j krUd|_ |d|j |j…}|j d@d>|j d@d>B|j d@d>B|j d@d>B|jd@B}|jd@d>|jd@d>B|jd@d>B|jd@B}| t |j|j||t|jƒt|jƒt|jƒt|jƒ¡¡| |¡dS)Nr~ér'r§rŠr¥r¨)rrÌr»rïrðrñr*rÁrÿrìrërËrçrArèrérírîrêrérŒrýÚ headerFmtrÊ) rçrârãÚbody_tmpÚqÚbodyÚsizeÚbyte3Úbyte4r{r{r|r»6 s\      ÿ þ ýüÿ  ÿ þýÿøÿ zMessage.encodec Cs2d|_t||jƒ}t |j|¡}|\|_}}}}} } |d?d@|_|d?d@|_|d?d@|_ |d?d@|_ |d@|_ |d?d@|_ |d?d@|_ |d?d@|_|d@|_g|_t|ƒD]} tƒ} z|  |¡Wn tysYdSw|j | ¡q\|j|f|j| f|j| ff} | D] \}}| |||¡q‹dS) Nrrùr~r§r'rŠr¥r¨)rìràrÿrŒrrúrÊrËrçrArërèrérírîrêrÌÚrangerhrÎrÜr´rïrðrñÚ parseRecords)rçrâråÚheaderrGrÿrÚnqueriesÚnansÚnnsÚnaddÚirüÚitemsrÞrr{r{r|rÎb s4     ÿ ÿzMessage.decodec Csšt|ƒD]F}t|jd}z| |¡Wn tyYdSw| |j¡}|s(q||jd|_z |j ||j ¡Wn tyDYdSw|  |¡qdS)NrH)r() rrirArÎrÜÚlookupRecordTyper½r(r)r-r´)rçr‡Únumrârrrr{r{r|r s$   ÿ  ÿ òzMessage.parseRecordsÚRecord_cCs|j |t¡S)aC Retrieve the L{IRecord} implementation for the given record type. @param type: A record type, such as C{A} or L{NS}. @type type: L{int} @return: An object which implements L{IRecord} or L{None} if none can be found for the given type. @rtype: C{Type[IRecord]} )Ú _recordTypesrr_)rçr½r{r{r|r  s zMessage.lookupRecordTypecCstƒ}| |¡| ¡S)z‚ Encode this L{Message} into a byte string in the format described by RFC 1035. @rtype: L{bytes} )rr»r*)rçrâr{r{r|ÚtoStrª s z Message.toStrcCst|ƒ}| |¡dS)z† Decode a byte string in the format described by RFC 1035 into this L{Message}. @param str: L{bytes} N)rrÎ)rçrºrâr{r{r|ÚfromStrµ szMessage.fromStrrÚ)r«r¬r­r®r/rúrŒr@rÿrÌrïrÚnsrnrèrºrr9r8rør»rÎrr ÚglobalsrµÚ startswithr¯r rrr{r{r{r|rfr s@(  ô[ ,  € rfc@sveZdZdZdZeZddeddddddddddddddfdd„Zd e fd d „Z d d „Z dd„Z e dd„ƒZdd„ZdS)Ú _EDNSMessageaæ An I{EDNS} message. Designed for compatibility with L{Message} but with a narrower public interface. Most importantly, L{_EDNSMessage.fromStr} will interpret and remove I{OPT} records that are present in the additional records section. The I{OPT} records are used to populate certain I{EDNS} specific attributes. L{_EDNSMessage.toStr} will add suitable I{OPT} records to the additional section to represent the extended EDNS information. @see: U{https://tools.ietf.org/html/rfc6891} @ivar id: See L{__init__} @ivar answer: See L{__init__} @ivar opCode: See L{__init__} @ivar auth: See L{__init__} @ivar trunc: See L{__init__} @ivar recDes: See L{__init__} @ivar recAv: See L{__init__} @ivar rCode: See L{__init__} @ivar ednsVersion: See L{__init__} @ivar dnssecOK: See L{__init__} @ivar authenticData: See L{__init__} @ivar checkingDisabled: See L{__init__} @ivar maxSize: See L{__init__} @ivar queries: See L{__init__} @ivar answers: See L{__init__} @ivar authority: See L{__init__} @ivar additional: See L{__init__} @ivar _messageFactory: A constructor of L{Message} instances. Called by C{_toMessage} and C{_fromMessage}. ©rÊrËrçrArërèrérêÚ ednsVersionr"rírîrìrÌrïrðrñrFròNcCsš||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ |dur-g}||_ |dur6g}||_|dur?g}||_|durHg}||_dS)a+ Construct a new L{_EDNSMessage} @see: U{RFC1035 section-4.1.1} @see: U{RFC2535 section-6.1} @see: U{RFC3225 section-3} @see: U{RFC6891 section-6.1.3} @param id: A 16 bit identifier assigned by the program that generates any kind of query. This identifier is copied the corresponding reply and can be used by the requester to match up replies to outstanding queries. @type id: L{int} @param answer: A one bit field that specifies whether this message is a query (0), or a response (1). @type answer: L{bool} @param opCode: A four bit field that specifies kind of query in this message. This value is set by the originator of a query and copied into the response. @type opCode: L{int} @param auth: Authoritative Answer - this bit is valid in responses, and specifies that the responding name server is an authority for the domain name in question section. @type auth: L{bool} @param trunc: Truncation - specifies that this message was truncated due to length greater than that permitted on the transmission channel. @type trunc: L{bool} @param recDes: Recursion Desired - this bit may be set in a query and is copied into the response. If set, it directs the name server to pursue the query recursively. Recursive query support is optional. @type recDes: L{bool} @param recAv: Recursion Available - this bit is set or cleared in a response, and denotes whether recursive query support is available in the name server. @type recAv: L{bool} @param rCode: Extended 12-bit RCODE. Derived from the 4 bits defined in U{RFC1035 4.1.1} and the upper 8bits defined in U{RFC6891 6.1.3}. @type rCode: L{int} @param ednsVersion: Indicates the EDNS implementation level. Set to L{None} to prevent any EDNS attributes and options being added to the encoded byte string. @type ednsVersion: L{int} or L{None} @param dnssecOK: DNSSEC OK bit as defined by U{RFC3225 3}. @type dnssecOK: L{bool} @param authenticData: A flag indicating in a response that all the data included in the answer and authority portion of the response has been authenticated by the server according to the policies of that server. See U{RFC2535 section-6.1}. @type authenticData: L{bool} @param checkingDisabled: A flag indicating in a query that pending (non-authenticated) data is acceptable to the resolver sending the query. See U{RFC2535 section-6.1}. @type authenticData: L{bool} @param maxSize: The requestor's UDP payload size is the number of octets of the largest UDP payload that can be reassembled and delivered in the requestor's network stack. @type maxSize: L{int} @param queries: The L{list} of L{Query} associated with this message. @type queries: L{list} of L{Query} @param answers: The L{list} of answers associated with this message. @type answers: L{list} of L{RRHeader} @param authority: The L{list} of authority records associated with this message. @type authority: L{list} of L{RRHeader} @param additional: The L{list} of additional records associated with this message. @type additional: L{list} of L{RRHeader} Nr)rçrÊrËrçrArërèrérêrr"rírîrìrÌrïrðrñr{r{r|rèþ s2m z_EDNSMessage.__init__rícCró)N)rËrArërèrérírîr")rÊrçrêrìrrôrõrör÷rór{r{r|r‰ s òz_EDNSMessage.__repr__c Cs¬|j|j|j|j|j|j|j|j|jd@|j |j d }|j dd…|_ |j dd…|_ |j dd…|_ |jdd…|_|jdurTt|j|j|j|jd?d}|j |¡|S)a= Convert to a standard L{dns.Message}. If C{ednsVersion} is not None, an L{_OPTHeader} instance containing all the I{EDNS} specific attributes and options will be appended to the list of C{additional} records. @return: A L{dns.Message} @rtype: L{dns.Message} r') rÊrËrçrArërèrérêrírîNr¨)r!r"rr )Ú_messageFactoryrÊrËrçrArërèrérêrírîrÌrïrðrñrrr"rìr´)rçÚmr+r{r{r|Ú _toMessage› s2 õ û z_EDNSMessage._toMessagecCs | ¡ ¡S)z~ Encode to wire format by first converting to a standard L{dns.Message}. @return: A L{bytes} string. )rrrór{r{r|rÅ s z_EDNSMessage.toStrcCsg}g}|jD]}|jtkr| t |¡¡q| |¡q|did|j“d|j“d|j“d|j “d|j “d|j “d|j “d|j “d |j“d |j“d d “d d“d|jd d …“d|jd d …“d|jd d …“d|“Ž}t|ƒdkrŠ|d}|j|_|j|_|j|_|jd>|j B|_ |S)aÀ Construct and return a new L{_EDNSMessage} whose attributes and records are derived from the attributes and records of C{message} (a L{Message} instance). If present, an C{OPT} record will be extracted from the C{additional} section and its attributes and options will be used to set the EDNS specific attributes C{extendedRCODE}, C{ednsVersion}, C{dnssecOK}, C{ednsOptions}. The C{extendedRCODE} will be combined with C{message.rCode} and assigned to C{self.rCode}. @param message: The source L{Message}. @type message: L{Message} @return: A new L{_EDNSMessage} @rtype: L{_EDNSMessage} rÊrËrçrArërèrérêrírîrNr"FrÌrïrðrñr~rr¨r{)rñr½r*r´rr.rÊrËrçrArërèrérêrírîrÌrïrðrÁr!rr"rrìr )r rÎrñÚ optRecordsrGÚ newMessageÚoptr{r{r|Ú _fromMessageÍ s\   ÿþýüûúùø ÷ ö óòñðïî z_EDNSMessage._fromMessagecCs>| ¡}| |¡| |¡}|jD] }t||t||ƒƒqdS)z× Decode from wire format, saving flags, values and records to this L{_EDNSMessage} instance in place. @param bytes: The full byte string to be decoded. @type bytes: L{bytes} N)rrrr/r0r1)rçryrÚ ednsMessager4r{r{r|r s    ÿz_EDNSMessage.fromStr)r«r¬r­r®r/rfrrqrèrºrrrr<rrr{r{r{r|rÀ s:' î *  .writeMessage)r9r?r r r,r&r8r3)rçrXrÌr/rÊr0r{rHr|Úquery³ s    ÿ  zDNSDatagramProtocol.query)rÆN) r«r¬r­r®r8r:r;r0r?rFrGrIr{r{r{r|rki s  rkc@sBeZdZdZdZdZdd„Zdd„Zdd „Zd d „Z dd d„Z dS)rmz DNS protocol over TCP. Nr°cCs(| ¡}|j t dt|ƒ¡|¡dS)r<rûN)rr9rérŒrýrÁ)rçrÎrÕr{r{r|r0Ù s zDNSProtocol.writeMessagecCsi|_|j |¡dS)zV Connection is made: reset internal state, and notify the controller. N)r$rÚconnectionMaderór{r{r|rJâ szDNSProtocol.connectionMadecCs|j |¡dS)zZ Notify the controller that this protocol is no longer connected. N)rÚconnectionLost)rçÚreasonr{r{r|rKé r¾zDNSProtocol.connectionLostcCs&|j|7_|jr‘|jdur,t|jƒdkr,t d|jdd…¡d|_|jdd…|_t|jƒ|jkrŠ|jd|j…}tƒ}| |¡z |j|j\}}Wnt y^|j   ||¡Ynw|j|j=|  ¡z|  |¡Wn ty|t ¡Ynw|j|jd…|_d|_ndS|js dSdS)NrŠrûr)ÚbufferrårÁrŒrrfrr$rÊr4rrCrArBr+rr@)rçr5ÚmyChunkrr¸rEr{r{r|Ú dataReceivedð s2  ÿ   ÿæzDNSProtocol.dataReceivedrÉcCs| ¡}| ||||j¡S)z¿ Send out a message with the given queries. @type queries: L{list} of C{Query} instances @param queries: The queries to transmit @rtype: C{Deferred} )r&r3r0)rçrÌr/rÊr{r{r|rI s zDNSProtocol.query)rÉ) r«r¬r­r®rårMr0rJrKrOrIr{r{r{r|rmÑ s rm)NNNN)r®rÒr r[rŒÚiorÚ itertoolsrÚtypingrrrÚzope.interfacerrr r"r r Útwisted.internet.errorr Útwisted.pythonr rrrÚtputilÚtwisted.python.compatrrrÚ__all__rr}r€rˆrrtrrr(r!r"rr-r r#r%r)r3r+rr$r&r0r,rrr/r'rrr*r1r.rœr2rar;r:rrr9rdr rcr8r6r5r7r4r`rbrqrorrrprsrnr<r@r=r>r?rArBrCrDrÚtwisted.names.errorrurvrwr·r¿rÆrÙràrrrergrhÚ FancyStrMixinÚ FancyEqMixinrr6rirjrTrMrNrIrLrOrQrVrJrErXrUr^rGrFrZrSrHrWrKrPrRr[r]r_rYr\rÐrÝrærfrrlÚDatagramProtocolrkÚProtocolrmr{r{r{r|ÚsŠ   h    íÿþýüûúùø ÷ ö õ ô óòñðïã û !('1f<;<z&        1s<.]Cz130;-?+,^ ÿ4P\Oh