Making DNS Zones

dns.zone.from_text(text, origin=None, rdclass=<RdataClass.IN: 1>, relativize=True, zone_factory=<class 'dns.zone.Zone'>, filename=None, allow_include=False, check_origin=True, idna_codec=None)[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, 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.

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, origin=None, rdclass=<RdataClass.IN: 1>, relativize=True, zone_factory=<class 'dns.zone.Zone'>, filename=None, allow_include=True, check_origin=True)[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.

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, zone_factory=<class 'dns.zone.Zone'>, relativize=True, check_origin=True)[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.

Returns a subclass of dns.zone.Zone.