1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """DNS RRsets (an RRset is a named rdataset)"""
19
20
21 import dns.name
22 import dns.rdataset
23 import dns.rdataclass
24 import dns.renderer
25 from ._compat import string_types
26
27
28 -class RRset(dns.rdataset.Rdataset):
29
30 """A DNS RRset (named rdataset).
31
32 RRset inherits from Rdataset, and RRsets can be treated as
33 Rdatasets in most cases. There are, however, a few notable
34 exceptions. RRsets have different to_wire() and to_text() method
35 arguments, reflecting the fact that RRsets always have an owner
36 name.
37 """
38
39 __slots__ = ['name', 'deleting']
40
48
54
67
70
72 if not isinstance(other, RRset):
73 return False
74 if self.name != other.name:
75 return False
76 return super(RRset, self).__eq__(other)
77
78 - def match(self, name, rdclass, rdtype, covers, deleting=None):
79 """Returns ``True`` if this rrset matches the specified class, type,
80 covers, and deletion state.
81 """
82
83 if not super(RRset, self).match(rdclass, rdtype, covers):
84 return False
85 if self.name != name or self.deleting != deleting:
86 return False
87 return True
88
89 - def to_text(self, origin=None, relativize=True, **kw):
90 """Convert the RRset into DNS master file format.
91
92 See ``dns.name.Name.choose_relativity`` for more information
93 on how *origin* and *relativize* determine the way names
94 are emitted.
95
96 Any additional keyword arguments are passed on to the rdata
97 ``to_text()`` method.
98
99 *origin*, a ``dns.name.Name`` or ``None``, the origin for relative
100 names.
101
102 *relativize*, a ``bool``. If ``True``, names will be relativized
103 to *origin*.
104 """
105
106 return super(RRset, self).to_text(self.name, origin, relativize,
107 self.deleting, **kw)
108
109 - def to_wire(self, file, compress=None, origin=None, **kw):
110 """Convert the RRset to wire format.
111
112 All keyword arguments are passed to ``dns.rdataset.to_wire()``; see
113 that function for details.
114
115 Returns an ``int``, the number of records emitted.
116 """
117
118 return super(RRset, self).to_wire(self.name, file, compress, origin,
119 self.deleting, **kw)
120
122 """Convert an RRset into an Rdataset.
123
124 Returns a ``dns.rdataset.Rdataset``.
125 """
126 return dns.rdataset.from_rdata_list(self.ttl, list(self))
127
128
129 -def from_text_list(name, ttl, rdclass, rdtype, text_rdatas,
130 idna_codec=None):
131 """Create an RRset with the specified name, TTL, class, and type, and with
132 the specified list of rdatas in text format.
133
134 Returns a ``dns.rrset.RRset`` object.
135 """
136
137 if isinstance(name, string_types):
138 name = dns.name.from_text(name, None, idna_codec=idna_codec)
139 if isinstance(rdclass, string_types):
140 rdclass = dns.rdataclass.from_text(rdclass)
141 if isinstance(rdtype, string_types):
142 rdtype = dns.rdatatype.from_text(rdtype)
143 r = RRset(name, rdclass, rdtype)
144 r.update_ttl(ttl)
145 for t in text_rdatas:
146 rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
147 r.add(rd)
148 return r
149
150
151 -def from_text(name, ttl, rdclass, rdtype, *text_rdatas):
152 """Create an RRset with the specified name, TTL, class, and type and with
153 the specified rdatas in text format.
154
155 Returns a ``dns.rrset.RRset`` object.
156 """
157
158 return from_text_list(name, ttl, rdclass, rdtype, text_rdatas)
159
160
162 """Create an RRset with the specified name and TTL, and with
163 the specified list of rdata objects.
164
165 Returns a ``dns.rrset.RRset`` object.
166 """
167
168 if isinstance(name, string_types):
169 name = dns.name.from_text(name, None, idna_codec=idna_codec)
170
171 if len(rdatas) == 0:
172 raise ValueError("rdata list must not be empty")
173 r = None
174 for rd in rdatas:
175 if r is None:
176 r = RRset(name, rd.rdclass, rd.rdtype)
177 r.update_ttl(ttl)
178 r.add(rd)
179 return r
180
181
183 """Create an RRset with the specified name and TTL, and with
184 the specified rdata objects.
185
186 Returns a ``dns.rrset.RRset`` object.
187 """
188
189 return from_rdata_list(name, ttl, rdatas)
190