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.RdataClass or str) – The rdata class.

  • rdtype (dns.rdatatype.RdataType or str) – The rdata type.

  • tok (dns.tokenizer.Tokenizer or str) – The tokenizer or input string.

  • origin (dns.name.Name or None) – The origin to use for relative names.

  • relativize (bool) – If True, names will be relativized. Default is True.

  • relativize_to (dns.name.Name or None) – The origin to use when relativizing. Defaults to origin.

  • idna_codec (dns.name.IDNACodec or None) – The IDNA encoder/decoder to use when creating a tokenizer. If None, the default IDNA 2003 codec is used.

Returns:

An instance of the chosen Rdata subclass.

Return type:

Rdata

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:
Returns:

An instance of the chosen Rdata subclass.

Return type:

Rdata

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.RdataClass or str) – The rdata class.

  • rdtype (dns.rdatatype.RdataType or str) – 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.Name or None) – If not None, names will be relativized to this origin.

Returns:

An instance of the chosen Rdata subclass.

Return type:

Rdata

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.Rdata implementing 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, or dns.rdataclass.ANY for 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 the GenericRdata class.