Ϫf z dZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZmZddlmZmZmZddlmZmZdd lmZdd lmZmZmZmZdd l m!Z!m"Z"m#Z#gd Z$ejJZ%d Z&dZ'dZ(dZ)dZ*e+dd\Z,Z-Z.Z/Z0Z1Z2Z3Z4Z5Z6Z7Z8Z9Z:Z;ZdZ?dZ@dZAdZBdZCdZDdZEdZFdZGie,de-de.d e/d!e0d"e1d#e2d$e3d%e4d&e5d'e6d(e7d)e8d*e9d+e:d,e;d-ed0e?d1e@d2eAd3eBd4eCd5eDd6eEd7eFd8eGd9i ZHe+d:d;\ZIZJZKZLZMeIdeLd?eMd@iZNe eHjeNjDcic]\}}|| c}}ZPe+ddA\ZQZRZSZTdBZUeQdCeRdDeSdEeTdFeUdGiZVeVjDcic]\}}|| c}}ZWe+dH\ZXZYZZdIZ[dAZ\e+dJ\Z]Z^Z_Z`ZaZbdKZce+dKd\ZdZeZfGdLdMeZgddNlhmiZimjZjmkZkdOZlddPZmdQZnddRZoeddSZpeddTZpddUZpdVZqGdWdXeZrGdYdZeregZseerGd[d\ZteerGd]d^Zue"eerGd_d`ZveerGdadbejejZyeerGdcddejejZzeerGdedfejZ{eesGdgdhejejZ|Gdidje|Z}Gdkdle|Z~Gdmdne|ZGdodpe|ZGdqdre|ZGdsdte|ZGdudve|ZGdwdxe|ZGdydze|ZeesGd{d|ejZeesGd}d~ejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZeesGddejejZGddeZeesGddejejZdZdZ d ddZGddejZGddejZGddZGddeej<ZGddeej@Zycc}}wcc}}w)zU DNS protocol implementation. Future Plans: - Get rid of some toplevels, maybe. ) annotationsN)BytesIO)chain)OptionalSequence SupportsIntUnionoverload) Attribute Interface implementer)deferprotocol)CannotListenError)failurelog randbytesutil)cmp comparable nativeString)d IEncodableIRecordIEncodableRecordAA6AAAAAFSDBCNAMEDNAMEHINFOMAILAMAILBMBMDMFMGMINFOMRMXNAPTRNSNULLOPTPTRRPSOASPFSRVTXTSSHFPTSIGWKSANYCHCSHSIN ALL_RECORDSAXFRIXFREFORMATENAMEENOTIMPEREFUSEDESERVER EBADVERSIONEBADSIGEBADKEYEBADTIMERecord_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_QUERIESCharstrMessageNameQueryRRHeader SimpleRecordDNSDatagramProtocolDNSMixin DNSProtocolOK OP_INVERSE OP_NOTIFYOP_QUERY OP_STATUS OP_UPDATEPORTAuthoritativeDomainErrorDNSQueryTimeoutError DomainErrorct|gS)z Construct a bytes object representing a single byte with the given ordinal value. @type ordinal: L{int} @rtype: L{bytes} bytes)ordinals 3/usr/lib/python3/dist-packages/twisted/names/dns.py _ord2bytesrs ' ct|ddS)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)reprr}s r _nicebytesrs ;qr?rc zdjdj|Dcgc] }t|c}Scc}w)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[{}], )formatjoinr)listbs r_nicebyteslistrs. ==4#@aJqM#@A BB#@s8 c^tjdtjdddS)z Wrapper around L{twisted.python.randbytes.RandomFactory.secureRandom} to return 2 random bytes. @rtype: L{bytes} HT)fallbackr)structunpackr secureRandomrr randomSourcers' ==i44QF G JJr5r!#&'),crr,r%r&rr1r$r'r)r-r7r/r!r(r*r4r0rrr3r+rr r.r5r2TKEYr6r?r>r#r"r=r<r:r9r;r8c eZdZdZedZy)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 TYPErrrrrs C DDrr)ryrzr{ch|dvrdgS|jd}|ddk7r|jd|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.rr)splitappend)namelabelss r _nameToLabelsr+s> {u ZZ F bzS c Mrc t|tr|jd}t|tsBt dj tj tj |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 {}) isinstancestrencoder~ TypeErrorrrtype)domains r domainStringr?s],&#v& fe $ 9 @ @ fd6l   Mrct|j}t|j}|t| d|k(S)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)rlowerlen)descendantName ancestorNamedescendantLabelsancestorLabelss r_isSubdomainOfr`sF2%^%9%9%;<"<#5#5#78N S002 3~ EErcd}|jj}|D]2\}}|j|stt |dd|zcS t|S#t $rt d|zwxYw)zm mypy doesn't like type-punning str | bytes | int | None into a str so we have this helper function. ))Sr)M<)ri)DiQ)Wi: )Yi3Nrz!Invalid time interval specifier: )upperstripendswithintfloat ValueError)ssuffixessuffmults r _str2timer~sH  A- d ::d uQsV}t+, ,-B1v B?@ @ rNc|j}t|}|jt||j|y)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)rrwriter)rrrrinds rrzCharstr.encodes2&k JsO$ Frc^d|_tt|d}t|||_y)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}. rrN)rordr)rrrrs rrzCharstr.decodes*  eQ' (#E1- rc`t|tr|j|jk(StSr)rrirNotImplementedrothers r__eq__zCharstr.__eq__s% eW %;;%,,. .rc,t|jSr)hashrrs r__hash__zCharstr.__hash__sDKK  rc,t|jS)zI Represent this L{Charstr} instance by its string value. )rrrs r__str__zCharstr.__str__sDKK((rr)rr~rrobjectreturnboolr r) rrrrrrrrr rrrriris   . !)rric@eZdZdZd d dZd dZd dZd dZdZd dZ y)rkz 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} c$t||_y)zM @param name: A name. @type name: L{bytes} or L{str} N)rr)rrs rrz Name.__init__*s !& rNc|j}|r|T||vr,|jtjdd||zy|j t j z||<|jd}|dkDr|d|||dzd}}n|}d}t|}|jt||j||r|jdy)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!Hirrr) rrrpacktellrj headerSizefindrr)rrrrrlabels rrz Name.encode1syy#8#KK D&8D>2I JK%*ZZ\G4F4F%FHTN))D/CQw"4Cj$sQwy/t%j KK 3 ( KK !"  Grct}d|_d} tt|d}|dk(r|dkDr|j |y|dz dk(re|dzdztt|dz}||vr t d |j ||dk(r|j}|j |t||}|jdk(r||_n|jd z|z|_) 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). rrrNrr?z Compression loop in encoded namer)setrrrseekraddr)rrrvisitedoffrnew_offrs rrz Name.decodeRs% M%+,AAv7JJsOQ1}r6a-#mE1.E*FFg%$%GHH G$!8**,C 7#!%+EyyC!  II,u4 'rct|tr5|jj|jjk(StSr)rrkrrrrs rrz Name.__eq__xs5 eT "99??$ (8(8(:: :rc,t|jSrrrrs rrz Name.__hash__}DIIrc,t|jS)zE Represent this L{Name} instance by its string name. rrrs rr z Name.__str__sDII&&rr )r bytes | strrr r) rrrrrrrrrr rrrrkrk s''B$5L 'rrkcLeZdZdZdeefd dZd dZd dZdZ dZ d d Z d d Z y)rlz 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} rc@t||_||_||_y)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)rkrrclsrrrr,s rrzQuery.__init__sJ  rNc|jj|||jtjd|j |j yN!HH)rrrrrrr,rrrs rrz Query.encodes7 ) FKKtyy$((;)regetrrhrdr,rrtcs rr z Query.__str__sq OO II{tyy.4992LM    dhh(A B 1QCq1--rcjd|jjd|jd|jdS)NzQuery(r))rrr,rs r__repr__zQuery.__repr__s. )DII=488,aHHr)rUnion[bytes, str]rrr,rrr) rrrrrr<rrrrr5r r@rrrrlrls6 25!PR =9 C.Irrlc~eZdZdZddfdddddd fZd Z dd Zed ZedZ ddZ ddZ e dZ y ) _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 rc,t|jSrr()ns rz_OPTHeader.s</rrudpPayloadSize extendedRCODEversiondnssecOKoptions)rrrGrHrIrJrKNcR||_||_||_||_|g}||_y)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. NrGrHrIrJrK)rrGrHrIrJrKs rrz_OPTHeader.__init__s4@-*   ?G rctdS)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)rkrs rrz_OPTHeader.namesCyrctS)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.rs rrz_OPTHeader.type$s  rc xt}|jD]}|j||j}t |j j |j |j|jdz|jdzz|jdzzt|j||y)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)rrr,ttlpayloadN) rrKrgetvaluermrrrGrHrIrJrc)rrrro optionBytess rrz_OPTHeader.encode/s I A HHQK jjl ####r)DLLB,>>RTATT!+.  & !rc t}|j||tt||j|_|j |}|jD]}|dvst||t|| y)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. )rrN) rmrrcrrdlengthrT fromRRHeadercompareAttributessetattrgetattr)rrrh newOptHeaderattrNames rrz_OPTHeader.decodeIss J !-qzz"BC ((+ .. IH//h h(GH Ircd}|jg}t|jj}t|jj}|j |kr@t }|j ||j||j |kr@||j|jdz |jdz dz|jdzdz |S)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} NrQrrirRrM) rTrdatarr_OPTVariableOptionrrr,rS)r,rrHeaderrK optionsBytesoptionsBytesLengthrVs rrZz_OPTHeader.fromRRHeader_s    'G"8#3#3#8#89L!$X%5%5%:%:!; ##%(::&(&q!##%(:: #<<",,",LLB&-llV+2   r)irrFNr)rrrrshowAttributesr[rpropertyrrrr classmethodrZrrrrCrCs* /0N 'R  "4I,  rrCc<eZdZdZddeffZdZdZd dZd dZ d d Z y) rcz 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 coderbrkrbr0c ||_||_y)z @type code: L{int} @param code: The option code @type data: L{bytes} @param data: The option data Nrl)rrkrbs rrz_OPTVariableOption.__init__s  rNc |jtj|j|jt |j |j zy)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)rrr_fmtrkrrbr1s rrz_OPTVariableOption.encodes6  FKK 499c$))nE QRrctj|j}t||}tj|j|\|_}t|||_y)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)rcalcsizerorrrkrb)rrrrrs rrz_OPTVariableOption.decodesK OODII &UA&"MM$))T: 6!%0 r)rrr) rrrrrrgr[rorrrrrrrcrcs3 v|45N( D  S1rrccneZdZdZdZdZdZdZdee dddf d dZ dd Z dd Z d Z dd ZeZy)rmak 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. )rrr,rSrTauthz!HHIHNrrFc B|dn |j}|?||k7r:tdtj||dtj||dt |}|dkr tdt ||_||_||_||_ ||_ ||_ y)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. NzPayload type (z) does not match given type (r?rzTTL cannot be negative) rrrer:rrkrrr,rSrTrs) rrrr,rSrTrs payloadType integralTTLs rrzRRHeader.__init__s>&od7<<  "{d': OOK=OOD$/ #h ?56 6J    rc  |jj|||jtj|j |j |j|jd|jr|j}|jj|||j}|j|dz d|jtjd||z |j|dyy)Nrrr) rrrrrfmtrr,rSrTrr)rrrprefixafts rrzRRHeader.encodes ) FKK$))TXXtxxKL <<ZZ\F LL  x 0**,C JJvz1 % KK D#,7 8 JJsA  rc|jj|tj|j}t ||}tj |j|}|\|_|_|_ |_ yr) rrrrqrxrrrr,rSrY)rrrrrrs rrzRRHeader.decodes\  OODHH %UA& MM$((D )784 48TXt}rc|jSrrsrs risAuthoritativezRRHeader.isAuthoritative%s yyrcRtj|jtj|jd|jz}tj|j d|j z}d|j |||j|jxrdxsdfzS)Nr7z-TrueFalse) rer:rrhrdr,rrSrsr;s rr zRRHeader.__str__(s OO II{tyy.4992LM    dhh(A B> II HH II & +G B   r) rrArrr,rrSrrTzOptional[IEncodableRecord]rsrrr)rrrrr[rxrYcachedResponserr<rrrrr r@rrrrmrms.J CHN#&.2333 3  3 , 33j 9  HrrmcJeZdZUdZdZdZdZded<dZd dZ d dZ d d Z d Z y) rna  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. )rr%srS)rrSNz Optional[int]rcDt||_t||_y)z^ @param name: See L{SimpleRecord.name} @type name: L{bytes} or L{str} N)rkrrrS)rrrSs rrzSimpleRecord.__init__Ks J C=rc<|jj||yr)rrr1s rrzSimpleRecord.encodeSs )rcXt|_|jj|yr)rkrrrrrs rrzSimpleRecord.decodeVsF  rc,t|jSrr%rs rrzSimpleRecord.__hash__Zr&rrNr) rrrrrgr[r__annotations__rrrrrrrrrnrn8s7 5N'D- D!* rrnceZdZdZeZdZy)rXz& An authoritative nameserver. r,N)rrrrr,r fancybasenamerrrrXrX_s DMrrXceZdZdZeZdZy)rQzX A mail destination. This record type is obsolete. @see: L{Record_MX} r%N)rrrrr%rrrrrrQrQh DMrrQceZdZdZeZdZy)rRzV A mail forwarder. This record type is obsolete. @see: L{Record_MX} r&N)rrrrr&rrrrrrRrRurrrRceZdZdZeZdZy)rMz* The canonical name for an alias. rN)rrrrrrrrrrrMrMs DMrrMceZdZdZeZdZy)rPzJ A mailbox domain name. This is an experimental record type. r$N)rrrrr$rrrrrrPrP DMrrPceZdZdZeZdZy)rSzH A mail group member. This is an experimental record type. r'N)rrrrr'rrrrrrSrSrrrSceZdZdZeZdZy)rUzN A mail rename domain name. This is an experimental record type. r)N)rrrrr)rrrrrrUrUrrrUceZdZdZeZdZy)rZz A domain name pointer. r/N)rrrrr/rrrrrrZrZs DMrrZceZdZdZeZdZy)rNa[ 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} r N)rrrrr rrrrrrNrNs  DMrrNcLeZdZdZdZeZdZd dZd dZ d dZ dZ d dZ e Z d Zy) rIa  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. addressrSNct|tr|jd}tj|}||_t ||_y) @type address: L{bytes} or L{str} @param address: The IPv4 address associated with this record, in quad-dotted notation. rN)rr~rsocket inet_atonrrrSrrrSs rrzRecord_A.__init__s> gu %nnW-G""7+ C=rc:|j|jyrrrr1s rrzRecord_A.encode DLL!rc&t|d|_y)Nrrrrs rrzRecord_A.decodes$UA. rc,t|jSrrrrs rrzRecord_A.__hash__DLL!!rcDd|jd|jdS)Nz > KK  ud + rcXtjdt|dd|_t d|jz dz |_|j r.dd|j z zt||j z|_|jr|jj|yy)Nrrrrrrr) rrrrrr~rryrrs rrzRecord_A6.decode=st]5!-DEaH#.#56 ::!R$**_5 eTZZ8XXDK >> KK  u % rc:t|tr|j|jk(xrk|j|j d|j|j dk(xr4|j |j k(xr|j |j k(StSr)rrJrrr~ryrSrrs rrzRecord_A6.__eq__Es eY '%//1*KK .%,, {}2MM*KK5<</*HH )   rcvt|j|j|j d|jfSr)rrrr~ryrs rrzRecord_A6.__hash__Os-T^^T[[$**%?MNNrcd|jtjt|j|j |j fzS)Nz)ryrrrrrrSrs rr zRecord_A6.__str__Rs=' KK   Xt{{ 3 NN HH +   r)rrrN)rrrr)ryr)rSUnion[str, bytes, int, None]rr r)rrrrrrrrgr[rhrrrrrrr rrrrJrJs6 DMUN@ 77 "!,0 !!! ! * !.,&O rrJc>eZdZdZeZdZdZdZd dZ d dZ d dZ d Z y) r^a: 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} r3)priorityweighttargetportrS)rr)rrrrrSNct||_t||_t||_t ||_t ||_y)zb @param target: See L{Record_SRV.target} @type target: L{bytes} or L{str} N)rrrrrkrrrS)rrrrrrSs rrzRecord_SRV.__init__s; H  &k I 6l C=rc|jtjd|j|j|j |j j|dyN!HHH)rrrrrrrrr1s rrzRecord_SRV.encodes= FKK t{{DIINO 5$'rc tjdt|tjd}|\|_|_|_t|_|jj|yr) rrrrqrrrrkrrrs rrzRecord_SRV.decodesO MM&-vv7N"O P01- t{DIf  5!rcpt|j|j|j|jfSr)rrrrrrs rrzRecord_SRV.__hash__s&T]]DKKDKKHIIr)rrrrNr) rrrrr3rrr[rgrrrrrrrr^r^[s4 D DMGVN !( " Jrr^cLeZdZdZeZdZdZdZ d dZ d dZ d dZ d Z y) rWa 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 preferenceflagsserviceregexp replacementr+)rr)rrr)rrr)rrr)rrrrSNct||_t||_t||_t||_t||_t||_t||_ y)zs @param replacement: See L{Record_NAPTR.replacement} @type replacement: L{bytes} or L{str} N) rrrrirrrrkrrrS)rrrrrrrrSs rrzRecord_NAPTR.__init__sTZ j/U^ w' fo  ,C=rcX|jtjd|j|j|j j |d|jj |d|jj |d|jj |dyr/) rrrrrrrrrrr1s rrzRecord_NAPTR.encodesu FKKtzz4??CD %& E4( 5$' t,rc tjdt|tjd}|\|_|_t |_t |_t |_ t|_ |jj||jj||jj||jj|yr/) rrrrqrrrirrrrkrrrs rrzRecord_NAPTR.decodes MM%ufooe6L!M N&'# DOY y i 6 %  E" 5! &rct|j|j|j|j|j |j fSr)rrrrrrrrs rrzRecord_NAPTR.__hash__ s@         r)rrrrrrNr) rrrrr+rr[rrgrrrrrrrrWrWsP*X DMN !,- '  rrWc>eZdZdZeZdZdZdZd dZ d dZ d dZ d Z y) rLa 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)subtypehostnamerS)r)rrrrSNcdt||_t||_t ||_y)zj @param hostname: See L{Record_AFSDB.hostname} @type hostname: L{bytes} or L{str} N)rrrkrrrS)rrrrSs rrzRecord_AFSDB.__init__6s% 7| X C=rc|jtjd|j|jj ||yNr)rrrrrrr1s rrzRecord_AFSDB.encode?s1 FKKdll34 UH-rc tjdt|tjd}|\|_|j j |yr)rrrrqrrrrs rrzRecord_AFSDB.decodeCs= MM$ eV__T5J K L U#rcDt|j|jfSr)rrrrs rrzRecord_AFSDB.__hash__HsT\\4==122rrrNr) rrrrrrrr[rgrrrrrrrrLrLs2( DM6GN!.$ 3rrLc>eZdZdZeZdZdZdZd dZ d dZ d dZ d Z y) r[a 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} r0)mboxtxtrS))rrr)rrrrSNcdt||_t||_t||_y)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)rkrrrrS)rrrrSs rrzRecord_RP.__init__fs%J 9C=rct|jj|||jj||yr)rrrr1s rrzRecord_RP.encoders( ) x(rct|_t|_|jj||jj|yr)rkrrrrs rrzRecord_RP.decodevs6F 6  rcDt|j|jfSr)rrrrs rrzRecord_RP.__hash__|TYY)**rrrNr) rrrrr0rrr[rgrrrrrrrr[r[Ls2$ DM.JN !) +rr[cfeZdZdZeZdZdefdefdfZdZ d ddZ dd Z dd Z dd Z d Zy)rOa 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!cpuosrS)rrrSNcB||c|_|_t||_yr)rrrrS)rrrrSs rrzRecord_HINFO.__init__s  $'C=rc|jtjdt|j|jz|jtjdt|j |j zyr)rrrrrrr1s rrzRecord_HINFO.encodesR FKKc$((m4txx?@ FKKc$''l3dgg=>rctjdt|dd}t|||_tjdt|dd}t|||_y)Nrrr)rrrrr)rrrrrs rrzRecord_HINFO.decodesVmmD-q"9:1= , ]]4ua!8 9! <r*rc<t|tr|jj|jjk(xrP|jj|jjk(xr|j |j k(St Sr)rrOrrrrSrrs rrzRecord_HINFO.__eq__sn e\ * 588>>#33*HHNN$ (99*HH )  rc|t|jj|jjfSr)rrrrrs rrzRecord_HINFO.__hash__s'TWW]]_dhhnn&6788rr)rr~rr~rSrrr )rrrrr!rrrrgr[rrrrrrrrrOrOso  DMj)D*+=uEN,,0 ! ! !* !?+ 9rrOcFeZdZdZeZdZdZdZdZ dZ d dZ d dZ d dZ d Zy) rTa 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()rmailbxemailbxrS))rresponsibilityr)rerrorsrrScft|t|c|_|_t||_y)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)rkrrrrS)rrrrSs rrzRecord_MINFO.__init__s'&*']DM" dlC=rct|jj|||jj||yr)rrrr1s rrzRecord_MINFO.encodes* E8, E8,rcttc|_|_|jj||jj|yr)rkrrrrs rrzRecord_MINFO.decodes:%)VTV" dl E" E"rcDt|j|jfSr)rrrrs rrzRecord_MINFO.__hash__sT\\4<<011rrr)rrrrr(rrrrr[rgrrrrrrrrTrTs>* DGGM5N !-# 2rrTc>eZdZdZeZdZdZdZd dZ d dZ d dZ d Z y) rVa 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*)rrrS)rrrSNc t||_t|jd||_t ||_y)z\ @param name: See L{Record_MX.name}. @type name: L{bytes} or L{str} exchangeN)rrrkr:rrrS)rrrrSkwargss rrzRecord_MX.__init__ s1 j/J56 C=rc|jtjd|j|jj ||yr)rrrrrrr1s rrzRecord_MX.encodes1 FKKdoo67 )rctjdt|dd|_t |_|j j |y)Nrrr)rrrrrkrrrs rrzRecord_MX.decodes; --mE1.EFqIF  rcDt|j|jfSr)rrrrs rrzRecord_MX.__hash__sT__dii011rrr) rrrrr*rrr[rgrrrrrrrrVrVs2 DM5BN!* 2rrVcVeZdZdZdZdZdZeZdZ dZ dZ dZ dZ dZdd Zdd Zdd Zd Zy )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 } r5 algorithmfingerprintType fingerprintrS)r)r*r+rrrrc<||_||_||_||_yrr()rr)r*r+rSs rrzRecord_SSHFP.__init__Ms ".&rNc|jtjd|j|j|j|j y)N!BB)rrrr)r*r+r1s rrzRecord_SSHFP.encodeSs7 FKKt~~t7K7KLM D$$%rctjdt|d}|\|_|_t||dz |_y)Nr.r)rrrr)r*r+rs rrzRecord_SSHFP.decodeWs; MM%ua!8 912.-( ;rcZt|j|j|jfSr)rr)r*r+rs rrzRecord_SSHFP.__hash__\s$T^^T%9%94;K;KLMMr)rrrrr)rrrrrr[rgr5r ALGORITHM_RSA ALGORITHM_DSSALGORITHM_ECDSAALGORITHM_Ed25519FINGERPRINT_TYPE_SHA1FINGERPRINT_TYPE_SHA256rrrrrrrr_r_ sT:MNDN DMMO &< Nrr_cDeZdZdZeZdZdefdfZdZ dZ d dZ d d Z d Z y) raz 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. r4rbrSrbrScdt||_t|jdd|_y)NrS)rrbrr:rS)rrbkws rrzRecord_TXT.__init__rs$J BFF5$/0rNc |jD]3}|jtjdt ||z5yr)rbrrrr)rrrds rrzRecord_TXT.encodews5 7A KK D#a&1A5 6 7rc"d}g|_||krVtjdt|dd}|jj t||||dzz }||krV||k7r&t j d||j|fzyy)Nrrrz1Decoded %d bytes in %s record, but rdlength is %d)rbrrrrrmsgr)rrrsoFarLs rrzRecord_TXT.decode{s fn dM%$;tt|jSr)rtuplerbrs rrzRecord_TXT.__hash__sE$))$%%rr)rrrrr4rrrrgr[rrrrrrrrara`s< DM~.6N'1 7 &rracFeZdZdZdZdZdZdefdfZd dZ d dZ d d Z d Z y) rca> 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 NUNKNOWNr8rbrSc2||_t||_yr)rbrrS)rrbrSs rrzUnknownRecord.__init__s C=rc:|j|jy)zc Write the raw bytes corresponding to this record's payload to the stream. N)rrbr1s rrzUnknownRecord.encodes  DIIrc@| tdt|||_y)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) Exceptionrrbrs rrzUnknownRecord.decodes# >GH H!%0 rcDt|j|jfSr)rrbrSrs rrzUnknownRecord.__hash__r rrr) rrrrrrr[rrgrrrrrrrrcrcs<  DM'z*E2N!1+rrcceZdZdZeZdZy)r]ao 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. r2N)rrrrr2rrrrrr]r]s  DMrr]cReZdZdZdZdZgdZeZddddde ddfd Z d d Z d d Z d Z y)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. r6)r) timeSignedfudgeMAC originalIDerror otherDatarS)r)rLrNrPrQNrrrc |dn t||_||_t||_||_||_||_||_||_ yr) rkr)rLrrMrNrOrPrQrS) rr)rLrMrNrOrPrQrSs rrzRecord_TSIG.__init__sK "+!2Y$e_ $ "rc .|jj|||jtjd|j dd|jtjd|j t|j|j|j|jtjd|j|jt|j|j|jy)Nz!Qrr0r) r)rrrrrLrMrrNrOrPrQr1s rrzRecord_TSIG.encode s eX. FKKdoo6qr:; FKKtzz3txx=AB DHH KKS=P Q   DNN#rcRt}|j|||_tjddt |dz}|\|_|_}t |||_tjdt |d}|\|_ |_ }t |||_ y)Nz!QHHs rr) rkrr)rrrrLrMrNrOrPrQ)rrrr)fields macLength otherLengths rrzRecord_TSIG.decode sF "v{]5"5M'MN17.Y  2v}UA'>?390[&uk:rcpt|j|j|j|jfSr)rr)rLrNrOrs rrzRecord_TSIG.__hash__% s&T^^T__dhhPQQrr)rrrrrr[rgr6rrrrrrrrrrr`r`sR8M NN D  2$ ;Rrr`c X|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)idanswerNr)r[queries)responseConstructormessager#responses r_responseFromMessagera) s2,#HgjjHHHq)H Orcg}tj|jj}|D]I}|j|j }t |||}||vs||k7s3|jd|d|K|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. r8=)inspect signature __class__r parametersdefaultr]r)obj alwaysShow fieldNamesdisplayableArgsrer defaultValue fieldValues r_getDisplayableArgumentsroD sO!!#--"8"89I> ++D199 S$ 5 J J,$>  " "QtfAj^#< = > rc|g}|g}|g}|g}g}|D](}||vst||ddk(s|j|*t|||}d|jjg|z}|r/|jdj dj ||D])}t||g} | s|jd|d| +|jdd j |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}. FT}. @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)rr[r\r{rsrr|r}r~rrr]rrr) rr[r\r{r|r}rsr~rrrrs rrzMessage.__init__ spT        * 0  rc"t|ddddS)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\rsrr|r}rr)r[r{r~rr]rrrr[rtrkrurjryrs rr@zMessage.__repr__0 s$ <J  rcP|jjt|||y)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]rrlr-s raddQueryzMessage.addQueryI s E$c23rc~i}t}|jD]}|j|||jD]}|j|||jD]}|j|||j D]}|j|||j }t||jz}|jr2||jkDr#d|_ |d|j|jz }|jdzdz|jdzdzz|jdzdzz|jdzdzz|jdzz}|jdzdz|j dzdzz|j"dzdzz|j$dzz}|j't)j*|j,|j.||t|jt|jt|jt|j |j'|y)NrrRrrrr)rr]rrrrrUrrrrr\r{rsr|r}rrr~rrr headerFmtr[) rrrbody_tmpqbodysizebyte3byte4s rrzMessage.encodeX s9 )A HHXx ( ) )A HHXx ( ) )A HHXx ( ) )A HHXx ( )  "4y4??* <UV +DAq   aE * +   sE EEct|D]}t|j} |j||j |j }|sI||j|_ |jj||j|j|y#t$rYywxYw#t$rYywxYw)Nr~)rS) rrmrsrrlookupRecordTyperrSrTrYr)rrnumrrrr<s rrzMessage.parseRecords ss A499-F  e$%%fkk2A6::.FN %%eV__= KK      s#B(.&B8( B54B58 CCRecord_cB|jj|tS)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]} ) _recordTypesr:rc)rrs rrzMessage.lookupRecordType s  $$T=99rcXt}|j||jS)z Encode this L{Message} into a byte string in the format described by RFC 1035. @rtype: L{bytes} )rrrU)rrs rtoStrz Message.toStr s$  E~~rc<t|}|j|y)z Decode a byte string in the format described by RFC 1035 into this L{Message}. @param str: L{bytes} N)rr)rrrs rfromStrzMessage.fromStr s  Errr)rrrrr[rrrqrr]rrnsrrrr@r=r<rrrrrglobalsr startswithrrrrrrrrjrj s&P$I +J$('G'g'b  Yv 2#.2 4*X+: *L A ??9 %184L4-- .A  :  rrjcleZdZdZdZeZddeddddddddddddddfdZd dZ d Z d Z e d Z d Zy) _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{rsrr|r}r~ ednsVersionrJrrrr]rrrrFrNc||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ |g}||_ |g}||_|g}||_|g}||_y)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)rr[r\r{rsrr|r}r~rrJrrrr]rrrs rrz_EDNSMessage.__init__ sZ       &  * 0 ?G ?G  I"  J$rc"t|ddddS)N)r\rsrr|r}rrrJ)r[r{r~rrrrrrrs rr@z_EDNSMessage.__repr__ s#  KJ  rc l|j|j|j|j|j|j |j |j|jdz|j|j }|jdd|_ |jdd|_ |jdd|_ |jdd|_|jUt!|j|j"|j$|jdz }|jj'||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} rR) r[r\r{rsrr|r}r~rrNr)rIrJrGrH)_messageFactoryr[r\r{rsrr|r}r~rrr]rrrrrCrJrr)rmrVs r _toMessagez_EDNSMessage._toMessage s  ww;;;;**;;****s",,!22 ! LLO LLO nnQ' q)    '((#||"jjAo A LL   "rc>|jjS)z~ Encode to wire format by first converting to a standard L{dns.Message}. @return: A L{bytes} string. )rrrs rrz_EDNSMessage.toStr s  &&((rcg}g}|jD]K}|jtk(r%|jtj |;|j|M|did|j d|jd|jd|jd|jd|jd|jd|jd |jd |jd d d dd|j d d d|j"d d d|j$d d d|}t'|dk(rY|d}|j(|_|j,|_|j.|_|j2dz|jz|_ |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{rsrr|r}r~rrrNrJFr]rrrrrrr)rrr.rrCrZr[r\r{rsrr|r}r~rrr]rrrrIrrJrGrrH)r,r_r optRecordsr| newMessageopts r _fromMessagez_EDNSMessage._fromMessage s*  ## %Avv}!!*"9"9!"<=!!!$  %  zz >> >>   --  >>  -- -- "// %55   OOA& OOA&! "''*# $"% * z?a Q-C%([[J ""%,,J !$!3!3J "00A5 EJ rc |j}|j||j|}|jD]}t ||t ||y)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[r\r])rr~r ednsMessager`s rrz_EDNSMessage.fromStr, sX  " %''* .. DH D(GK$B C Drr)rrrrr[rjrrurr@rrrirrrrrrr s~%N(O  %I%V $(T)::x Drrc8eZdZdZdZdZddZdZdZdZ dZ y) rpz DNS protocol mixin shared by UDP and TCP implementations. @ivar _reactor: A L{IReactorTime} and L{IReactorUDP} provider which will be used to issue DNS queries and manage request timeouts. Ncf||_tjdd|_|ddlm}||_y)Niir)reactor) controllerrandom randranger[twisted.internetr_reactor)rrrs rrzDNSMixin.__init__G s,$""5%0 ? 0 rc: t}||jvr|S)z1 Return a unique ID for queries. )r liveMessagesrr[s rpickIDzDNSMixin.pickIDN s&B*** rc>|jj||g|S)zL Wrapper around reactor.callLater, mainly for test purpose. )r callLater)rperiodfuncargss rrzDNSMixin.callLaterW s"'t}}&&vt;d;;rc t|d}||_ ||tj }|j ||j||}||f|j|<|S#t$rtjcYSwxYw)a Send out a message with the given queries. @type queries: L{list} of C{Query} instances @param queries: The queries to transmit @type timeout: L{int} or C{float} @param timeout: How long to wait before giving up @type id: L{int} @param id: Unique key for this request @type writeMessage: C{callable} @param writeMessage: One-parameter callback which writes the message @rtype: C{Deferred} @return: a C{Deferred} which will be fired with the result of the query, or errbacked with any errors that could happen (exceptions during writing of the query, timeout errors, ...). r)r|) rjr] BaseExceptionrfailDeferredr _clearFailedr)rr]timeoutr[ writeMessagerresultDeferred cancelCalls r_queryzDNSMixin._query] s* Bq !  O)^^GT->->PRS !/ <" ::<  sA##BBc |j|=|jtjt |y#t$rY9wxYw)z5 Clean the Deferred after a timeout. N)rKeyErrorerrbackrFailurerz)rdeferredr[s rrzDNSMixin._clearFailed sH !!"% )=b)ABC   s = A A r) rrrrr[rrrrrrrrrrprp< s. BL < !FDrrpc@eZdZdZdZdZdZdZdZdZ dZ d d Z y) roz DNS protocol over UDP. Nc.i|_i|_d|_y)z7 Stop protocol: reset state variables. N)rresends transportrs r stopProtocolz DNSDatagramProtocol.stopProtocol s rc i|_i|_y)z3 Upon start, reset internal state. N)rrrs r startProtocolz!DNSDatagramProtocol.startProtocol s rcX|jj|j|y)X Send a message holding DNS queries. @type message: L{Message} N)rrr)rr_rs rrz DNSDatagramProtocol.writeMessage s W]]_g6rc@|jjd|dy)Nrr) maxPacketSize)r listenUDPrs rstartListeningz"DNSDatagramProtocol.startListening s 4s;rct} |j||j|jvrV|j|j\}}|j|j=|j |j|y|j|jvr|j j#|||yy#t$r&tjdt ||fzYyt $r%}tjd|d|Yd}~yd}~wt$r+tjtjdYywxYw#t$rtjYywxYw)zi Read a datagram, extract the message in it and trigger the associated Deferred. z#Truncated packet (%d bytes) from %sNzInvalid packet (z) from zUnexpected decoding error)rjrrrr>rrrerrrrr[rcancelcallbackrrmessageReceived)rrbaddrrexr< cancellers rdatagramReceivedz$DNSDatagramProtocol.datagramReceived s3 I  IIdO 444$$ $,,QTT2LAy!!!$$'      1 tt4<<'//4>(1  GG9SY |j|=y#t$rYywxYw)zN Mark message ID as no longer having duplication suppression. N)rrrs r removeResendz DNSDatagramProtocol.removeResend s%  R    s  cjs j|j }ndj |<fd}j||||S#t$rtjcYSwxYw)a4 Send out a message with the given queries. @type address: L{tuple} of L{str} and L{int} @param address: The address to which to send the query @type queries: L{list} of C{Query} instances @param queries: The queries to transmit @rtype: C{Deferred} rc*j|yr)r)rrrs rrz/DNSDatagramProtocol.query..writeMessage s   a )r)rrrrrrrr)rrr]rr[rs`` rqueryzDNSDatagramProtocol.query sv~~ $##% :B DLL  *{{7GR>>% $zz|# $sAA<;A<)rUN) rrrrrrrrrrrrrrrroro s2G7<!?F?rroc8eZdZdZdZdZdZdZdZdZ d dZ y) rqz DNS protocol over TCP. Nrc|j}|jjtjdt ||zy)rrN)rrrrrr)rr_rs rrzDNSProtocol.writeMessage s5 MMO V[[s1v6:;rcHi|_|jj|y)zV Connection is made: reset internal state, and notify the controller. N)rrconnectionMaders rrzDNSProtocol.connectionMade s &&t,rc:|jj|y)zZ Notify the controller that this protocol is no longer connected. N)rconnectionLost)rreasons rrzDNSProtocol.connectionLost s &&t,rcn|xj|z c_|jrE|jWt|jdk\r?tjd|jddd|_|jdd|_t|j|jk\r|jd|j}t }|j | |j|j\}}|j|j=|j |j||j|jd|_d|_ny|jrDyy#t$rtjYVwxYw#t$r|jj!||YwxYw)Nrrr)bufferrrrrrjrrr[rrrrrrrr)rrbmyChunkrr<rs r dataReceivedzDNSProtocol.dataReceived sU t kk{{"s4;;'71'<$mmD$++bq/B1E "kk!"o 4;;4;;.++m 4I '" "#'#4#4QTT#:LAy))!$$/$$&" 1 #kk$++-8 " 5kk()" " =OO33At<=s$F !E))F F  %F43F4c^|j}|j||||jS)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} )rrr)rr]rr[s rrzDNSProtocol.query4 s*[[]{{7GR1B1BCCr)r) rrrrrrrrrrrrrrrqrq s-F F<--> Drrq)rz str | bytesr r~)rrr r)rzUnion[str, bytes, int]r r)rNoner r)rrr zUnion[int, None])NNNN) rir rjSequence[str] | Nonertr rkr rur r r)r __future__rrdrrrior itertoolsrtypingrrrr r zope.interfacer r r rrrtwisted.internet.errorrtwisted.pythonrrrrtputiltwisted.python.compatrrr__all__rrrrrrxrrr,r%r&rr1r$r'r)r-r7r/r!r(r*r4r0rrr3r+rr r.r5r2rr6rer?r>r#r"r=rhrrgr<r:r9r;r8rdrfrursrvrtrwrrr@rDrArBrCrErFrGrHrtwisted.names.errorryrzr{rrrrrrrrrirkrl FancyStrMixin FancyEqMixinrCrcrmrnrXrQrRrMrPrSrUrZrNrIr\rYrbrKrJr^rWrLr[rOrTrVr_rarcr]r`raroryrjrrpDatagramProtocolroProtocolrq)kvs00rrs-   # CC<<-4BB??e P ??CK * !RL'          s   7    & 7 7 !"#$ 7& 7 7 7&&; @).c3%dE5+ && 7 7  !&k&7&7&9;;L;L;N O Pfq!QT P q!BB T2tRr4eD "/"5"5"78Aq!t8 #((*i 27q.GWeWh "2r](EiE(BF<B,     4$ $ Nz7 Z.).).)b Zc'c'c'L  Z9I9I 9Ix Zw %%v':':w w t Z91--v/B/B9191x Zwv""wwt "6'')<)<""L     <    <   ..v""....b p $$f&:&:p p f "&&&(;(;""> 9=$$f&:&:9=9=x +"&%%v';';+"+"\ ` $$f&9&9` ` F @J$$f&:&:@J@JF w 6&&(<(<w w t .36'')<)<.3.3b 0+##V%9%90+0+f 296'')<)<2929j 826&&(<(<8282v *2$$f&9&9*2*2Z <N6&&(<(<<N<N~ (&$$f&:&:(&(&V )+F'')=)=)+)+X" [R&%%v';';[R[R|64(,&*'+)- 5 5$5$5% 5 ' 5  5pKf!!K\ WD6&&WDt LDLD^h?(H$=$=h?VHD(H--HDg_ Q 9s ? Z1? Z7