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
23 import dns.exception
24 import dns.name
25 import dns.resolver
26 from ._compat import string_types
27
28 public_enum_domain = dns.name.from_text('e164.arpa.')
29
30
32 """Convert an E.164 number in textual form into a Name object whose
33 value is the ENUM domain name for that number.
34 @param text: an E.164 number in textual form.
35 @type text: str
36 @param origin: The domain in which the number should be constructed.
37 The default is e164.arpa.
38 @type origin: dns.name.Name object or None
39 @rtype: dns.name.Name object
40 """
41 parts = [d for d in text if d.isdigit()]
42 parts.reverse()
43 return dns.name.from_text('.'.join(parts), origin=origin)
44
45
47 """Convert an ENUM domain name into an E.164 number.
48 @param name: the ENUM domain name.
49 @type name: dns.name.Name object.
50 @param origin: A domain containing the ENUM domain name. The
51 name is relativized to this domain before being converted to text.
52 @type origin: dns.name.Name object or None
53 @param want_plus_prefix: if True, add a '+' to the beginning of the
54 returned number.
55 @rtype: str
56 """
57 if origin is not None:
58 name = name.relativize(origin)
59 dlabels = [d for d in name.labels if d.isdigit() and len(d) == 1]
60 if len(dlabels) != len(name.labels):
61 raise dns.exception.SyntaxError('non-digit labels in ENUM domain name')
62 dlabels.reverse()
63 text = b''.join(dlabels)
64 if want_plus_prefix:
65 text = b'+' + text
66 return text
67
68
69 -def query(number, domains, resolver=None):
86