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