DNS Rdata Base Class
All Rdata objects are instances of some subclass of
dns.rdata.Rdata, and are immutable. The Rdata factory functions
described in Making DNS Rdata will create objects which are instances
of the most appropriate subclass. For example, a AAAA record will be
an instance of the dns.rdtypes.IN.AAAA.AAAA class, but a record of
TYPE12345, which we don’t know anything specific about, will be an
instance of dns.rdata.GenericRdata.
Rdata of the same type and class are ordered. For rdata that do not contain domain names, or which contain absolute domain names, the order is the same as the DNSSEC ordering. For rdata containing at least one relative name, that rdata will sort before any rdata with an absolute name. This makes comparison well defined (compared to earlier versions of dnspython), but is a stop-gap measure for backwards compatibility. We want to disallow this type of comparison because it easily leads to bugs. Consider this rdataset:
$ORIGIN example.
name 300 IN NS a ; 1
NS a. ; 2
In this case the record marked “2” sorts before the one marked “1” when all the names are made absolute and the DNSSEC ordering is used. But when relative comparisons are allowed, “1” sorts before “2”. This isn’t merely cosmetic, as code making a DNSSEC signature or computing a zone checksum would get different answers for the same content if it failed to make all names absolute before sorting.
Comparing relative rdata with absolute is thus deprecated and will be
removed in a future version of dnspython. Setting
dns.rdata._allow_relative_comparisons to True will allow the
future behavior to be tested with existing code.
- class dns.rdata.Rdata(*args, **kwargs)[source]
- covers() RdataType[source]
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).
- Return type:
- extended_rdatatype() int[source]
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.
- Return type:
- replace(**kwargs: Any) Rdata[source]
Create a new Rdata instance based on the instance replace was invoked on. It is possible to pass different parameters to override the corresponding properties of the base Rdata.
Any field specific to the Rdata type can be replaced, but the rdtype and rdclass fields cannot.
- to_digestable(origin: Name | None = None) bytes[source]
Convert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form.
- Return type:
- to_generic(origin: Name | None = None) GenericRdata[source]
Create a
dns.rdata.GenericRdataequivalent of this rdata.- Return type:
- to_styled_text(style: RdataStyle) str[source]
Convert an rdata to styled text format.
See the documentation for
dns.rdata.RdataStylefor a description of the style parameters.- Return type:
- to_text(origin: Name | None = None, relativize: bool = True, style: RdataStyle | None = None, **kw: Any) str[source]
Convert an rdata to text format.
- Parameters:
style (
dns.rdata.RdataStyleorNone) – If specified, overrides origin and relativize.- Return type:
- to_wire(file: Any | None = None, compress: dict[Name, int] | None = None, origin: Name | None = None, canonicalize: bool = False) bytes | None[source]
Convert an rdata to wire format.
- Returns:
Wire-format bytes if no output file was specified, or
Noneif a file was provided.- Return type:
bytes or
None
- class dns.rdata.RdataStyle(omit_final_dot: bool = False, idna_codec: IDNACodec | None = None, origin: Name | None = None, relativize: bool = False, txt_is_utf8: bool = False, base64_chunk_size: int = 32, base64_chunk_separator: str = ' ', hex_chunk_size: int = 128, hex_chunk_separator: str = ' ', truncate_crypto: bool = False)[source]
Rdata text styles
An
RdataStyleis also adns.name.NameStyle; see that class for a description of its options.- txt_is_utf8
A
bool. IfTrue, TXT-like records will be treated as UTF-8 if they decode successfully, and the output string may contain any Unicode codepoint. IfFalse(the default), TXT-like records are treated according to RFC 1035 rules.
- base64_chunk_size
An
int(default 32). The chunk size for text representations that break base64 strings into chunks.
- base64_chunk_separator
A
str(default" "). The separator for text representations that break base64 strings into chunks.
- hex_chunk_size
An
int(default 128). The chunk size for text representations that break hex strings into chunks.
- hex_chunk_separator
A
str(default" "). The separator for text representations that break hex strings into chunks.
- truncate_crypto
A
bool(defaultFalse). IfTrue, output of crypto types (e.g. DNSKEY) is altered to be human-readable in a debugging context, but the crypto content is removed. Use of this option will lose information.