1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """DNS name dictionary"""
17
18 import dns.name
19
21
22 """A dictionary whose keys are dns.name.Name objects.
23 @ivar max_depth: the maximum depth of the keys that have ever been
24 added to the dictionary.
25 @type max_depth: int
26 """
27
31
33 if not isinstance(key, dns.name.Name):
34 raise ValueError('NameDict key must be a name')
35 depth = len(key)
36 if depth > self.max_depth:
37 self.max_depth = depth
38 super(NameDict, self).__setitem__(key, value)
39
41 """Find the deepest match to I{name} in the dictionary.
42
43 The deepest match is the longest name in the dictionary which is
44 a superdomain of I{name}.
45
46 @param name: the name
47 @type name: dns.name.Name object
48 @rtype: (key, value) tuple
49 """
50
51 depth = len(name)
52 if depth > self.max_depth:
53 depth = self.max_depth
54 for i in xrange(-depth, 0):
55 n = dns.name.Name(name[i:])
56 if self.has_key(n):
57 return (n, self[n])
58 v = self[dns.name.empty]
59 return (dns.name.empty, v)
60