U mftA @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__rr:/opt/hc_python/lib/python3.8/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 seZdZdZddddgZejjdfejj ejj ejj e dfdd Z fd d Z e d d ddZd1ejjee d dfdd ZfddZfddZfddZddZddZddZfdd Zd!d"Zd2eejjeejjeeejj eeee fed%d&d'Z!d3ejje eejj"eejjeejj ee d(d)d*Z#ejj ejj ejj ed+d,d-Z$e%ejjd.d/d0Z&Z'S)4RdatasetzA DNS rdataset.rdclassrdtypecoversttlr)rrrrcs&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|dk r.|||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 sz'Rdataset._rdata_repr..)joinrrr4r _rdata_reprszRdataset._rdata_reprcCs^|jdkrd}ndtj|jd}dtj|jdtj|j|d|dS) Nr()z)rr r&to_text rdataclassrrr8)rZctextrrr__repr__s&   zRdataset.__repr__cCs|Sr)r>r7rrr__str__szRdataset.__str__csBt|tsdS|j|jks2|j|jks2|j|jkr6dSt|S)NF) isinstancerrrrr__eq__r+rrrrCs    zRdataset.__eq__cCs || Sr)rCr+rrr__ne__szRdataset.__ne__TF)nameorigin relativizeoverride_rdclass want_commentskwrc Ks|dk r"|||}t|}d}nd}d}t} |dk r@|} 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<r9rz {}{}{} {} z ;z%s%s%d %s %s %s%s )rFrG)Zchoose_relativityr2ioStringIOrr"writeformatr r?r>r&rZ rdcommentrgetvalue) rrErFrGrHrIrJZntextpadr0rr%extrarrrr>sJ"        zRdataset.to_text)rEfilecompressrFrH want_shufflerc Cs|dk r|}d}n|j}t|dkrP|||||td|j|dddS|rht|}t |n|}|D]T} |||||td|j||j t j |d| |||W5QRXqpt|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_wirerNstructpackrlistrandomshufflerr rendererZprefixed_length) rrErSrTrFrHrUrlr%rrrrXs$!  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_orderiterr7rrrprocessing_order^s zRdataset.processing_order)N)NNTNF)NNNT)(r r r r __slots__r r&r'r? RdataClass RdataTypeintrrr$rdataRdatarr)r*r-r.r8r@rArCrDrENameboolrr2rr>Z CompressTyperXr`rrb __classcell__rrrrr0sv  '         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)rrmrrrrsszImmutableRdataset.__init__cCs tddSNrn TypeErrorr#rrrr${szImmutableRdataset.update_ttlNcCs tddSrprq)rr%rrrrr)~szImmutableRdataset.addcCs tddSrprqr+rrrr*szImmutableRdataset.union_updatecCs tddSrprqr+rrrr-sz%ImmutableRdataset.intersection_updatecCs tddSrprqr+rrrr.szImmutableRdataset.updatecCs tddSrprq)rirrr __delitem__szImmutableRdataset.__delitem__cCs tddSrprqr+rrr__ior__szImmutableRdataset.__ior__cCs tddSrprqr+rrr__iand__szImmutableRdataset.__iand__cCs tddSrprqr+rrr__iadd__szImmutableRdataset.__iadd__cCs tddSrprqr+rrr__isub__szImmutableRdataset.__isub__cCs tddSrprqr7rrrr(szImmutableRdataset.clearcsttSrrlrcopyr7rrr__copy__szImmutableRdataset.__copy__csttSrryr7rrrrzszImmutableRdataset.copycstt|Sr)rlrunionr+rrrr|szImmutableRdataset.unioncstt|Sr)rlr intersectionr+rrrr}szImmutableRdataset.intersectioncstt|Sr)rlr differencer+rrrr~szImmutableRdataset.differencecstt|Sr)rlrsymmetric_differencer+rrrrsz&ImmutableRdataset.symmetric_difference)N)r r r rrZ _clone_classrr$r)r*r-r.rtrurvrwrxr(r{rzr|r}r~rrkrrrrrlms(      rlT) rrr text_rdatas idna_codecrFrG 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?rdr!r&rerr$rg from_textrrr)) rrrrrrFrGrrtr%rrrfrom_text_lists    r)rrrrrcGst|||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)rrrrrrrrs r)rrdatasrcCs\t|dkrtdd}|D].}|dkr@t|j|j}||||q|dk sXt|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)AssertionError)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 rgrh)rrrrr from_rdatasr)NNTN)0rrLr\rYtypingrrrrrrrZ dns.exceptionr Z dns.immutableZdns.nameZ dns.rdataZdns.rdataclassZ dns.rdatatypeZ dns.rendererZdns.setZdns.ttlsetSetZ SimpleSet exceptionZ DNSExceptionr rrrnrlr?rdr2r&rerfrEZ IDNACodecrirjrrrgrhrrrrrrsX$?J    )