The RRSet Reader
dns.zonefile.read_rrsets()
reads one or more RRsets from text format. It
is designed to be used in situations where you are processing DNS data in
text format, but do not want or need a valid zone. For example, a DNS registry
web application might want to allow the user to input RRs.
- dns.zonefile.read_rrsets(text: ~typing.Any, name: ~dns.name.Name | str | None = None, ttl: int | None = None, rdclass: ~dns.rdataclass.RdataClass | str | None = RdataClass.IN, default_rdclass: ~dns.rdataclass.RdataClass | str = RdataClass.IN, rdtype: ~dns.rdatatype.RdataType | str | None = None, default_ttl: int | str | None = None, idna_codec: ~dns.name.IDNACodec | None = None, origin: ~dns.name.Name | str | None = <DNS name .>, relativize: bool = False) List[RRset] [source]
Read one or more rrsets from the specified text, possibly subject to restrictions.
text, a file object or a string, is the input to process.
name, a string,
dns.name.Name
, orNone
, is the owner name of the rrset. If notNone
, then the owner name is “forced”, and the input must not specify an owner name. IfNone
, then any owner names are allowed and must be present in the input.ttl, an
int
, string, or None. If notNone
, the the TTL is forced to be the specified value and the input must not specify a TTL. IfNone
, then a TTL may be specified in the input. If it is not specified, then the default_ttl will be used.rdclass, a
dns.rdataclass.RdataClass
, string, orNone
. If notNone
, then the class is forced to the specified value, and the input must not specify a class. IfNone
, then the input may specify a class that matches default_rdclass. Note that it is not possible to return rrsets with differing classes; specifyingNone
for the class simply allows the user to optionally type a class as that may be convenient when cutting and pasting.default_rdclass, a
dns.rdataclass.RdataClass
or string. The class of the returned rrsets.rdtype, a
dns.rdatatype.RdataType
, string, orNone
. If notNone
, then the type is forced to the specified value, and the input must not specify a type. IfNone
, then a type must be present for each RR.default_ttl, an
int
, string, orNone
. If notNone
, then if the TTL is not forced and is not specified, then this value will be used. ifNone
, then if the TTL is not forced an error will occur if the TTL is not specified.idna_codec, a
dns.name.IDNACodec
, specifies the IDNA encoder/decoder. IfNone
, the default IDNA 2003 encoder/decoder is used. Note that codecs only apply to the owner name; dnspython does not do IDNA for names in rdata, as there is no IDNA zonefile format.origin, a string,
dns.name.Name
, orNone
, is the origin for any relative names in the input, and also the origin to relativize to if relativize isTrue
.relativize, a bool. If
True
, names are relativized to the origin; ifFalse
then any relative names in the input are made absolute by appending the origin.
Examples
Read RRSets with name, TTL, and rdclass forced:
input = '''
mx 10 a
mx 20 b
ns ns1
'''
rrsets = dns.read_rrsets(input, name='name', ttl=300)
Read RRSets with name, TTL, rdclass, and rdtype forced:
input = '''
10 a
20 b
'''
rrsets = dns.read_rrsets(input, name='name', ttl=300, rdtype='mx')
Note that in this case the length of rrsets will always be one.
Read relativized RRsets with unforced rdclass (but which must match default_rdclass):
input = '''
name1 20 MX 10 a.example.
name2 30 IN MX 20 b
'''
rrsets = dns.read_rrsets(input, origin='example', relativize=True,
rdclass=None)
The dns.zonefile.Reader Class
The Reader
class reads data in DNS zonefile format, or various
restrictions of that format, and converts it to a sequence of operations
in a transaction.
This class is primarily used by dns.zone.Zone.from_text()
and
dns.zonefile.read_rrsets
, but may be useful for other software which needs
to process the zonefile format.
- class dns.zonefile.Reader(tok: Tokenizer, rdclass: RdataClass, txn: Transaction, allow_include: bool = False, allow_directives: bool | Iterable[str] = True, force_name: Name | None = None, force_ttl: int | None = None, force_rdclass: RdataClass | None = None, force_rdtype: RdataType | None = None, default_ttl: int | None = None)[source]
Read a DNS zone file into a transaction.