Making DNS Rdata

dns.rdata.from_text(rdclass: RdataClass | str, rdtype: RdataType | str, tok: Tokenizer | str, origin: Name | None = None, relativize: bool = True, relativize_to: Name | None = None, idna_codec: IDNACodec | None = None) Rdata[source]

Build an rdata object from text format.

This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used.

Once a class is chosen, its from_text() class method is called with the parameters to this function.

If tok is a str, then a tokenizer is created and the string is used as its input.

rdclass, a dns.rdataclass.RdataClass or str, the rdataclass.

rdtype, a dns.rdatatype.RdataType or str, the rdatatype.

tok, a dns.tokenizer.Tokenizer or a str.

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.

idna_codec, a dns.name.IDNACodec, specifies the IDNA encoder/decoder to use if a tokenizer needs to be created. If None, the default IDNA 2003 encoder/decoder is used. If a tokenizer is not created, then the codec associated with the tokenizer is the one that is used.

Returns an instance of the chosen Rdata subclass.

dns.rdata.from_wire_parser(rdclass: RdataClass | str, rdtype: RdataType | str, parser: Parser, origin: Name | None = None) Rdata[source]

Build an rdata object from wire format

This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used.

Once a class is chosen, its from_wire() class method is called with the parameters to this function.

rdclass, a dns.rdataclass.RdataClass or str, the rdataclass.

rdtype, a dns.rdatatype.RdataType or str, the rdatatype.

parser, a dns.wire.Parser, the parser, which should be restricted to the rdata length.

origin, a dns.name.Name (or None). If not None, then names will be relativized to this origin.

Returns an instance of the chosen Rdata subclass.

dns.rdata.from_wire(rdclass: RdataClass | str, rdtype: RdataType | str, wire: bytes, current: int, rdlen: int, origin: Name | None = None) Rdata[source]

Build an rdata object from wire format

This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used.

Once a class is chosen, its from_wire() class method is called with the parameters to this function.

rdclass, an int, the rdataclass.

rdtype, an int, the rdatatype.

wire, a bytes, the wire-format message.

current, an int, the offset in wire of the beginning of the rdata.

rdlen, an int, the length of the wire-format rdata

origin, a dns.name.Name (or None). If not None, then names will be relativized to this origin.

Returns an instance of the chosen Rdata subclass.

Miscellaneous Rdata Functions

dns.rdata.register_type(implementation: Any, rdtype: int, rdtype_text: str, is_singleton: bool = False, rdclass: RdataClass = RdataClass.IN) None[source]

Dynamically register a module to handle an rdatatype.

implementation, a subclass of dns.rdata.Rdata implementing the type, or a module containing such a class named by its text form.

rdtype, an int, the rdatatype to register.

rdtype_text, a str, the textual form of the rdatatype.

is_singleton, a bool, indicating if the type is a singleton (i.e. RRsets of the type can have only one member.)

rdclass, the rdataclass of the type, or dns.rdataclass.ANY if it applies to all classes.

dns.rdata.load_all_types(disable_dynamic_load=True)[source]

Load all rdata types for which dnspython has a non-generic implementation.

Normally dnspython loads DNS rdatatype implementations on demand, but in some specialized cases loading all types at an application-controlled time is preferred.

If disable_dynamic_load, a bool, is True then dnspython will not attempt to use its dynamic loading mechanism if an unknown type is subsequently encountered, and will simply use the GenericRdata class.