/usr/lib/python3/dist-packages/twisted/names/__pycache__
NameSizeModeActions
authority.cpython-310.pyc147360644editdlrm
cache.cpython-310.pyc38830644editdlrm
client.cpython-310.pyc221710644editdlrm
common.cpython-310.pyc91360644editdlrm
dns.cpython-310.pyc987720644editdlrm
error.cpython-310.pyc27820644editdlrm
hosts.cpython-310.pyc50830644editdlrm
resolve.cpython-310.pyc33830644editdlrm
root.cpython-310.pyc119200644editdlrm
secondary.cpython-310.pyc78850644editdlrm
server.cpython-310.pyc211750644editdlrm
srvconnect.cpython-310.pyc86970644editdlrm
tap.cpython-310.pyc45730644editdlrm
_rfc1982.cpython-310.pyc85700644editdlrm
__init__.cpython-310.pyc2160644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/names/__pycache__/dns.cpython-310.pyc (98772B)
o pj@s6UdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZmZmZddlmZmZdd lmZdd lmZmZmZmZdd lm Z m!Z!m"Z"gd Z#ej$Z$d dZ%ddZ&ddZ'ddZ(dZ)e*dd\Z+Z,Z-Z.Z/Z0Z1Z2Z3Z4Z5Z6Z7Z8Z9Z:Z;ZdZ?dZ@dZAdZBdZCdZDd ZEd!ZFie+d"e,d#e-d$e.d%e/d&e0d'e1d(e2d)e3d*e4d+e5d,e6d-e7d.e8d/e9d0e:d1e;d2ed5e?d6e@d7eAd8eBd9eCd:eDd;eEdd?\ZHZIZJZKZLeHd@eIdAeJdBeKdCeLdDiZMdEdFe eGNeMNDZOe*ddG\ZPZQZRZSdHZTePdIeQdJeRdKeSdLeTdMiZUdNdFeUNDZVe*dO\ZWZXZYdPZZdGZ[e*dQ\Z\Z]Z^Z_Z`ZadRZbe*dRd\ZcZdZeGdSdTdTeZfddUlgmhZhmiZimjZjdVdWZkdXdYZldZd[Zmd\d]Znd^d_ZoGd`dadaepZqGdbdcdcZrejsddddeZtejserdBeudf<edgerfdhdiZvGdjdkdkeZwGdldmdmewefZxeewGdndodoZyeewGdpdqdqZze!eewGdrdsdsZ{eewGdtduduej|ej}Z~eewGdvdwdwej|ej}ZeewGdxdydyej}ZeexGdzd{d{ej|ej}ZGd|d}d}eZGd~ddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZeexGdddej}ZeexGdddej}ej|ZeexGdddej|ej}ZeexGdddej}ej|ZeexGdddej}ej|ZeexGdddej|ej}ZeexGdddej}ej|ZeexGdddej}ej|ZeexGdddej|ej}ZeexGdddej}ej|ZeexGdddej|ej}ZeexGdddej}ej|ZeexGdddej|ej}ZeexGdddej}ej|ZeexGdddej}ej|ZeexGdddej}ej|ZGdddeZeexGdddej}ej|ZddZddZ dddZGdddej}ZGdddej}ZGdddZGdddeejZGdddeejZdS)zU DNS protocol implementation. Future Plans: - Get rid of some toplevels, maybe. N)contextmanager)BytesIO)chain)Optional SupportsIntUnion) Attribute Interface implementer)deferprotocol)CannotListenError)failurelog randbytesutil)cmp comparable nativeString)e 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_UPDATEPORTAuthoritativeDomainErrorDNSDecodeErrorDNSQueryTimeoutError DomainErrorcCs t|gS)z Construct a bytes object representing a single byte with the given ordinal value. @type ordinal: L{int} @rtype: L{bytes} bytes)ordinalr}3/usr/lib/python3/dist-packages/twisted/names/dns.py _ord2bytess rcCst|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)reprrzr}r}r~ _nicebytessrcCsdddd|DS)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).0br}r}r~ sz"_nicebyteslist..)formatjoin)listr}r}r~_nicebyteslistsrcCstdtjddddS)z Wrapper around L{twisted.python.randbytes.RandomFactory.secureRandom} to return 2 random bytes. @rtype: L{bytes} HT)fallbackr)structunpackr secureRandomr}r}r}r~ randomSourcesr5r!#&'),crr)r"r#rr.r!r$r&r*r4r,rr%r'r1r-rrr0r(rrr+r2r/TKEYr3r<r;r rr:cCi|]\}}||qSr}r}rkvr}r}r~ rr9r7r6r8r5cCrr}r}rr}r}r~r rc@seZdZdZedZdS)rz0 A single entry in a zone of authority. z,An indicator of what kind of record this is.N)__name__ __module__ __qualname____doc__rTYPEr}r}r}r~rs r)rvrxrycCs2|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} ).rr)splitappend)namelabelsr}r}r~ _nameToLabels-s     rcCs>t|tr |d}t|tstdtjtj|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)domainr}r}r~ domainStringAs   rcCs.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)rlowerlen)descendantName ancestorNamedescendantLabelsancestorLabelsr}r}r~_isSubdomainOfbs  rcCsd}t|tr |d}t|trF|}|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<)ri)DiQ)Wi: )Yi3asciiNrz!Invalid time interval specifier: ) rr{decoderupperstripendswithintfloat ValueError)ssuffixessuffmultr}r}r~str2times         rcCs||}t||kr t|SN)readrEOFError)filelbuffr}r}r~ readPreciselys  rc@eZdZdZdS)rwzl Raised when a DNS message cannot be decoded because it violates a protocol-level safety limit. Nrrrrr}r}r}r~rwrwc@s2eZdZdZdZd deddfddZd d d ZdS) _DecodeContexta Mutable state shared between the L{IEncodable} decoders invoked while reading a single DNS message. The primary purpose is to bound the total number of compression-pointer jumps taken across every name in the message, defending against packets that fan out thousands of records pointing to deeply chained pointers. This class is private. External callers must not rely on it; the per-message scope is installed and torn down by L{Message.decode} through L{_decodeContextVar}. @ivar jumps: The number of compression pointers followed so far. @ivar maxJumps: The inclusive upper bound on L{jumps}. Exceeding it causes L{registerJump} to raise L{DNSDecodeError}. jumpsmaxJumpsrreturnNcCsd|_||_dS)Nrr)selfrr}r}r~__init__s z_DecodeContext.__init__cCs0|jd7_|j|jkrtd|jddS)aq Record that a compression pointer has been followed. The check is performed before any further bytes are read so the caller fails fast as soon as the aggregate limit is breached, even if additional records remain in the buffer. @raise DNSDecodeError: if the cumulative number of jumps exceeds L{maxJumps}. rzCToo many compression pointers while decoding DNS message (limit is )N)rrrwrr}r}r~ registerJumps z_DecodeContext.registerJump)r)rN)rrrr __slots__rrrr}r}r}r~rs r_dnsDecodeContext)default_decodeContextVarcontextc cs0t|}z |VWt|dSt|w)ah Install C{context} on L{_decodeContextVar} for the duration of the C{with} block and restore the previous value on exit. This wraps the L{contextvars.ContextVar.set} / L{contextvars.ContextVar.reset} token dance so call sites can use a plain C{with} statement. @param context: The L{_DecodeContext} to install as the active context. N)rsetreset)rtokenr}r}r~_installDecodeContexts  rc@s$eZdZdZdddZdddZdS)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. NcCdS)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})striocompDictr}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})rlengthr}r}r~rrzIEncodable.decoder)rrrrrrr}r}r}r~rs rc@r)rz` Interface for DNS records that can be encoded and decoded. @since: Twisted 21.2.0 Nrr}r}r}r~r'rrc@sReZdZdddZdddZdddZd ed efd d Zd dZ d e fddZ dS)rfrcCs"t|ts t|d||_dS)Nz is not a byte string)rr{rstring)rrr}r}r~r1s  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)rrwriter)rrrrindr}r}r~r6szCharstr.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}. rrN)rordr)rrrrr}r}r~rCs zCharstr.decodeotherrcCst|tr |j|jkStSr)rrfrNotImplementedrrr}r}r~__eq__Rs  zCharstr.__eq__cC t|jSr)hashrrr}r}r~__hash__W zCharstr.__hash__cCr)zI Represent this L{Charstr} instance by its string value. )rrrr}r}r~__str__Z zCharstr.__str__rr) rrrrrrobjectboolrr rr r}r}r}r~rf/s   rfc@sdeZdZUdZdZeed<dddZddd Zdd d Z d e d e fddZ ddZ d efddZdS)rhaB 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} @ivar maxCompressionPointers: Per-message cap on the total number of compression-pointer dereferences L{decode} will follow before raising L{DNSDecodeError}. Defaults to C{1000}. Override it on a subclass or individual instance to tune the trade-off between tolerance for legitimately verbose messages and resistance to denial-of-service attacks. rmaxCompressionPointersrcCst||_dS)zM @param name: A name. @type name: L{bytes} or L{str} N)rr)rrr}r}r~rtsz Name.__init__NcCs|j}|rT|dur%||vr|tdd||BdS|tj||<|d}|dkr>|d|||dd}}n|}d}t|}|t ||||s|ddS)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) rrrpacktellrg headerSizefindrr)rrrrrlabelr}r}r~r{s"    z Name.encodec Cst}|durt|jd}t}d|_d} tt|d}|dkr-|dkr+||dS|d?dkr_|d@d >tt|dB}| ||vrLt d | ||dkrY| }||qt||}|jdkrm||_n|jd ||_q) a3 Decode a byte string into this Name. When invoked from L{Message.decode}, a shared compression-pointer counter is picked up transparently from the private L{_decodeContextVar}. Standalone callers get a fresh per-call counter seeded from L{maxCompressionPointers}, so existing code keeps working unchanged while still being protected against pathological inputs. @type strio: file @param strio: Bytes will be read from this file until the full Name is decoded. @type length: L{int} or L{None} @param length: Present for compatibility with the L{IEncodable} interface; ignored by this decoder. @raise EOFError: Raised when there are not enough bytes available from C{strio}. @raise ValueError: Raised when the name cannot be decoded because it contains a compression loop. @raise DNSDecodeError: Raised when the cumulative number of compression-pointer jumps exceeds the configured limit. Nrrrrrr?z Compression loop in encoded namer) rgetrrrrrrseekrraddr) rrrrvisitedoffrnew_offrr}r}r~rs6       z Name.decoderrcCs"t|tr|j|jkStSr)rrhrrrrr}r}r~rs z Name.__eq__cCrrrrrr}r}r~r r z Name.__hash__cCr)zE Represent this L{Name} instance by its string name. rrrr}r}r~r r z Name.__str__r r)rrrrrr__annotations__rrrrrrr rr r}r}r}r~rhas     !8rhc@sveZdZdZdeefdeeefde de fddZ dd d Z dd d Z d dZ ddZdefddZdefddZdS)riz 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} rrrclscCst||_||_||_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)rhrrr$rrrr$r}r}r~rs  zQuery.__init__NcCs*|j|||td|j|jdSN!HH)rrrrrrr$rrrr}r}r~rsz Query.encodecCs.|j|t|d}td|\|_|_dS)Nrr')rrrrrrr$)rrrrr}r}r~rs  z Query.decodecCst|jj|j|jfSr)rrrrr$rr}r}r~r  szQuery.__hash__cCs<t|trt|jj|j|jf|jj|j|jfStSr)rrirrrrr$rrr}r}r~__cmp__s z Query.__cmp__rcCsLt|jt|jd|j}t|jd|j}d|jd|d|dS)N UNKNOWN (%d)z)rbrrrerar$rrtcr}r}r~r s z Query.__str__cCs d|jjd|jd|jdS)NzQuery(rr)rrr$rr}r}r~__repr__ zQuery.__repr__r)rrrrrr9rr{rrrrrr r)r r0r}r}r}r~ris&  ric@szeZdZdZdddfddddd d fZd Z  dddZeddZeddZ dddZ dddZ e ddZ 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 rcCrrr")nr}r}r~8s z_OPTHeader.rudpPayloadSize extendedRCODEversiondnssecOKoptions)rrr5r6r7r8r9rFNcCs.||_||_||_||_|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. Nr5r6r7r8r9)rr5r6r7r8r9r}r}r~rKs  z_OPTHeader.__init__cCstdS)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)rhrr}r}r~rts 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+rr}r}r~rs 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)rrr$ttlpayloadN) rr9rgetvaluerjrrr5r6r7r8r`)rrrro optionBytesr}r}r~rs  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. )rrN) rjrr`rrdlengthr? fromRRHeadercompareAttributessetattrgetattr)rrrh newOptHeaderattrNamer}r}r~rs   z_OPTHeader.decodecCsd}|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<rrir=r;) r?rdatarr_OPTVariableOptionrrr$r>)r$rrHeaderr9 optionsBytesoptionsBytesLengthrAr}r}r~rDs"         z_OPTHeader.fromRRHeader)r:rrFNr)rrrrshowAttributesrErpropertyrrrr classmethodrDr}r}r}r~r2!s2    )   r2c@sBeZdZdZddeffZdZdZddd Zdd d Z dd dZ d S)rLz 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 coderKrSrKr'rrcCs||_||_dS)z @type code: L{int} @param code: The option code @type data: L{bytes} @param data: The option data NrT)rrSrKr}r}r~rs z_OPTVariableOption.__init__NcCs(|t|j|jt|j|jdS)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_fmtrSrrKr(r}r}r~rs( 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)rcalcsizerUrrrSrK)rrrrrr}r}r~rs z_OPTVariableOption.decode)rrr) rrrrrrPrErUrrrr}r}r}r~rLs   rLc @seZdZdZdZdZdZdZdee dddfde e e fd e d e d ed eed ef ddZdddZdddZddZde fddZeZdS)rjak 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$r>r?authz!HHIHNrrFrrr$r>r?rWc Cs|durdn|j}|dur!||kr!tdt||t||ft|}|dkr-tdt||_||_||_||_ ||_ ||_ 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) rrrbrrrhrrr$r>r?rW) rrrr$r>r?rW payloadType integralTTLr}r}r~r:s$    zRRHeader.__init__c Cs|j|||t|j|j|j|jd|j rD| }|j ||| }| |dd|td||| |ddSdS)Nrrr) rrrrrfmtrr$r>r?rr)rrrprefixaftr}r}r~ros zRRHeader.encodecCsH|j|t|j}t||}t|j|}|\|_|_|_ |_ dSr) rrrrVrZrrrr$r>rC)rrrrrrr}r}r~rzs   zRRHeader.decodecCs|jSrrWrr}r}r~isAuthoritativeszRRHeader.isAuthoritativercCsRt|jt|jd|j}t|jd|j}d|j|||j|jr%dp&dfS)Nr*z-TrueFalse) rbrrrerar$rr>rWr-r}r}r~r s zRRHeader.__str__r)rrrrrErZrCcachedResponserr9rr{rrrrrrrrrr_r r0r}r}r}r~rjs<  5  rjc@sTeZdZUdZdZdZdZeee d<dZ dddZ dd d Z dd d Z d dZdS)rka  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%sr>)rr>NrrcCst||_t||_dS)z^ @param name: See L{SimpleRecord.name} @type name: L{bytes} or L{str} N)rhrrr>)rrr>r}r}r~rs zSimpleRecord.__init__cCs|j||dSr)rrr(r}r}r~rszSimpleRecord.encodecCst|_|j|dSr)rhrrrrrr}r}r~rszSimpleRecord.decodecCrrr!rr}r}r~r r zSimpleRecord.__hash__rNr)rrrrrPrErrrr#rrrrr r}r}r}r~rks      rkc@eZdZdZeZdZdS)rUz& An authoritative nameserver. r)N)rrrrr)r fancybasenamer}r}r}r~rUrUc@rg)rNzX A mail destination. This record type is obsolete. @see: L{Record_MX} r"N)rrrrr"rrhr}r}r}r~rNrNc@rg)rOzV A mail forwarder. This record type is obsolete. @see: L{Record_MX} r#N)rrrrr#rrhr}r}r}r~rOrjrOc@rg)rJz* The canonical name for an alias. rN)rrrrrrrhr}r}r}r~rJrirJc@rg)rMzJ A mailbox domain name. This is an experimental record type. r!N)rrrrr!rrhr}r}r}r~rMrMc@rg)rPzH A mail group member. This is an experimental record type. r$N)rrrrr$rrhr}r}r}r~rPrkrPc@rg)rRzN A mail rename domain name. This is an experimental record type. r&N)rrrrr&rrhr}r}r}r~rRrkrRc@rg)rWz A domain name pointer. r,N)rrrrr,rrhr}r}r}r~rWrirWc@rg)rKa[ 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)rrrrrrrhr}r}r}r~rKs rKc@s\eZdZdZdZeZdZdddZdddZ dd d Z d d Z d e fddZ e ZddZdS)rFa  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>N0.0.0.0cCs2t|tr |d}t|}||_t||_dS) @type address: L{bytes} or L{str} @param address: The IPv4 address associated with this record, in quad-dotted notation. rN)rr{rsocket inet_atonrmrr>rrmr>r}r}r~r4s   zRecord_A.__init__cC||jdSrrrmr(r}r}r~rAzRecord_A.encodecCt|d|_dS)Nrrrmrer}r}r~rDruzRecord_A.decodecCrrrrmrr}r}r~r Gr zRecord_A.__hash__rcCsd|d|jdS)Nz rr}r}r~r JzRecord_A.__str__cC t|jSrrp inet_ntoarmrr}r}r~ryOs zRecord_A.dottedQuad)rnNr)rrrrrErrrmrrrr rr r0ryr}r}r}r~rF!s    rFc@sVeZdZdZdZdZdZeZ        ddd Z dd d Z dd d Z ddZ dS)rYaA Marks the start of a zone of authority. This record describes parameters which are shared by all records within a particular zone. @type mname: L{Name} @ivar mname: The domain-name of the name server that was the original or primary source of data for this zone. @type rname: L{Name} @ivar rname: A domain-name which specifies the mailbox of the person responsible for this zone. @type serial: L{int} @ivar serial: The unsigned 32 bit version number of the original copy of the zone. Zone transfers preserve this value. This value wraps and should be compared using sequence space arithmetic. @type refresh: L{int} @ivar refresh: A 32 bit time interval before the zone should be refreshed. @type minimum: L{int} @ivar minimum: The unsigned 32 bit minimum TTL field that should be exported with any RR from this zone. @type expire: L{int} @ivar expire: A 32 bit time value that specifies the upper limit on the time interval that can elapse before the zone is no longer authoritative. @type retry: L{int} @ivar retry: A 32 bit time interval that should elapse before a failed refresh should be retried. @type ttl: L{int} @ivar ttl: The default TTL to use for records served from this zone. r.)serialmnamernamerefreshexpireretryminimumr>))rrrd)rrrdr~rrrrr>rrNc CsZt|t||_|_t|t||_|_t|t||_|_t||_t||_ dS)z @param mname: See L{Record_SOA.mname} @type mname: L{bytes} or L{str} @param rname: See L{Record_SOA.rname} @type rname: L{bytes} or L{str} N) rhrrrr~rrrrr>) rrrr~rrrrr>r}r}r~rs  zRecord_SOA.__init__c CsD|j|||j|||td|j|j|j|j |j dS)N!LlllL) rrrrrrr~rrrrr(r}r}r~rszRecord_SOA.encodecCsXtt|_|_|j||j|tdt|d}|\|_|_|_ |_ |_ dS)Nr) rhrrrrrrr~rrrrrrrr]r}r}r~rs   zRecord_SOA.decodecC t|j|j|j|j|j|jfSr)rr~rrrrrrr}r}r~r szRecord_SOA.__hash__)rrrrrrrNr) rrrrrhrErPr.rrrrr r}r}r}r~rYSs$'     rYc@sNeZdZdZdZdefdfZdZeZ dddZ dd d Z dd d Z d dZ dS)rVz A null record. This is an experimental record type. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. r*r?r>)r?r>NcC||_t||_dSr)r?rr>)rr?r>r}r}r~rzRecord_NULL.__init__cCrsr)rr?r(r}r}r~rruzRecord_NULL.encodecCst|||_dSr)rr?rer}r}r~rruzRecord_NULL.decodecCrr)rr?rr}r}r~r r zRecord_NULL.__hash__)NNr)rrrrrhrrPrEr*rrrrr r}r}r}r~rVs     rVc@sVeZdZdZdZdZgdZeZe ddZ dd d Z dd dZ dddZ ddZd S)r_aX A well known service description. This record type is obsolete. See L{Record_SRV}. @type address: L{bytes} @ivar address: The packed network-order representation of the IPv4 address associated with this record. @type protocol: L{int} @ivar protocol: The 8 bit IP protocol number for which this service map is relevant. @type map: L{bytes} @ivar map: A bitvector indicating the services available at the specified address. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. r4)rmr mapr>)_addressrmrdr r>cCr{rr|rr}r}r~rs zRecord_WKS._addressrnrrNcCs<t|tr |d}t||_|||_|_t||_ dS)rorN) rr{rrprqrmr rrr>)rrmr rr>r}r}r~r s   zRecord_WKS.__init__cCs0||j|td|j||jdSN!B)rrmrrr rr(r}r}r~rs zRecord_WKS.encodecCs8t|d|_tdt|dd|_t||d|_dS)Nrrrrr)rrmrrr rrer}r}r~rs zRecord_WKS.decodecCt|j|j|jfSr)rrmr rrr}r}r~r  zRecord_WKS.__hash__)rnrrNr)rrrrrhrErPr4rrQrrrrr r}r}r}r~r_s    r_c@sReZdZdZeZdZdZdZe ddZ dd d Z dd d Z dd dZ ddZdS)rHaT An IPv6 host address. @type address: L{bytes} @ivar address: The packed network-order representation of the IPv6 address associated with 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/rfc1886.html} r)rr>rlcCtt|jSr)rp inet_ntopAF_INET6rmrr}r}r~r:zRecord_AAAA._address::NcCs0t|tr |d}tt||_t||_dS)z @type address: L{bytes} or L{str} @param address: The IPv6 address for this host, in RFC 2373 format. rN) rr{rrp inet_ptonrrmrr>rrr}r}r~r>s  zRecord_AAAA.__init__cCrsrrtr(r}r}r~rIruzRecord_AAAA.encodecCrv)Nrrwrer}r}r~rLruzRecord_AAAA.decodecCrrrxrr}r}r~r Or zRecord_AAAA.__hash__)rNr)rrrrrrrhrPrErQrrrrr r}r}r}r~rH$s    rHc@sreZdZdZeZdZdZdZe ddZ dd d Z dd dZ dddZ dedefddZddZdefddZd S)rGa An IPv6 address. This is an experimental record type. @type prefixLen: L{int} @ivar prefixLen: The length of the suffix. @type suffix: L{bytes} @ivar suffix: An IPv6 address suffix in network order. @type prefix: L{Name} @ivar prefix: If specified, a name which will be used as a prefix for other A6 records. @type bytes: L{int} @ivar bytes: The length of the prefix. @type ttl: L{int} @ivar ttl: The maximum number of seconds which this record should be cached. @see: U{http://www.faqs.org/rfcs/rfc2874.html} @see: U{http://www.faqs.org/rfcs/rfc3363.html} @see: U{http://www.faqs.org/rfcs/rfc3364.html} r))_suffixsuffixrd)r[r[rdr>) prefixLenr[rr>cCrr)rprrrrr}r}r~rvrzRecord_A6._suffixrrrNcCsTt|tr |d}||_tt||_t||_ t d|jd|_t ||_ dS)z @param suffix: An IPv6 address suffix in in RFC 2373 format. @type suffix: L{bytes} or L{str} @param prefix: An IPv6 address prefix for other A6 records. @type prefix: L{bytes} or L{str} r @N) rr{rrrprrrrhr[rrr>)rrrr[r>r}r}r~rzs   zRecord_A6.__init__cCsN|td|j|jr||j|j d|jr%|j|ddSdSr)rrrrr{rr[rr(r}r}r~rs zRecord_A6.encodecCshtdt|dd|_td|jd|_|jr'dd|jt||j|_|jr2|j|dSdS)Nrrrrrrr) rrrrrr{rr[rrer}r}r~rszRecord_A6.decoderrcCsVt|tr)|j|jko(|j|j d|j|j dko(|j|jko(|j|jkStSr)rrGrrr{r[r>rrr}r}r~rs  "  zRecord_A6.__eq__cCs t|j|j|j d|jfSr)rrrr{r[rr}r}r~r r1zRecord_A6.__hash__cCs d|jtt|j|j|jfS)Nz)r[rprrrrr>rr}r}r~r s  zRecord_A6.__str__)rrrNr)rrrrrrrhrPrErQrrrrrrrr rr r}r}r}r~rGSs     rGc@FeZdZdZeZdZdZdZddd Z dd d Z dd d Z ddZ dS)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} r0)priorityweighttargetportr>)rr)rrrdrr>rrNcCs6t||_t||_t||_t||_t||_dS)zb @param target: See L{Record_SRV.target} @type target: L{bytes} or L{str} N)rrrrrhrrr>)rrrrrr>r}r}r~rs    zRecord_SRV.__init__cCs.|td|j|j|j|j|ddSN!HHH)rrrrrrrrr(r}r}r~rszRecord_SRV.encodecCs@tdt|td}|\|_|_|_t|_|j |dSr) rrrrVrrrrhrrrr}r}r~rszRecord_SRV.decodecCt|j|j|j|jfSr)rrrrrrr}r}r~r rzzRecord_SRV.__hash__)rrrrNr) rrrrr0rrhrErPrrrr r}r}r}r~r[s"   r[c@sTeZdZdZeZdZdZdZ       ddd Z dd d Z dd d Z ddZ dS)rTa 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)rrrd)rrrd)rrrd)rrrdr>rrNcCsJt||_t||_t||_t||_t||_t||_t ||_ dS)zs @param replacement: See L{Record_NAPTR.replacement} @type replacement: L{bytes} or L{str} N) rrrrfrrrrhrrr>)rrrrrrrr>r}r}r~r9s      zRecord_NAPTR.__init__cCsT|td|j|j|j|d|j|d|j|d|j |ddSr&) rrrrrrrrrrr(r}r}r~rOs zRecord_NAPTR.encodecCsxtdt|td}|\|_|_t|_t|_t|_ t |_ |j ||j ||j ||j |dSr&) rrrrVrrrfrrrrhrrrr}r}r~rWs    zRecord_NAPTR.decodecCrr)rrrrrrrrr}r}r~r cszRecord_NAPTR.__hash__)rrrrrrNr) rrrrr(rrErhrPrrrr r}r}r}r~rTs",    rTc@r)rIa 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)subtypehostnamer>)r)rrrdr>rrNcCs"t||_t||_t||_dS)zj @param hostname: See L{Record_AFSDB.hostname} @type hostname: L{bytes} or L{str} N)rrrhrrr>)rrrr>r}r}r~rs  zRecord_AFSDB.__init__cC&|td|j|j||dSNr)rrrrrrr(r}r}r~rzRecord_AFSDB.encodecCs0tdt|td}|\|_|j|dSr)rrrrVrrrrr}r}r~rzRecord_AFSDB.decodecCt|j|jfSr)rrrrr}r}r~r ruzRecord_AFSDB.__hash__rrNr) rrrrrrrhrErPrrrr r}r}r}r~rIps   rIc@sFeZdZdZeZdZdZdZdddZ dd d Z dd d Z d dZ dS)rXa 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-)mboxtxtr>))rrrd)rrrdr>rNcCs"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)rhrrrr>)rrrr>r}r}r~rs  zRecord_RP.__init__cC |j|||j||dSr)rrrr(r}r}r~rzRecord_RP.encodecCs,t|_t|_|j||j|dSr)rhrrrrer}r}r~rs zRecord_RP.decodecCrr)rrrrr}r}r~r ruzRecord_RP.__hash__rrNr) rrrrr-rrhrErPrrrr r}r}r}r~rXs   rXc@sfeZdZdZeZdZdefdefdfZdZ dd d Z dd d Z dd dZ de defddZddZdS)rLa 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. rcpuosr>)rrr>rNcCs|||_|_t||_dSr)rrrr>)rrrr>r}r}r~rszRecord_HINFO.__init__cCs@|tdt|j|j|tdt|j|jdSr)rrrrrrr(r}r}r~rs"zRecord_HINFO.encodecCsHtdt|dd}t|||_tdt|dd}t|||_dS)Nrrr)rrrrr)rrrrrr}r}r~rs zRecord_HINFO.decoderrcCsBt|tr|j|jko|j|jko|j|jkStSr)rrLrrrr>rrr}r}r~rs  zRecord_HINFO.__eq__cCst|j|jfSr)rrrrrr}r}r~r rzzRecord_HINFO.__hash__rr)rrrrrrrhrrPrErrrrrrr r}r}r}r~rLs    rLc@sNeZdZdZeZdZdZdZdZ dZ dddZ dd d Z dd d Z d dZdS)rQa 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%)rmailbxemailbxr>))rresponsibilityrd)rerrorsrdr>rcCs$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)rhrrrr>)rrrr>r}r}r~r+szRecord_MINFO.__init__cCrr)rrrr(r}r}r~r6rzRecord_MINFO.encodecCs.tt|_|_|j||j|dSr)rhrrrrer}r}r~r:s zRecord_MINFO.decodecCrr)rrrrr}r}r~r ?ruzRecord_MINFO.__hash__rr)rrrrr%rrrrhrErPrrrr r}r}r}r~rQs   rQc@r)rSa 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')rrr>)rrcr>rrNcKs*t||_t|d||_t||_dS)z\ @param name: See L{Record_MX.name}. @type name: L{bytes} or L{str} exchangeN)rrrhrrrr>)rrrr>kwargsr}r}r~r[s zRecord_MX.__init__cCrr)rrrrrrr(r}r}r~rdrzRecord_MX.encodecCs0tdt|dd|_t|_|j|dS)Nrrr)rrrrrhrrrer}r}r~rhrzRecord_MX.decodecCrr)rrrrr}r}r~r mruzRecord_MX.__hash__rr) rrrrr'rrhrErPrrrr r}r}r}r~rSCs   rSc@s^eZdZdZdZdZdZeZdZ dZ dZ dZ dZ dZdd d ZdddZdddZddZd 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 } r2 algorithmfingerprintType fingerprintr>)rrrrrrrrrcCs||_||_||_||_dSrr)rrrrr>r}r}r~rs zRecord_SSHFP.__init__NcCs(|td|j|j||jdS)N!BB)rrrrrrr(r}r}r~rszRecord_SSHFP.encodecCs2tdt|d}|\|_|_t||d|_dS)Nrr)rrrrrrrr}r}r~rs zRecord_SSHFP.decodecCrr)rrrrrr}r}r~r rzRecord_SSHFP.__hash__)rrrrr)rrrrrhrErPr2r ALGORITHM_RSA ALGORITHM_DSSALGORITHM_ECDSAALGORITHM_Ed25519FINGERPRINT_TYPE_SHA1FINGERPRINT_TYPE_SHA256rrrr r}r}r}r~r\qs     r\c@sLeZdZdZeZdZdefdfZdZ ddZ dd d Z dd d Z d dZ 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. r1rKr>rKr>cOs t||_t|dd|_dS)Nr>)rrKrrr>)rrKkwr}r}r~rs zRecord_TXT.__init__NcCs*|jD]}|tdt||qdSr)rKrrrr)rrrdr}r}r~rs zRecord_TXT.encodecCstd}g|_||kr'tdt|dd}|jt||||d7}||ks ||kr8td||j|fdSdS)Nrrrz1Decoded %d bytes in %s record, but rdlength is %d)rKrrrrrmsgrh)rrrsoFarLr}r}r~rs  zRecord_TXT.decodecCstt|jSr)rtuplerKrr}r}r~r szRecord_TXT.__hash__r)rrrrr1rrhrrPrErrrr r}r}r}r~r^s     r^c@sNeZdZdZdZdZdZdefdfZddd Z dd d Z dd d Z ddZ 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 NUNKNOWNrrKr>rcCrr)rKrr>)rrKr>r}r}r~rrzUnknownRecord.__init__cCs||jdS)zc Write the raw bytes corresponding to this record's payload to the stream. N)rrKr(r}r}r~rzUnknownRecord.encodecCs |durtdt|||_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) ExceptionrrKrer}r}r~rszUnknownRecord.decodecCrr)rrKr>rr}r}r~r  ruzUnknownRecord.__hash__rfr) rrrrrrhrErrPrrrr r}r}r}r~r`s      r`c@rg)rZao 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)rrrrr/rrhr}r}r}r~rZ s rZc@sZeZdZdZdZdZgdZeZddddde ddfd d Z dd d Z dd dZ ddZ 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. r3)r timeSignedfudgeMAC originalIDerror otherDatar>)rrrrrNrrrc CsH|durdnt||_||_t||_||_||_||_||_||_ dSr) rhrrrrrrrrr>) rrrrrrrrr>r}r}r~rH s  zRecord_TSIG.__init__c Cs|j|||td|jdd|td|jt|j||j|td|j |j t|j ||j dS)Nz!Qrr'r) rrrrrrrrrrrrr(r}r}r~ra s zRecord_TSIG.encodecCsvt}||||_tddt|d}|\|_|_}t|||_tdt|d}|\|_ |_ }t|||_ dS)Nz!QHHs rr) rhrrrrrrrrrrr)rrrrfields macLength otherLengthr}r}r~rk s  zRecord_TSIG.decodecCrr)rrrrrrr}r}r~r v rzzRecord_TSIG.__hash__r)rrrrrhrErPr3rrorrrr 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)idanswerNr})rqueries)responseConstructormessagerresponser}r}r~_responseFromMessagez srcCs^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 parametersrrGr)obj alwaysShow fieldNamesdisplayableArgsrr defaultValue fieldValuer}r}r~_getDisplayableArguments s   rc Cs|durg}|dur g}|durg}|durg}g}|D]}||vs*t||ddkr/||qt|||}d|jjg|}|rK|dd||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}. @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)rrrrrWrrrrrrrrrr) rrrrrrrWrrrrrr}r}r~r+ sJ zMessage.__init__rcCt|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. )rrWrrrrr)rrrrrrrrrrrrrrrr}r}r~r0 s  zMessage.__repr__cCs|jt|||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)rrrir%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|jt|jt|jt|j||dS)Nrr=rrrr)rrrrrrr@rrrrrrrWrrrrrrrr headerFmtr) rrrbody_tmpqbodysizebyte3byte4r}r}r~r s\            zMessage.encodec Cstd|_t||j}t|j|}|\|_}}}}} } |d?d@|_|d?d@|_|d?d@|_ |d?d@|_ |d@|_ |d?d@|_ |d?d@|_ |d?d@|_|d@|_t|jd } t| Qg|_t|D]$} t} z| |WntyYWddSw|j| qg|j|f|j| f|j| ff}|D] \}}||||qWddS1swYdS) Nrr rrr=rrrr)rrrrrrrrrrWrrrrrrrrrrrangerirrrrrr parseRecords)rrrheaderr]rrnqueriesnansnnsnadd decodeContextiritemsrr3r}r}r~r sB        "zMessage.decodec Cst|D]F}t|jd}z||Wn tyYdSw||j}|s(q||jd|_z |j||j Wn tyDYdSw| |qdS)Nr^)r>) rrjrWrrlookupRecordTyperr>r?rCr)rrnumrrrr.r}r}r~r s$      zMessage.parseRecordsRecord_cCs|j|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]} ) _recordTypesrr`)rrr}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} )rrr@)rrr}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)rrrr}r}r~fromStr7 szMessage.fromStrr)"rrrrrrr#rErrrVrrrrnsrorrr0r:r9r rrrr"globalsr startswithrrr#r$r}r}r}r~rg sB  /  [ ,'   rgc@sveZdZdZdZeZddeddddddddddddddfddZd e fd d Z d d Z ddZ e ddZddZdS) _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}. rrrrWrrrr ednsVersionr8rrrrrrrrFrNcCs||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ |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))rrrrrWrrrrr*r8rrrrrrrr}r}r~r s2m z_EDNSMessage.__init__rcCr)N)rrWrrrrrr8)rrrrr*rr r r rr}r}r~r0 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=) rrrrWrrrrrrNr)r7r8r5r6)_messageFactoryrrrrWrrrrrrrrrrr*r2r8rr)rmrAr}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. )r-r#rr}r}r~r#G s z_EDNSMessage.toStrcCsg}g}|jD]}|jtkr|t|q||q|did|jd|jd|jd|j d|j d|j d|j d|j d |jd |jd d d dd|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} rrrrWrrrrrrr*Nr8Frrrrrrrr})rrr+rr2rDrrrrWrrrrrrrrrrr7r*r8r5rr6)r$rr optRecordsr] newMessageoptr}r}r~ _fromMessageO 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)r+r$r1rErFrG)rr{r, ednsMessagerJr}r}r~r$ s    z_EDNSMessage.fromStr)rrrrrErgr+rrrrr0r-r#rRr1r$r}r}r}r~r(B s:'  *  .writeMessage)rNrTr r rAr;rMrH)rrmrrDrrEr}r]r~query5 s      zDNSDatagramProtocol.query)rN) rrrrrMrOrPrErTr[r\r^r}r}r}r~rl s  rlc@sBeZdZdZdZdZddZddZdd Zd d Z dd dZ dS)rnz DNS protocol over TCP. NrcCs(|}|jtdt||dS)rQrN)r#rNrrrr)rrrr}r}r~rE[ s zDNSProtocol.writeMessagecCsi|_|j|dS)zV Connection is made: reset internal state, and notify the controller. N)r9r4connectionMaderr}r}r~r_d szDNSProtocol.connectionMadecCs|j|dS)zZ Notify the controller that this protocol is no longer connected. N)r4connectionLost)rreasonr}r}r~r`k rzDNSProtocol.connectionLostcCs&|j|7_|jr|jdur,t|jdkr,td|jddd|_|jdd|_t|j|jkr|jd|j}t}||z |j|j\}}Wnt y^|j ||Ynw|j|j=| z| |Wn ty|tYnw|j|jd|_d|_ndS|js dSdS)Nrrr)bufferrrrrrgr$r9rrIr4rXrVrWr@rrU)rrKmyChunkr,rrZr}r}r~ dataReceivedr s2     zDNSProtocol.dataReceivedrcCs|}|||||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} )r;rHrE)rrrDrr}r}r~r^ s zDNSProtocol.query)r) rrrrrrbrEr_r`rdr^r}r}r}r~rnS s rn)NNNN)r contextvarsrr5rpr contextlibrior itertoolsrtypingrrrzope.interfacerr r r7r r twisted.internet.errorr twisted.pythonrrrrtputiltwisted.python.compatrrr__all__rrrrrrurrr)r"r#rr.r!r$r&r*r4r,rr%r'r1r-rrr0r(rrr+r2r/rr3rbr<r;r rr:rerrdr9r7r6r8r5rarcrrrprsrqrtror=rAr>r?r@rBrCrDrErtwisted.names.errorrvrxryrrrrrrrwr ContextVarrr#rrrrfrhri FancyStrMixin FancyEqMixinr2rLrjrkrUrNrOrJrMrPrRrWrKrFrYrVr_rHrGr[rTrIrXrLrQrSr\r^r`rZr]rrrrgr(rmDatagramProtocolrlProtocolrnr}r}r}r~s    i           !( 4'1<;<z&        1s<.]Cz130;-?+,^ 4c\Oh