Making DNS Zones

dns.zone.from_text(text: str, origin: ~dns.name.Name | str | None = None, rdclass: ~dns.rdataclass.RdataClass = RdataClass.IN, relativize: bool = True, zone_factory: ~typing.Any = <class 'dns.zone.Zone'>, filename: str | None = None, allow_include: bool = False, check_origin: bool = True, idna_codec: ~dns.name.IDNACodec | None = None, allow_directives: bool | ~typing.Iterable[str] = True) Zone[source]

Build a zone object from a zone file format string.

text, a str, the zone file format input.

origin, a dns.name.Name, a str, or None. The origin of the zone; if not specified, the first $ORIGIN statement in the zone file will determine the origin of the zone.

rdclass, a dns.rdataclass.RdataClass, the zone’s rdata class; the default is class IN.

relativize, a bool, determine’s whether domain names are relativized to the zone’s origin. The default is True.

zone_factory, the zone factory to use or None. If None, then dns.zone.Zone will be used. The value may be any class or callable that returns a subclass of dns.zone.Zone.

filename, a str or None, the filename to emit when describing where an error occurred; the default is '<string>'.

allow_include, a bool. If True, the default, then $INCLUDE directives are permitted. If False, then encoutering a $INCLUDE will raise a SyntaxError exception.

check_origin, a bool. If True, the default, then sanity checks of the origin node will be made by calling the zone’s check_origin() method.

idna_codec, a dns.name.IDNACodec, specifies the IDNA encoder/decoder. If None, the default IDNA 2003 encoder/decoder is used.

allow_directives, a bool or an iterable of str. If True, the default, then directives are permitted, and the allow_include parameter controls whether $INCLUDE is permitted. If False or an empty iterable, then no directive processing is done and any directive-like text will be treated as a regular owner name. If a non-empty iterable, then only the listed directives (including the $) are allowed.

Raises dns.zone.NoSOA if there is no SOA RRset.

Raises dns.zone.NoNS if there is no NS RRset.

Raises KeyError if there is no origin node.

Returns a subclass of dns.zone.Zone.

dns.zone.from_file(f: ~typing.Any, origin: ~dns.name.Name | str | None = None, rdclass: ~dns.rdataclass.RdataClass = RdataClass.IN, relativize: bool = True, zone_factory: ~typing.Any = <class 'dns.zone.Zone'>, filename: str | None = None, allow_include: bool = True, check_origin: bool = True, idna_codec: ~dns.name.IDNACodec | None = None, allow_directives: bool | ~typing.Iterable[str] = True) Zone[source]

Read a zone file and build a zone object.

f, a file or str. If f is a string, it is treated as the name of a file to open.

origin, a dns.name.Name, a str, or None. The origin of the zone; if not specified, the first $ORIGIN statement in the zone file will determine the origin of the zone.

rdclass, an int, the zone’s rdata class; the default is class IN.

relativize, a bool, determine’s whether domain names are relativized to the zone’s origin. The default is True.

zone_factory, the zone factory to use or None. If None, then dns.zone.Zone will be used. The value may be any class or callable that returns a subclass of dns.zone.Zone.

filename, a str or None, the filename to emit when describing where an error occurred; the default is '<string>'.

allow_include, a bool. If True, the default, then $INCLUDE directives are permitted. If False, then encoutering a $INCLUDE will raise a SyntaxError exception.

check_origin, a bool. If True, the default, then sanity checks of the origin node will be made by calling the zone’s check_origin() method.

idna_codec, a dns.name.IDNACodec, specifies the IDNA encoder/decoder. If None, the default IDNA 2003 encoder/decoder is used.

allow_directives, a bool or an iterable of str. If True, the default, then directives are permitted, and the allow_include parameter controls whether $INCLUDE is permitted. If False or an empty iterable, then no directive processing is done and any directive-like text will be treated as a regular owner name. If a non-empty iterable, then only the listed directives (including the $) are allowed.

Raises dns.zone.NoSOA if there is no SOA RRset.

Raises dns.zone.NoNS if there is no NS RRset.

Raises KeyError if there is no origin node.

Returns a subclass of dns.zone.Zone.

dns.zone.from_xfr(xfr: ~typing.Any, zone_factory: ~typing.Any = <class 'dns.zone.Zone'>, relativize: bool = True, check_origin: bool = True) Zone[source]

Convert the output of a zone transfer generator into a zone object.

xfr, a generator of dns.message.Message objects, typically dns.query.xfr().

relativize, a bool, determine’s whether domain names are relativized to the zone’s origin. The default is True. It is essential that the relativize setting matches the one specified to the generator.

check_origin, a bool. If True, the default, then sanity checks of the origin node will be made by calling the zone’s check_origin() method.

Raises dns.zone.NoSOA if there is no SOA RRset.

Raises dns.zone.NoNS if there is no NS RRset.

Raises KeyError if there is no origin node.

Raises ValueError if no messages are yielded by the generator.

Returns a subclass of dns.zone.Zone.