1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """DNS E.164 helpers
17
18 @var public_enum_domain: The DNS public ENUM domain, e164.arpa.
19 @type public_enum_domain: dns.name.Name object
20 """
21
22 import dns.exception
23 import dns.name
24 import dns.resolver
25
26 public_enum_domain = dns.name.from_text('e164.arpa.')
27
29 """Convert an E.164 number in textual form into a Name object whose
30 value is the ENUM domain name for that number.
31 @param text: an E.164 number in textual form.
32 @type text: str
33 @param origin: The domain in which the number should be constructed.
34 The default is e164.arpa.
35 @type origin: dns.name.Name object or None
36 @rtype: dns.name.Name object
37 """
38 parts = [d for d in text if d.isdigit()]
39 parts.reverse()
40 return dns.name.from_text('.'.join(parts), origin=origin)
41
43 """Convert an ENUM domain name into an E.164 number.
44 @param name: the ENUM domain name.
45 @type name: dns.name.Name object.
46 @param origin: A domain containing the ENUM domain name. The
47 name is relativized to this domain before being converted to text.
48 @type origin: dns.name.Name object or None
49 @param want_plus_prefix: if True, add a '+' to the beginning of the
50 returned number.
51 @rtype: str
52 """
53 if not origin is None:
54 name = name.relativize(origin)
55 dlabels = [d for d in name.labels if (d.isdigit() and len(d) == 1)]
56 if len(dlabels) != len(name.labels):
57 raise dns.exception.SyntaxError('non-digit labels in ENUM domain name')
58 dlabels.reverse()
59 text = ''.join(dlabels)
60 if want_plus_prefix:
61 text = '+' + text
62 return text
63
64 -def query(number, domains, resolver=None):
80