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
, astr
, orNone
. 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 isTrue
.zone_factory, the zone factory to use or
None
. IfNone
, thendns.zone.Zone
will be used. The value may be any class or callable that returns a subclass ofdns.zone.Zone
.filename, a
str
orNone
, the filename to emit when describing where an error occurred; the default is'<string>'
.allow_include, a
bool
. IfTrue
, the default, then$INCLUDE
directives are permitted. IfFalse
, then encoutering a$INCLUDE
will raise aSyntaxError
exception.check_origin, a
bool
. IfTrue
, the default, then sanity checks of the origin node will be made by calling the zone’scheck_origin()
method.idna_codec, a
dns.name.IDNACodec
, specifies the IDNA encoder/decoder. IfNone
, the default IDNA 2003 encoder/decoder is used.allow_directives, a
bool
or an iterable of str. IfTrue
, the default, then directives are permitted, and the allow_include parameter controls whether$INCLUDE
is permitted. IfFalse
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
, astr
, orNone
. 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 isTrue
.zone_factory, the zone factory to use or
None
. IfNone
, thendns.zone.Zone
will be used. The value may be any class or callable that returns a subclass ofdns.zone.Zone
.filename, a
str
orNone
, the filename to emit when describing where an error occurred; the default is'<string>'
.allow_include, a
bool
. IfTrue
, the default, then$INCLUDE
directives are permitted. IfFalse
, then encoutering a$INCLUDE
will raise aSyntaxError
exception.check_origin, a
bool
. IfTrue
, the default, then sanity checks of the origin node will be made by calling the zone’scheck_origin()
method.idna_codec, a
dns.name.IDNACodec
, specifies the IDNA encoder/decoder. IfNone
, the default IDNA 2003 encoder/decoder is used.allow_directives, a
bool
or an iterable of str. IfTrue
, the default, then directives are permitted, and the allow_include parameter controls whether$INCLUDE
is permitted. IfFalse
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, typicallydns.query.xfr()
.relativize, a
bool
, determine’s whether domain names are relativized to the zone’s origin. The default isTrue
. It is essential that the relativize setting matches the one specified to the generator.check_origin, a
bool
. IfTrue
, the default, then sanity checks of the origin node will be made by calling the zone’scheck_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
.