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.- Parameters:
rdclass (
dns.rdataclass.RdataClassorstr) – The rdata class.rdtype (
dns.rdatatype.RdataTypeorstr) – The rdata type.tok (
dns.tokenizer.Tokenizerorstr) – The tokenizer or input string.origin (
dns.name.NameorNone) – The origin to use for relative names.relativize (bool) – If
True, names will be relativized. Default isTrue.relativize_to (
dns.name.NameorNone) – The origin to use when relativizing. Defaults to origin.idna_codec (
dns.name.IDNACodecorNone) – The IDNA encoder/decoder to use when creating a tokenizer. IfNone, the default IDNA 2003 codec is used.
- Returns:
An instance of the chosen
Rdatasubclass.- Return type:
- 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.
- Parameters:
rdclass (
dns.rdataclass.RdataClassorstr) – The rdata class.rdtype (
dns.rdatatype.RdataTypeorstr) – The rdata type.parser (
dns.wire.Parser) – The wire format parser, restricted to the rdata length.origin (
dns.name.NameorNone) – If notNone, names will be relativized to this origin.
- Returns:
An instance of the chosen
Rdatasubclass.- Return type:
- 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.
- Parameters:
rdclass (
dns.rdataclass.RdataClassorstr) – The rdata class.rdtype (
dns.rdatatype.RdataTypeorstr) – The rdata type.wire (bytes) – The wire-format message.
current (int) – The offset of the start of the rdata in wire.
rdlen (int) – The length of the rdata in wire format.
origin (
dns.name.NameorNone) – If notNone, names will be relativized to this origin.
- Returns:
An instance of the chosen
Rdatasubclass.- Return type:
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.
- Parameters:
implementation – A subclass of
dns.rdata.Rdataimplementing the type, or a module containing such a class named by its text form.rdtype (int) – The rdatatype to register.
rdtype_text (str) – The textual form of the rdatatype.
is_singleton (bool) – If
True, RRsets of this type can have only one member.rdclass (
dns.rdataclass.RdataClass) – The rdata class, ordns.rdataclass.ANYfor 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.
- Parameters:
disable_dynamic_load (bool) – If
True(the default), dnspython will not attempt to use its dynamic loading mechanism if an unknown type is subsequently encountered, and will simply use theGenericRdataclass.