-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path_util.py
More file actions
39 lines (30 loc) · 995 Bytes
/
_util.py
File metadata and controls
39 lines (30 loc) · 995 Bytes
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
__all__ = ["_reverse_host", "_check_in"]
def _reverse_host(host, trailing_dot=True):
rv = ".".join(reversed(host.split(".")))
if trailing_dot:
return rv + "."
else:
return rv
def _check_in(domains, hostname):
parts = hostname.split(".")
# Single label names are invalid
if len(parts) == 1:
return
if hostname in domains:
return hostname
if parts[-1] in domains:
return parts[-1]
if len(parts) > 2:
subdomain_rule = "{}.{}".format(parts[-2], parts[-1])
if subdomain_rule in domains:
return subdomain_rule
if len(parts) > 3:
subdomain_rule = "{}.{}.{}".format(parts[-3], parts[-2], parts[-1])
if subdomain_rule in domains:
return subdomain_rule
if len(parts) > 4:
subdomain_rule = "{}.{}.{}.{}".format(
parts[-4], parts[-3], parts[-2], parts[-1]
)
if subdomain_rule in domains:
return subdomain_rule