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