-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathdns_lookup.py
More file actions
41 lines (30 loc) · 1 KB
/
dns_lookup.py
File metadata and controls
41 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import dnsq
import sys
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
from collections.abc import MutableMapping
else:
from collections import MutableMapping
class DNSLookup(MutableMapping):
"""
DNSLookup has the same interface as a dict, but talks to a DNS server
"""
def __init__(self):
pass
def __getitem__(self, key):
try:
return dnsq.mx_hosts_for(key)
except:
return []
def __setitem__(self, key, value):
raise InvalidOperation('Setting MX record not supported.')
def __delitem__(self, key):
raise InvalidOperation('Deleting MX record not supported.')
def __iter__(self):
raise InvalidOperation('Iterating over MX records not supported.')
def __len__(self):
raise InvalidOperation('Length of MX records not supported.')
class InvalidOperation(Exception):
def __init__(self, reason):
self.reason = reason
def __str__(self):
return self.reason