Rdataset, RRset and Node Classes

An Rdataset is a set of Rdata objects which all have the same rdatatype, rdataclass, and covered type. Rdatasets also have a ttl (DNS time-to-live) field. Rdatasets support the normal Python set API, but are also ordered.

An RRset is a subclass of Rdataset that also has an owner name, i.e. a dns.name.Name that says where in the DNS tree this set is located.

A Node is a set of Rdataset objects, the Rdatasets being interpreted as at the same place (i.e. same owner name) int the DNS tree. Nodes are primarily used in Zone objects.

class dns.rdataset.Rdataset(rdclass, rdtype, covers=<RdataType.TYPE0: 0>, ttl=0)[source]

A DNS rdataset.

Create a new rdataset of the specified class and type.

rdclass, an int, the rdataclass.

rdtype, an int, the rdatatype.

covers, an int, the covered rdatatype.

ttl, an int, the TTL.

add(rd, ttl=None)[source]

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.

intersection_update(other)[source]

Update the set, removing any elements from other which are not in both sets.

match(rdclass, rdtype, covers)[source]

Returns True if this rdataset matches the specified class, type, and covers.

processing_order()[source]

Return 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 perference shuffled.

For types that do not define a processing order, the rdatas are simply shuffled.

to_text(name=None, origin=None, relativize=True, override_rdclass=None, want_comments=False, **kw)[source]

Convert 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.

to_wire(name, file, compress=None, origin=None, override_rdclass=None, want_shuffle=True)[source]

Convert 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.

union_update(other)[source]

Update the set, adding any elements from other which are not already in the set.

update(other)[source]

Add all rdatas in other to self.

other, a dns.rdataset.Rdataset, the rdataset from which to update.

update_ttl(ttl)[source]

Perform 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.

class dns.rrset.RRset(name, rdclass, rdtype, covers=<RdataType.TYPE0: 0>, deleting=None)[source]

A DNS RRset (named rdataset).

RRset inherits from Rdataset, and RRsets can be treated as Rdatasets in most cases. There are, however, a few notable exceptions. RRsets have different to_wire() and to_text() method arguments, reflecting the fact that RRsets always have an owner name.

Create a new RRset.

full_match(name, rdclass, rdtype, covers, deleting=None)[source]

Returns True if this rrset matches the specified name, class, type, covers, and deletion state.

match(*args, **kwargs)[source]

Does this rrset match the specified attributes?

Behaves as full_match() if the first argument is a dns.name.Name, and as dns.rdataset.Rdataset.match() otherwise.

(This behavior fixes a design mistake where the signature of this method became incompatible with that of its superclass. The fix makes RRsets matchable as Rdatasets while preserving backwards compatibility.)

to_rdataset()[source]

Convert an RRset into an Rdataset.

Returns a dns.rdataset.Rdataset.

to_text(origin=None, relativize=True, **kw)[source]

Convert the RRset 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.

origin, a dns.name.Name or None, the origin for relative names.

relativize, a bool. If True, names will be relativized to origin.

to_wire(file, compress=None, origin=None, **kw)[source]

Convert the RRset to wire format.

All keyword arguments are passed to dns.rdataset.to_wire(); see that function for details.

Returns an int, the number of records emitted.

class dns.node.Node[source]

A Node is a set of rdatasets.

delete_rdataset(rdclass, rdtype, covers=<RdataType.TYPE0: 0>)[source]

Delete the rdataset matching the specified properties in the current node.

If a matching rdataset does not exist, it is not an error.

rdclass, an int, the class of the rdataset.

rdtype, an int, the type of the rdataset.

covers, an int, the covered type.

find_rdataset(rdclass, rdtype, covers=<RdataType.TYPE0: 0>, create=False)[source]

Find an rdataset matching the specified properties in the current node.

rdclass, an int, the class of the rdataset.

rdtype, an int, the type of the rdataset.

covers, an int or None, 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.

create, a bool. If True, create the rdataset if it is not found.

Raises KeyError if an rdataset of the desired type and class does not exist and create is not True.

Returns a dns.rdataset.Rdataset.

get_rdataset(rdclass, rdtype, covers=<RdataType.TYPE0: 0>, create=False)[source]

Get an rdataset matching the specified properties in the current node.

None is returned if an rdataset of the specified type and class does not exist and create is not True.

rdclass, an int, the class of the rdataset.

rdtype, an int, the type of the rdataset.

covers, an int, 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.

create, a bool. If True, create the rdataset if it is not found.

Returns a dns.rdataset.Rdataset or None.

replace_rdataset(replacement)[source]

Replace an rdataset.

It is not an error if there is no rdataset matching replacement.

Ownership of the replacement object is transferred to the node; in other words, this method does not store a copy of replacement at the node, it stores replacement itself.

replacement, a dns.rdataset.Rdataset.

Raises ValueError if replacement is not a dns.rdataset.Rdataset.

to_text(name, **kw)[source]

Convert a node to text format.

Each rdataset at the node is printed. Any keyword arguments to this method are passed on to the rdataset’s to_text() method.

name, a dns.name.Name or str, the owner name of the rdatasets.

Returns a str.