a MetA @sdZddlZddlZddlZddlmZmZmZmZm Z m Z m Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ e jjZGddde jjZGddde jjZGdd d e jjZe jjGd d d eZde e j j!e"fe e j#j$e"fe%ee"e e j&j'e e j&j(e)e e j&j(ed ddZ*e e j j!e"fe e j#j$e"fe%eedddZ+e%ee j,j-edddZ.e%eedddZ/dS)zHDNS rdatasets (an rdataset is a set of rdatas of a given type and class)N)Any CollectionDictListOptionalUnioncastc@seZdZdZdS)DifferingCoversz~An attempt was made to add a DNS SIG/RRSIG whose covered type is not the same as that of the other rdatas in the rdataset.N__name__ __module__ __qualname____doc__rr0/usr/lib/python3.9/site-packages/dns/rdataset.pyr 'sr c@seZdZdZdS)IncompatibleTypesz?An attempt was made to add DNS RR data of an incompatible type.Nr rrrrr,src seZdZdZgdZejjdfejj ejj ejj e dfdd Z fddZ e dd d d Zd-ejjee dd fd d ZfddZfddZfddZddZddZddZfddZddZd.eejjeejjeeejj eeee fed!d"d#Z!d/ejje eejj"eejjeejj ee d$d%d&Z#ejj ejj ejj ed'd(d)Z$e%ejjd*d+d,Z&Z'S)0RdatasetzA DNS rdataset.)rdclassrdtypecoversttlrcs&t||_||_||_||_dS)a5Create a new rdataset of the specified class and type. *rdclass*, a ``dns.rdataclass.RdataClass``, the rdataclass. *rdtype*, an ``dns.rdatatype.RdataType``, the rdatatype. *covers*, an ``dns.rdatatype.RdataType``, the covered rdatatype. *ttl*, an ``int``, the TTL. N)super__init__rrrr)selfrrrr __class__rrr5s  zRdataset.__init__cs.t}|j|_|j|_|j|_|j|_|SN)r_clonerrrr)robjrrrrMs  zRdataset._cloneN)rreturncCs4tj|}t|dkr ||_n||jkr0||_dS)aPerform TTL minimization. Set the TTL of the rdataset to be the lesser of the set's current TTL or the specified TTL. If the set contains no rdatas, set the TTL to the specified TTL. *ttl*, an ``int`` or ``str``. rN)dnsrmakelenrrrrr update_ttlUs   zRdataset.update_ttl)rdrrcs|j|jks|j|jkrt|dur.|||jtjjksJ|jtjjkr|}t |dkrt|jtjj krt||_n|j|krt tj |jrt |dkr| t|dS)a!Add the specified rdata to the rdataset. If the optional *ttl* parameter is supplied, then ``self.update_ttl(ttl)`` will be called prior to adding the rdata. *rd*, a ``dns.rdata.Rdata``, the rdata *ttl*, an ``int``, the TTL. Raises ``dns.rdataset.IncompatibleTypes`` if the type and class do not match the type and class of the rdataset. Raises ``dns.rdataset.DifferingCovers`` if the type is a signature type and the covered type does not match that of the rdataset. Nr)rrrr$r rdatatypeZRRSIGZSIGrr"NONEr Z is_singletonclearradd)rr%rrrrrr)ds  z Rdataset.addcs||jt|dSr)r$rr union_updaterotherrrrr*s zRdataset.union_updatecs||jt|dSr)r$rrintersection_updater+rrrr-s zRdataset.intersection_updatecs||jt|dS)zAdd all rdatas in other to self. *other*, a ``dns.rdataset.Rdataset``, the rdataset from which to update. N)r$rrupdater+rrrr.s zRdataset.updatecs$ddddfdd|DS)NcSs t|dkr|dddS|S)Ndz...)r")srrrmaybe_truncates z,Rdataset._rdata_repr..maybe_truncatez[%s]z, c3s|]}dt|VqdS)z<%s>N)str).0Zrrr1rr z'Rdataset._rdata_repr..)joinrrr4r _rdata_reprszRdataset._rdata_reprcCs^|jdkrd}ndtj|jd}dtj|jdtj|j|d|dS) Nr()z)rr r&to_text rdataclassrrr9)rZctextrrr__repr__s&   zRdataset.__repr__cCs|Sr)r?r8rrr__str__szRdataset.__str__csBt|tsdS|j|jks2|j|jks2|j|jkr6dSt|S)NF) isinstancerrrrr__eq__r+rrrrDs    zRdataset.__eq__cCs || Sr)rDr+rrr__ne__szRdataset.__ne__TF)nameorigin relativizeoverride_rdclass want_commentskwrc Ks|dur"|||}t|}d}nd}d}t} |dur@|} n|j} t|dkr|| d||tj | tj |j nf|D]`} d} |r| j rd| j } | d|||jtj | tj |j | j f||d|| fq| dd S) auConvert the rdataset into DNS zone file format. See ``dns.name.Name.choose_relativity`` for more information on how *origin* and *relativize* determine the way names are emitted. Any additional keyword arguments are passed on to the rdata ``to_text()`` method. *name*, a ``dns.name.Name``. If name is not ``None``, emit RRs with *name* as the owner name. *origin*, a ``dns.name.Name`` or ``None``, the origin for relative names. *relativize*, a ``bool``. If ``True``, names will be relativized to *origin*. *override_rdclass*, a ``dns.rdataclass.RdataClass`` or ``None``. If not ``None``, use this class instead of the Rdataset's class. *want_comments*, a ``bool``. If ``True``, emit comments for rdata which have them. The default is ``False``. Nr=r:rz {}{}{} {} z ;z%s%s%d %s %s %s%s )rGrH)Zchoose_relativityr2ioStringIOrr"writeformatr r@r?r&rZ rdcommentrgetvalue) rrFrGrHrIrJrKZntextZpadr0rr%Zextrarrrr?sJ"        zRdataset.to_text)rFfilecompressrGrI want_shufflerc Cs|dur|}d}n|j}t|dkrP|||||td|j|dddS|rht|}t |n|}|D]h} |||||td|j||j t j |d| |||Wdqp1s0Yqpt|SdS)atConvert the rdataset to wire format. *name*, a ``dns.name.Name`` is the owner name to use. *file* is the file where the name is emitted (typically a BytesIO file). *compress*, a ``dict``, is the compression table to use. If ``None`` (the default), names will not be compressed. *origin* is a ``dns.name.Name`` or ``None``. If the name is relative and origin is not ``None``, then *origin* will be appended to it. *override_rdclass*, an ``int``, is used as the class instead of the class of the rdataset. This is useful when rendering rdatasets associated with dynamic updates. *want_shuffle*, a ``bool``. If ``True``, then the order of the Rdatas within the Rdataset will be shuffled before rendering. Returns an ``int``, the number of records emitted. NFrz!HHIHz!HHI)rr"to_wirerOstructpackrlistrandomZshufflerr ZrendererZprefixed_length) rrFrRrSrGrIrTrlr%rrrrWs$!  .zRdataset.to_wire)rrrrcCs&|j|kr"|j|kr"|j|kr"dSdS)zaReturns ``True`` if this rdataset matches the specified class, type, and covers. TF)rrr)rrrrrrrmatchQs zRdataset.match)rcCs&t|dkrgS|dt|SdS)aTReturn rdatas in a valid processing order according to the type's specification. For example, MX records are in preference order from lowest to highest preferences, with items of the same preference shuffled. For types that do not define a processing order, the rdatas are simply shuffled. rN)r"Z_processing_orderiterr8rrrprocessing_order^s zRdataset.processing_order)N)NNTNF)NNNT)(r r r r __slots__r r&r'r@ RdataClass RdataTypeintrrr$rdataRdatarr)r*r-r.r9rArBrDrErFNameboolrr2rr?Z CompressTyperWr]rr_ __classcell__rrrrr0st  '         W    : rcseZdZdZeZedfdd ZddZd(dd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZfddZfddZfd d!Zfd"d#Zfd$d%Zfd&d'ZZS))ImmutableRdatasetzAn immutable DNS rdataset.)rdatasetcs.t|j|j|j|jtj|j |_ dS)z9Create an immutable rdataset from the specified rdataset.N) rrrrrrr immutableritems)rrjrrrrsszImmutableRdataset.__init__cCs tddSNrk TypeErrorr#rrrr${szImmutableRdataset.update_ttlNcCs tddSrmrn)rr%rrrrr)~szImmutableRdataset.addcCs tddSrmrnr+rrrr*szImmutableRdataset.union_updatecCs tddSrmrnr+rrrr-sz%ImmutableRdataset.intersection_updatecCs tddSrmrnr+rrrr.szImmutableRdataset.updatecCs tddSrmrn)rirrr __delitem__szImmutableRdataset.__delitem__cCs tddSrmrnr+rrr__ior__szImmutableRdataset.__ior__cCs tddSrmrnr+rrr__iand__szImmutableRdataset.__iand__cCs tddSrmrnr+rrr__iadd__szImmutableRdataset.__iadd__cCs tddSrmrnr+rrr__isub__szImmutableRdataset.__isub__cCs tddSrmrnr8rrrr(szImmutableRdataset.clearcsttSrrircopyr8rrr__copy__szImmutableRdataset.__copy__csttSrrvr8rrrrwszImmutableRdataset.copycstt|Sr)rirunionr+rrrryszImmutableRdataset.unioncstt|Sr)rir intersectionr+rrrrzszImmutableRdataset.intersectioncstt|Sr)rir differencer+rrrr{szImmutableRdataset.differencecstt|Sr)rirsymmetric_differencer+rrrr|sz&ImmutableRdataset.symmetric_difference)N)r r r rrZ _clone_classrr$r)r*r-r.rqrrrsrtrur(rxrwryrzr{r|rhrrrrrims(      riT) rrr text_rdatas idna_codecrGrH relativize_torc Csdtjj|}tjj|}t||}|||D]*} tj |j |j | ||||} | | q4|S)a|Create an rdataset with the specified class, type, and TTL, and with the specified list of rdatas in text format. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder to use; if ``None``, the default IDNA 2003 encoder/decoder is used. *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. Returns a ``dns.rdataset.Rdataset`` object. ) r r@rar!r&rbrr$rd from_textrrr)) rrrr}r~rGrHrrtr%rrrfrom_text_lists   r)rrrr}rcGst|||ttt|S)zCreate an rdataset with the specified class, type, and TTL, and with the specified rdatas in text format. Returns a ``dns.rdataset.Rdataset`` object. )rrrr2)rrrr}rrrrs r)rrdatasrcCs\t|dkrtdd}|D].}|dur@t|j|j}||||q|dusXJ|S)zCreate an rdataset with the specified TTL, and with the specified list of rdata objects. Returns a ``dns.rdataset.Rdataset`` object. rzrdata list must not be emptyN)r" ValueErrorrrrr$r))rrrr%rrrfrom_rdata_lists    rcGst|tttjj|S)zCreate an rdataset with the specified TTL, and with the specified rdata objects. Returns a ``dns.rdataset.Rdataset`` object. )rrrr rdre)rrrrr from_rdatasr)NNTN)0rrMr[rXtypingrrrrrrrZ dns.exceptionr Z dns.immutableZdns.nameZ dns.rdataZdns.rdataclassZ dns.rdatatypeZ dns.rendererZdns.setZdns.ttlsetSetZ SimpleSet exceptionZ DNSExceptionr rrrkrir@rar2r&rbrcrFZ IDNACodecrfrgrrrdrerrrrrrsX$?J    )