3 ¢báW$-ã@s¼dZddlZddlmZddlZddlZddlZddlZddl Zddl Zddl m Z ej jZGdd„dejjƒZGdd „d ejjƒZGd d „d ej jƒZd d „Zdd„Zdd„Zdd„ZdS)zHDNS rdatasets (an rdataset is a set of rdatas of a given type and class)éN)ÚStringIOé)Ú string_typesc@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__©r r ú/usr/lib/python3.6/rdataset.pyr!src@seZdZdZdS)ÚIncompatibleTypesz?An attempt was made to add DNS RR data of an incompatible type.N)rrrr r r r r r 'sr csºeZdZdZddddgZejjf‡fdd„ Z‡fdd „Z d d „Z d$‡fd d„ Z ‡fdd„Z ‡fdd„Z ‡fdd„Zdd„Zdd„Z‡fdd„Zdd„Zd%dd„Zd&d d!„Zd"d#„Z‡ZS)'ÚRdatasetaÝA DNS rdataset. @ivar rdclass: The class of the rdataset @type rdclass: int @ivar rdtype: The type of the rdataset @type rdtype: int @ivar covers: The covered type. Usually this value is dns.rdatatype.NONE, but if the rdtype is dns.rdatatype.SIG or dns.rdatatype.RRSIG, then the covers value will be the rdata type the SIG/RRSIG covers. The library treats the SIG and RRSIG types as if they were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This makes RRSIGs much easier to work with than if RRSIGs covering different rdata types were aggregated into a single RRSIG rdataset. @type covers: int @ivar ttl: The DNS TTL (Time To Live) value @type ttl: int ÚrdclassÚrdtypeÚcoversÚttlcs*tt|ƒjƒ||_||_||_d|_dS)z©Create a new rdataset of the specified class and type. @see: the description of the class instance variables for the meaning of I{rdclass} and I{rdtype}rN)Úsuperr Ú__init__rrrr)Úselfrrr)Ú __class__r r rCs zRdataset.__init__cs2tt|ƒjƒ}|j|_|j|_|j|_|j|_|S)N)rr Ú_clonerrrr)rÚobj)rr r rOs zRdataset._clonecCs(t|ƒdkr||_n||jkr$||_dS)zà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. @param ttl: The TTL @type ttl: intrN)Úlenr)rrr r r Ú update_ttlWs  zRdataset.update_ttlNcs¸|j|jks|j|jkrt‚|dk r.|j|ƒ|jtjjksJ|jtjjkr‚|jƒ}t |ƒdkrt|jtjj krt||_n|j|kr‚t ‚tjj |jƒr¤t |ƒdkr¤|j ƒtt|ƒj|ƒdS)a%Add the specified rdata to the rdataset. If the optional I{ttl} parameter is supplied, then self.update_ttl(ttl) will be called prior to adding the rdata. @param rd: The rdata @type rd: dns.rdata.Rdata object @param ttl: The TTL @type ttl: intNr)rrr rÚdnsÚ rdatatypeZRRSIGZSIGrrÚNONErZ is_singletonÚclearrr Úadd)rÚrdrr)rr r rcs  z Rdataset.addcs |j|jƒtt|ƒj|ƒdS)N)rrrr Ú union_update)rÚother)rr r r ƒs zRdataset.union_updatecs |j|jƒtt|ƒj|ƒdS)N)rrrr Úintersection_update)rr!)rr r r"‡s zRdataset.intersection_updatecs |j|jƒtt|ƒj|ƒdS)z‹Add all rdatas in other to self. @param other: The rdataset from which to update @type other: dns.rdataset.Rdataset objectN)rrrr Úupdate)rr!)rr r r#‹s zRdataset.updatecCsR|jdkrd}ndtjj|jƒd}dtjj|jƒdtjj|jƒ|dS)NrÚú(ú)z)rrrÚto_textÚ rdataclassrr)rZctextr r r Ú__repr__”s zRdataset.__repr__cCs|jƒS)N)r()rr r r Ú__str__œszRdataset.__str__csFt|tƒsdS|j|jks2|j|jks2|j|jkr6dStt|ƒj|ƒS)zTwo rdatasets are equal if they have the same class, type, and covers, and contain the same rdata. @rtype: boolF)Ú isinstancer rrrrÚ__eq__)rr!)rr r r-Ÿs    zRdataset.__eq__cCs |j|ƒ S)N)r-)rr!r r r Ú__ne__¬szRdataset.__ne__Tc KsØ|dk r"|j||ƒ}t|ƒ}d}nd}d}tƒ}|dk r>|} n|j} t|ƒdkrz|jd||tjj| ƒtj j|j ƒfƒnNxL|D]D} |jd|||j tjj| ƒtj j|j ƒ| jf||dœ|—Žfƒq€W|j ƒdd …S) a„Convert the rdataset into DNS master file format. @see: L{dns.name.Name.choose_relativity} for more information on how I{origin} and I{relativize} determine the way names are emitted. Any additional keyword arguments are passed on to the rdata to_text() method. @param name: If name is not None, emit a RRs with I{name} as the owner name. @type name: dns.name.Name object @param origin: The origin for relative names, or None. @type origin: dns.name.Name object @param relativize: True if names should names be relativized @type relativize: boolNr'r$rz %s%s%s %s z%s%s%d %s %s %s )ÚoriginÚ relativizeréÿÿÿÿ) Zchoose_relativityÚstrrrrÚwriterr)r(rrrÚgetvalue) rÚnamer/r0Úoverride_rdclassÚkwZntextZpadÚsrrr r r r(¯s*      zRdataset.to_textc Cs|dk r|}d}n|j}|jddƒt|ƒdkr`|j|||ƒtjd|j|ddƒ}|j|ƒdS|rxt|ƒ} t j | ƒn|} xŒ| D]„} |j|||ƒtjd|j||j dƒ}|j|ƒ|j ƒ} | j|||ƒ|j ƒ} |j| dƒtjd| | ƒ}|j|ƒ|jddƒq‚Wt|ƒSdS)a,Convert the rdataset to wire format. @param name: The owner name of the RRset that will be emitted @type name: dns.name.Name object @param file: The file to which the wire format data will be appended @type file: file @param compress: The compression table to use; the default is None. @type compress: dict @param origin: The origin to be appended to any relative names when they are emitted. The default is None. @returns: the number of records emitted @rtype: int NFréz!HHIHrz!H) rÚseekrÚto_wireÚstructÚpackrr3ÚlistÚrandomZshufflerÚtell) rr5ÚfileÚcompressr/r6Z want_shufflerZstuffÚlrÚstartÚendr r r r;âs6         zRdataset.to_wirecCs&|j|kr"|j|kr"|j|kr"dSdS)zSReturns True if this rdataset matches the specified class, type, and coversTF)rrr)rrrrr r r Úmatchs    zRdataset.match)N)NNTN)NNNT)rrrr Ú __slots__rrrrrrrr r"r#r*r+r-r.r(r;rFÚ __classcell__r r )rr r ,s$        2 /r cCspt|tƒrtjj|ƒ}t|tƒr,tjj|ƒ}t||ƒ}|j|ƒx*|D]"}tjj|j |j |ƒ}|j |ƒqFW|S)z¤Create an rdataset with the specified class, type, and TTL, and with the specified list of rdatas in text format. @rtype: dns.rdataset.Rdataset object ) r,rrr)Ú from_textrr rZrdatarrr)rrrÚ text_rdatasÚrÚtrr r r Úfrom_text_lists       rMcGst||||ƒS)zœCreate an rdataset with the specified class, type, and TTL, and with the specified rdatas in text format. @rtype: dns.rdataset.Rdataset object )rM)rrrrJr r r rI/srIcCsTt|ƒdkrtdƒ‚d}x6|D].}|dkrBt|j|jƒ}|j|ƒ|j|ƒqW|S)z‹Create an rdataset with the specified TTL, and with the specified list of rdata objects. @rtype: dns.rdataset.Rdataset object rzrdata list must not be emptyN)rÚ ValueErrorr rrrr)rÚrdatasrKrr r r Úfrom_rdata_list9s   rPcGs t||ƒS)zƒCreate an rdataset with the specified TTL, and with the specified rdata objects. @rtype: dns.rdataset.Rdataset object )rP)rrOr r r Ú from_rdataKsrQ)r r?Úiorr<Z dns.exceptionrZ dns.rdatatypeZdns.rdataclassZ dns.rdataZdns.setZ_compatrÚsetÚSetZ SimpleSetZ exceptionZ DNSExceptionrr r rMrIrPrQr r r r Ús$  q