1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """DNS nodes. A node is a set of rdatasets."""
17
18 import StringIO
19
20 import dns.rdataset
21 import dns.rdatatype
22 import dns.renderer
23
25 """A DNS node.
26
27 A node is a set of rdatasets
28
29 @ivar rdatasets: the node's rdatasets
30 @type rdatasets: list of dns.rdataset.Rdataset objects"""
31
32 __slots__ = ['rdatasets']
33
35 """Initialize a DNS node.
36 """
37
38 self.rdatasets = [];
39
40 - def to_text(self, name, **kw):
41 """Convert a node to text format.
42
43 Each rdataset at the node is printed. Any keyword arguments
44 to this method are passed on to the rdataset's to_text() method.
45 @param name: the owner name of the rdatasets
46 @type name: dns.name.Name object
47 @rtype: string
48 """
49
50 s = StringIO.StringIO()
51 for rds in self.rdatasets:
52 if len(rds) > 0:
53 print >> s, rds.to_text(name, **kw)
54 return s.getvalue()[:-1]
55
57 return '<DNS node ' + str(id(self)) + '>'
58
60 """Two nodes are equal if they have the same rdatasets.
61
62 @rtype: bool
63 """
64
65
66
67 for rd in self.rdatasets:
68 if rd not in other.rdatasets:
69 return False
70 for rd in other.rdatasets:
71 if rd not in self.rdatasets:
72 return False
73 return True
74
76 return not self.__eq__(other)
77
80
83
86 """Find an rdataset matching the specified properties in the
87 current node.
88
89 @param rdclass: The class of the rdataset
90 @type rdclass: int
91 @param rdtype: The type of the rdataset
92 @type rdtype: int
93 @param covers: The covered type. Usually this value is
94 dns.rdatatype.NONE, but if the rdtype is dns.rdatatype.SIG or
95 dns.rdatatype.RRSIG, then the covers value will be the rdata
96 type the SIG/RRSIG covers. The library treats the SIG and RRSIG
97 types as if they were a family of
98 types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA). This makes RRSIGs much
99 easier to work with than if RRSIGs covering different rdata
100 types were aggregated into a single RRSIG rdataset.
101 @type covers: int
102 @param create: If True, create the rdataset if it is not found.
103 @type create: bool
104 @raises KeyError: An rdataset of the desired type and class does
105 not exist and I{create} is not True.
106 @rtype: dns.rdataset.Rdataset object
107 """
108
109 for rds in self.rdatasets:
110 if rds.match(rdclass, rdtype, covers):
111 return rds
112 if not create:
113 raise KeyError
114 rds = dns.rdataset.Rdataset(rdclass, rdtype)
115 self.rdatasets.append(rds)
116 return rds
117
120 """Get an rdataset matching the specified properties in the
121 current node.
122
123 None is returned if an rdataset of the specified type and
124 class does not exist and I{create} is not True.
125
126 @param rdclass: The class of the rdataset
127 @type rdclass: int
128 @param rdtype: The type of the rdataset
129 @type rdtype: int
130 @param covers: The covered type.
131 @type covers: int
132 @param create: If True, create the rdataset if it is not found.
133 @type create: bool
134 @rtype: dns.rdataset.Rdataset object or None
135 """
136
137 try:
138 rds = self.find_rdataset(rdclass, rdtype, covers, create)
139 except KeyError:
140 rds = None
141 return rds
142
144 """Delete the rdataset matching the specified properties in the
145 current node.
146
147 If a matching rdataset does not exist, it is not an error.
148
149 @param rdclass: The class of the rdataset
150 @type rdclass: int
151 @param rdtype: The type of the rdataset
152 @type rdtype: int
153 @param covers: The covered type.
154 @type covers: int
155 """
156
157 rds = self.get_rdataset(rdclass, rdtype, covers)
158 if not rds is None:
159 self.rdatasets.remove(rds)
160
176