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 """Create an RRset with the specified name, TTL, class, and type, and with
124 the specified list of rdatas in text format.
125
126 @rtype: dns.rrset.RRset object
127 """
128
129 if isinstance(name, string_types):
130 name = dns.name.from_text(name, None)
131 if isinstance(rdclass, string_types):
132 rdclass = dns.rdataclass.from_text(rdclass)
133 if isinstance(rdtype, string_types):
134 rdtype = dns.rdatatype.from_text(rdtype)
135 r = RRset(name, rdclass, rdtype)
136 r.update_ttl(ttl)
137 for t in text_rdatas:
138 rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
139 r.add(rd)
140 return r
141
142
143 -def from_text(name, ttl, rdclass, rdtype, *text_rdatas):
144 """Create an RRset with the specified name, TTL, class, and type and with
145 the specified rdatas in text format.
146
147 @rtype: dns.rrset.RRset object
148 """
149
150 return from_text_list(name, ttl, rdclass, rdtype, text_rdatas)
151
152
154 """Create an RRset with the specified name and TTL, and with
155 the specified list of rdata objects.
156
157 @rtype: dns.rrset.RRset object
158 """
159
160 if isinstance(name, string_types):
161 name = dns.name.from_text(name, None)
162
163 if len(rdatas) == 0:
164 raise ValueError("rdata list must not be empty")
165 r = None
166 for rd in rdatas:
167 if r is None:
168 r = RRset(name, rd.rdclass, rd.rdtype)
169 r.update_ttl(ttl)
170 r.add(rd)
171 return r
172
173
175 """Create an RRset with the specified name and TTL, and with
176 the specified rdata objects.
177
178 @rtype: dns.rrset.RRset object
179 """
180
181 return from_rdata_list(name, ttl, rdatas)
182