grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a àMÒesã @s~UdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZdZdZGdd„dejjƒZed fd d „Zed fd d „Z ed fdd„Z!dZ"dd„Z#dd„Z$ej%j&Z'ej%j%Gdd„dƒƒZ(ej%j%Gdd„de(ƒƒZ)iZ*e e ej+j,ej-j.fe fe/d<dZ0dd„Z1d,eej+j,e2feej-j.e2feej3j4e2fe ej5j6e7e ej5j6e ej5j8e(dœdd„Z9d-eej+j,e2feej-j.e2fej:j;e ej5j6e(d œd!d"„Ze>e ej5j6e(d#œd$d%„Z?Gd&d'„d'ejjƒZ@d(ej+jAfe e>e2e7ej+j,dd)œd*d+„ZBdS)/z DNS rdata.éN)Ú import_module)ÚAnyÚDictÚOptionalÚTupleÚUnioné Tc@seZdZdZdS)ÚNoRelativeRdataOrderingz°An attempt was made to do an ordered comparison of one or more rdata with relative names. The only reliable way of sorting rdata is to use non-relativized rdata. N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú-/usr/lib/python3.9/site-packages/dns/rdata.pyr 3sr ó cs6ˆs ˆ ¡S| ‡‡fdd„tdtˆƒˆƒDƒ¡ ¡S)zXBreak a binary string into chunks of chunksize characters separated by a space. csg|]}ˆ||ˆ…‘qSrr)Ú.0Úi©Ú chunksizeÚdatarrÚ Cóz_wordbreak..r)ÚdecodeÚjoinÚrangeÚlen)rrÚ separatorrrrÚ _wordbreak;s ÿrcKstt |¡||ƒS)zConvert a binary string into its hex encoding, broken up into chunks of chunksize characters separated by a separator. )rÚbinasciiZhexlify©rrrÚkwrrrÚ_hexifyJsr!cKstt |¡||ƒS)z‚Convert a binary string into its base64 encoding, broken up into chunks of chunksize characters separated by a separator. )rÚbase64Z b64encoderrrrÚ _base64ifyRsr#s"\cCszt|tƒr| ¡}t|tƒs$t|ƒ}d}|D]H}|tvrJ|dt|ƒ7}q,|dkrh|dkrh|t|ƒ7}q,|d|7}q,|S)z7Escape the characters in a quoted string which need it.Úú\réz\%03d)Ú isinstanceÚstrÚencodeÚ bytearrayÚ __escapedÚchr)ZqstringÚtextÚcrrrÚ _escapify_s  r/cCsFtt|ƒdddƒD]$}||dkr|d|d…Sq|dd…S)z‹Determine the index of greatest byte that isn't all zeros, and return the bitmap that contains all the bytes less than that index. ééÿÿÿÿr)rr)ZwhatrrrrÚ_truncate_bitmaprs r2c @s eZdZdZgd¢Zdd„Zdd„Zdd„Zd d „Ze j j d œd d „Z e d œdd„Zd]ee jjeeeefedœdd„Zd^eeee jjee jjeedœdd„Zd_eeee jjee jjeedœdd„Zd`ee jjddœdd„Zdaee jjedœdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Z d)d*„Z!d+d,„Z"d-d.„Z#d/d0„Z$d1d2„Z%d3d4„Z&e'dbe j(j)e j j e j*j+ee jjeee jjdd5œd6d7„ƒZ,e'dce j(j)e j j e j-j.ee jjdd8œd9d:„ƒZ/edd;œdd?„ƒZ1e'd@dA„ƒZ2e'ddeeee eedBœdCdD„ƒZ3e'dEdF„ƒZ4e'dGdH„ƒZ5e'dIdJ„ƒZ6e'dKdL„ƒZ7e'dMdN„ƒZ8e'dedOdP„ƒZ9e'dQdR„ƒZ:e'dSdT„ƒZ;e'dUdV„ƒZe'd[d\„ƒZ?dS)fÚRdataz#Base class for all DNS rdata types.)ÚrdclassÚrdtypeÚ rdcommentcCs"| |¡|_| |¡|_d|_dS)z™Initialize an rdata. *rdclass*, an ``int`` is the rdataclass of the Rdata. *rdtype*, an ``int`` is the rdatatype of the Rdata. N)Ú_as_rdataclassr4Ú _as_rdatatyper5r6)Úselfr4r5rrrÚ__init__‡s  zRdata.__init__cCstj dd„|jjDƒ¡S)Ncss|]}t|dgƒVqdS)Ú __slots__N)Úgetattr)rÚclsrrrÚ ”sz'Rdata._get_all_slots..)Ú itertoolsÚchainÚ from_iterableÚ __class__Ú__mro__©r9rrrÚ_get_all_slots“s ÿzRdata._get_all_slotscCs$i}| ¡D]}t||ƒ||<q |S©N)rEr<)r9ÚstateÚslotrrrÚ __getstate__˜s  zRdata.__getstate__cCs<| ¡D]\}}t |||¡qt|dƒs8t |dd¡dS)Nr6)ÚitemsÚobjectÚ __setattr__Úhasattr)r9rGrHÚvalrrrÚ __setstate__¦s zRdata.__setstate__)ÚreturncCstjjS)a¤Return the type a Rdata covers. DNS SIG/RRSIG rdatas apply to a specific type; this type is returned by the covers() function. If the rdata type is not SIG or RRSIG, dns.rdatatype.NONE is returned. This is useful when creating rdatasets, allowing the rdataset to contain only RRSIGs of a particular type, e.g. RRSIG(NS). Returns a ``dns.rdatatype.RdataType``. )ÚdnsÚ rdatatypeÚNONErDrrrÚcovers®s z Rdata.coverscCs| ¡d>|jBS)zÒReturn a 32-bit type value, the least significant 16 bits of which are the ordinary DNS type, and the upper 16 bits of which are the "covered" type, if any. Returns an ``int``. é)rTr5rDrrrÚextended_rdatatype¼szRdata.extended_rdatatypeNT©ÚoriginÚ relativizer rPcKst‚dS)zEConvert an rdata to text format. Returns a ``str``. N©ÚNotImplementedError©r9rXrYr rrrÚto_textÆs z Rdata.to_textF)ÚfileÚcompressrXÚ canonicalizerPcCst‚dSrFrZ©r9r^r_rXr`rrrÚ_to_wireÓszRdata._to_wirecCs8|r| ||||¡St ¡}| ||||¡| ¡SdS)zSConvert an rdata to wire format. Returns a ``bytes`` or ``None``. N)rbÚioÚBytesIOÚgetvalue)r9r^r_rXr`ÚfrrrÚto_wireÜs z Rdata.to_wirezdns.rdata.GenericRdata)rXrPcCstj |j|j|j|d�¡S)zrCreates a dns.rdata.GenericRdata equivalent of this rdata. Returns a ``dns.rdata.GenericRdata``. )rX)rQÚrdataÚ GenericRdatar4r5rg©r9rXrrrÚ to_genericïsÿzRdata.to_genericcCs|j|dd�S)z“Convert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form. Returns a ``bytes``. T)rXr`)rgrjrrrÚ to_digestableúszRdata.to_digestablecCsf| ¡}|tjjkrd}ndtj |¡d}dtj |j¡dtj |j¡|dt|ƒdS)Nr$ú(ú)z) rTrQrRrSr]Ú rdataclassr4r5r()r9rTZctextrrrÚ__repr__s(  ÿþ ýüûúùÿzRdata.__repr__cCs| ¡SrF)r]rDrrrÚ__str__sz Rdata.__str__cCsÂz| ¡}d}Wn,tjjy<tr4| tjj¡}d}Yn0z| ¡}d}Wn,tjjyztrr| tjj¡}d}Yn0tr–||kr¢|r�dSdSn |sž|r¢t‚||kr®dS||krºdSdSdS)aCompare an rdata with another rdata of the same rdtype and rdclass. For rdata with only absolute names: Return < 0 if self < other in the DNSSEC ordering, 0 if self == other, and > 0 if self > other. For rdata with at least one relative names: The rdata sorts before any rdata with only absolute names. When compared with another relative rdata, all names are made absolute as if they were relative to the root, as the proper origin is not available. While this creates a stable ordering, it is NOT guaranteed to be the DNSSEC ordering. In the future, all ordering comparisons for rdata with relative names will be disallowed. FTr1r0rN)rlrQÚnameÚNeedAbsoluteNameOrOriginÚ_allow_relative_comparisonsÚrootr )r9ÚotherÚourÚ our_relativeÚtheirÚtheir_relativerrrÚ_cmps4  z Rdata._cmpcCs²t|tƒsdS|j|jks&|j|jkr*dSd}d}z | ¡}Wn(tjjyf| tjj¡}d}Yn0z | ¡}Wn(tjjyœ| tjj¡}d}Yn0||krªdS||kS)NFT) r'r3r4r5rlrQrtrurw)r9rxrzr|ryr{rrrÚ__eq__Fs&     z Rdata.__eq__cCs6t|tƒsdS|j|jks&|j|jkr*dS| |¡ S)NT)r'r3r4r5r~©r9rxrrrÚ__ne__[s  z Rdata.__ne__cCs4t|tƒr"|j|jks"|j|jkr&tS| |¡dkS©Nr©r'r3r4r5ÚNotImplementedr}rrrrÚ__lt__bsÿ þ ýz Rdata.__lt__cCs4t|tƒr"|j|jks"|j|jkr&tS| |¡dkSr�r‚rrrrÚ__le__ksÿ þ ýz Rdata.__le__cCs4t|tƒr"|j|jks"|j|jkr&tS| |¡dkSr�r‚rrrrÚ__ge__tsÿ þ ýz Rdata.__ge__cCs4t|tƒr"|j|jks"|j|jkr&tS| |¡dkSr�r‚rrrrÚ__gt__}sÿ þ ýz Rdata.__gt__cCst| tjj¡ƒSrF)ÚhashrlrQrtrwrDrrrÚ__hash__†szRdata.__hash__)r4r5ÚtokrXrYÚ relativize_torPcCst‚dSrFrZ)r=r4r5rŠrXrYr‹rrrÚ from_text‰s zRdata.from_text©r4r5ÚparserrXrPcCst‚dSrFrZ©r=r4r5rŽrXrrrÚfrom_wire_parser•szRdata.from_wire_parser)ÚkwargsrPc s t ˆj¡j}ˆD]F}|dkr q||vrÂrz Rdata.replace..N) ÚinspectZ signaturer:Ú parametersÚAttributeErrorÚformatrBr r“r6rKrL)r9r‘r—r”ÚargsZrdr6rr•rÚreplaceŸs, ÿÿÿÿ z Rdata.replacecCstjj |¡SrF)rQrqÚ RdataClassÚmake©r=Úvaluerrrr7ÐszRdata._as_rdataclasscCstjj |¡SrF)rQrRÚ RdataTyper�ržrrrr8ÔszRdata._as_rdatatype)rŸr)Ú max_lengthÚempty_okrPcCs||rt|tƒr| ¡}n,t|tƒr,t|ƒ}nt|tƒr<|}ntdƒ‚|dur`t|ƒ|kr`tdƒ‚|sxt|ƒdkrxtdƒ‚|S)Nz not bytesztoo longrzempty bytes not allowed)r'r(r)r*ÚbytesÚ ValueErrorr)r=rŸr)r¡r¢ZbvaluerrrÚ _as_bytesØs    zRdata._as_bytescCs0t|tƒrtj |¡St|tjjƒs,tdƒ‚|S)Nz not a name)r'r(rQrtrŒÚNamer¤ržrrrÚ_as_nameîs   zRdata._as_namecCs.t|tƒstdƒ‚|dks"|dkr*tdƒ‚|S)Núnot an integerréÿz not a uint8©r'Úintr¤ržrrrÚ _as_uint8ùs  zRdata._as_uint8cCs.t|tƒstdƒ‚|dks"|dkr*tdƒ‚|S)Nr¨riÿÿz not a uint16rªržrrrÚ _as_uint16s  zRdata._as_uint16cCs.t|tƒstdƒ‚|dks"|dkr*tdƒ‚|S)Nr¨rlÿÿz not a uint32rªržrrrÚ _as_uint32 s  zRdata._as_uint32cCs.t|tƒstdƒ‚|dks"|dkr*tdƒ‚|S)Nr¨rlÿÿÿz not a uint48rªržrrrÚ _as_uint48s  zRdata._as_uint48cCsFt|tƒstdƒ‚|dur*||kr*tdƒ‚|durB||krBtdƒ‚|S)Nr¨zvalue too smallzvalue too largerª)r=rŸZlowZhighrrrÚ_as_ints z Rdata._as_intcCs8t|tƒrtj |¡St|tƒr,tj |¡Stdƒ‚dS)Nznot an IPv4 address)r'r(rQZipv4r`r£Ú inet_ntoar¤ržrrrÚ_as_ipv4_address#s     zRdata._as_ipv4_addresscCs8t|tƒrtj |¡St|tƒr,tj |¡Stdƒ‚dS)Nznot an IPv6 address)r'r(rQZipv6r`r£r±r¤ržrrrÚ_as_ipv6_address,s     zRdata._as_ipv6_addresscCst|tƒr|Stdƒ‚dS)Nz not a boolean)r'Úboolr¤ržrrrÚ_as_bool5s zRdata._as_boolcCs>t|tƒr| |dtjj¡St|tƒr2tj |¡Stdƒ‚dS)Nrz not a TTL) r'r«r°rQZttlZMAX_TTLr(rŒr¤ržrrrÚ_as_ttl<s    z Rdata._as_ttlcs:z ˆ|ƒfWSty4t‡fdd„|DƒƒYS0dS)Nc3s|]}ˆ|ƒVqdSrFr)rÚv©Úas_valuerrr>Nrz"Rdata._as_tuple..)Ú ExceptionÚtuple)r=rŸr¹rr¸rÚ _as_tupleEs  zRdata._as_tuplecCst|ƒ}t |¡|SrF)ÚlistÚrandomZshuffle)r=ÚiterablerJrrrÚ_processing_orderRs zRdata._processing_order)NT)NNF)NNNF)N)N)NTN)N)FNT)NN)@r r r r r;r:rErIrOrQrRr rTr«rVrrtr¦r´rr(rr]Z CompressTyper£rbrgrkrlrrrsr}r~r€r„r…r†r‡r‰Ú classmethodrqrœÚ tokenizerÚ TokenizerrŒÚwireÚParserr�r›r7r8r¥r§r¬r­r®r¯r°r²r³rµr¶r¼rÀrrrrr3�sæ  ý  û û  ú û  ú ÿ þ  /    ù  ø û ú 1  ûú           r3csreZdZdZdgZ‡fdd„Zdeejj e e e e fe dœdd „Zedd d „ƒZdd d„Zeddd„ƒZ‡ZS)riz�Generic Rdata Class This class is used for rdata types for which we have no better implementation. It implements the DNS "unknown RRs" scheme. rcstƒ ||¡||_dSrF)Úsuperr:r)r9r4r5r©rBrrr:cszGenericRdata.__init__NTrWcKs dt|jƒt|jfi|¤ŽS)Nz\# %d )rrr!r\rrrr]gszGenericRdata.to_textc Csj| ¡}| ¡r|jdkr&tj d¡‚| ¡}| d¡ ¡} t   | ¡} t | ƒ|kr^tj d¡‚|||| ƒS)Nú\#z$generic rdata does not start with \#Tz'generic rdata hex data has wrong length) r“Ú is_identifierrŸrQÚ exceptionÚ SyntaxErrorZget_intZ!concatenate_remaining_identifiersr)rZ unhexlifyr) r=r4r5rŠrXrYr‹ÚtokenÚlengthÚhexrrrrrŒos    zGenericRdata.from_textFcCs| |j¡dSrF)Úwriterrarrrrb}szGenericRdata._to_wirecCs|||| ¡ƒSrF)Z get_remainingr�rrrr�€szGenericRdata.from_wire_parser)NT)NTN)NNF)N)r r r r r;r:rrQrtr¦r´rr(rr]rÁrŒrbr�Ú __classcell__rrrÇrriYs" ý  û ÿ riÚ_rdata_classesz dns.rdtypesc Csøt ||f¡}|sàt tjj|f¡}|sàtj |¡}tj |¡}| dd¡}z.td  t ||g¡ƒ}t ||ƒ}|t||f<Wndt yÞz>td  t d|g¡ƒ}t ||ƒ}|ttjj|f<|t||f<Wnt yØYn0Yn0|sôt }|t||f<|S)Nú-Ú_Ú.ÚANY)rÑr“rQrRrÕrqr]r›rrÚ_module_prefixr<Ú ImportErrorri)r4r5r=Z rdclass_textÚ rdtype_textÚmodrrrÚget_rdata_class‹s2   ÿ      rÚ)r4r5rŠrXrYr‹Ú idna_codecrPc Cs6t|tƒrtjj||d�}tjj |¡}tjj  |¡}t ||ƒ}tj   tj j ¡�Ðd}|tkrÎ| ¡} | | ¡|  ¡rÎ| jdkrÎt ||||||¡} t||| jdt| jƒ|ƒ}| ¡} | | jkrÎtj   d¡‚|durê| ||||||¡}| ¡} | jdu�rt |d| j¡|WdƒS1�s(0YdS)a3Build an rdata object from text format. This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_text() class method is called with the parameters to this function. If *tok* is a ``str``, then a tokenizer is created and the string is used as its input. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *tok*, a ``dns.tokenizer.Tokenizer`` or a ``str``. *origin*, a ``dns.name.Name`` (or ``None``), the origin to use for relative names. *relativize*, a ``bool``. If true, name will be relativized. *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use when relativizing names. If not set, the *origin* value will be used. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder to use if a tokenizer needs to be created. If ``None``, the default IDNA 2003 encoder/decoder is used. If a tokenizer is not created, then the codec associated with the tokenizer is the one that is used. Returns an instance of the chosen Rdata subclass. )rÛNrÈrz9compressed data in generic syntax form of known rdatatyper6)r'r(rQrÂrÃrqrœr�rRr rÚrÊÚExceptionWrapperrËrir“ZungetrÉrŸrŒÚ from_wirerrrgZget_eol_as_tokenZcommentrKrL) r4r5rŠrXrYr‹rÛr=rhrÌZgrdataZrwirerrrrŒ§s<-    ÿÿ ÿ ÿ rŒr�cCsjtjj |¡}tjj |¡}t||ƒ}tj tjj ¡� |  ||||¡WdƒS1s\0YdS)aBuild an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *parser*, a ``dns.wire.Parser``, the parser, which should be restricted to the rdata length. *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N) rQrqrœr�rRr rÚrÊrÜZ FormErrorr�)r4r5rŽrXr=rrrr�s  r�)r4r5rÄÚcurrentÚrdlenrXrPcCsJtj ||¡}| |¡�t||||ƒWdƒS1s<0YdS)a1Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, an ``int``, the rdataclass. *rdtype*, an ``int``, the rdatatype. *wire*, a ``bytes``, the wire-format message. *current*, an ``int``, the offset in wire of the beginning of the rdata. *rdlen*, an ``int``, the length of the wire-format rdata *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N)rQrÄrÅZ restrict_tor�)r4r5rÄrÞrßrXrŽrrrrÝ%s" rÝc@seZdZdZddhZdZdS)ÚRdatatypeExistszDNS rdatatype already exists.r4r5zKThe rdata type with class {rdclass:d} and rdtype {rdtype:d} already exists.N)r r r r Z supp_kwargsZfmtrrrrràLsÿràF)Úimplementationr5rØÚ is_singletonr4rPcCsftjj |¡}t||ƒ}|tks,tj |¡r8t||d�‚t||  dd¡ƒt ||f<tj  |||¡dS)aïDynamically register a module to handle an rdatatype. *implementation*, a module implementing the type in the usual dnspython way. *rdtype*, an ``int``, the rdatatype to register. *rdtype_text*, a ``str``, the textual form of the rdatatype. *is_singleton*, a ``bool``, indicating if the type is a singleton (i.e. RRsets of the type can have only one member.) *rdclass*, the rdataclass of the type, or ``dns.rdataclass.ANY`` if it applies to all classes. r’rÒrÓN) rQrRr r�rÚriZ is_metatyperàr<r›rÑÚ register_type)rár5rØrâr4Z existing_clsrrrrãVs   ÿ rã)NTNN)N)N)Cr r"rr–rcr?r¾Ú importlibrÚtypingrrrrrZ dns.exceptionrQZ dns.immutableZdns.ipv4Zdns.ipv6Zdns.nameZdns.rdataclassZ dns.rdatatypeZ dns.tokenizerZdns.ttlZdns.wireZ _chunksizervrÊZ DNSExceptionr rr!r#r+r/r2Z immutableZconstifyZ _constifyr3rirÑrqrœrRr Ú__annotations__rÖrÚr(rÂrÃrtr¦r´Z IDNACodecrŒrÄrÅr�r£r«rÝràÚINrãrrrrÚs¤   Z,ÿ" ù   ø ^ü û *ú ù 'ûú