iup 0.3__py3-none-any.whl → 0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iup/main.py +47 -9
- {iup-0.3.dist-info → iup-0.4.dist-info}/METADATA +1 -1
- iup-0.4.dist-info/RECORD +8 -0
- {iup-0.3.dist-info → iup-0.4.dist-info}/WHEEL +1 -1
- iup/default_config.py +0 -21
- iup-0.3.dist-info/RECORD +0 -9
- {iup-0.3.dist-info → iup-0.4.dist-info}/entry_points.txt +0 -0
- {iup-0.3.dist-info → iup-0.4.dist-info}/top_level.txt +0 -0
iup/main.py
CHANGED
|
@@ -17,10 +17,10 @@ MAGIC_STR = "update rule to"
|
|
|
17
17
|
MAGIC_STR2 = "update blk"
|
|
18
18
|
|
|
19
19
|
def is_domain_name(string: str):
|
|
20
|
-
if
|
|
21
|
-
return True
|
|
22
|
-
else:
|
|
20
|
+
if not string:
|
|
23
21
|
return False
|
|
22
|
+
s = string.strip().lower()
|
|
23
|
+
return re.fullmatch(HOSTNAME_PATTERN, s) is not None
|
|
24
24
|
|
|
25
25
|
def is_ip_address(ip_str: str):
|
|
26
26
|
try:
|
|
@@ -29,9 +29,45 @@ def is_ip_address(ip_str: str):
|
|
|
29
29
|
except ValueError:
|
|
30
30
|
return False
|
|
31
31
|
|
|
32
|
+
|
|
32
33
|
def parse_host_name(hostname_str: str):
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
"""Normalize input and return domain name only (no scheme, no port).
|
|
35
|
+
|
|
36
|
+
Accepts inputs like:
|
|
37
|
+
- a.com:443
|
|
38
|
+
- https://a.com
|
|
39
|
+
- http//:a.com:443
|
|
40
|
+
|
|
41
|
+
Returns domain (e.g. 'a.com') or None. IP addresses are rejected.
|
|
42
|
+
"""
|
|
43
|
+
if not hostname_str:
|
|
44
|
+
return None
|
|
45
|
+
s = hostname_str.strip()
|
|
46
|
+
# detect and strip scheme (require '://', e.g. http:// or https://)
|
|
47
|
+
# this prevents malformed inputs like 'http:a.com:443' being treated as scheme
|
|
48
|
+
m = re.match(r'^([a-zA-Z][a-zA-Z0-9+\-]*)://', s)
|
|
49
|
+
has_scheme = bool(m)
|
|
50
|
+
if m:
|
|
51
|
+
s = s[m.end():]
|
|
52
|
+
# remove credentials if present (user:pass@host)
|
|
53
|
+
if '@' in s:
|
|
54
|
+
s = s.split('@')[-1]
|
|
55
|
+
# if there was a scheme, remove path part
|
|
56
|
+
if has_scheme and '/' in s:
|
|
57
|
+
s = s.split('/')[0]
|
|
58
|
+
# now s should be host[:port]
|
|
59
|
+
host_port = s.strip()
|
|
60
|
+
# strip port if present (last :digits)
|
|
61
|
+
if ':' in host_port:
|
|
62
|
+
parts = host_port.rsplit(':', 1)
|
|
63
|
+
if parts[1].isdigit():
|
|
64
|
+
host_port = parts[0]
|
|
65
|
+
host = host_port.strip().lower()
|
|
66
|
+
# reject pure IPs
|
|
67
|
+
if is_ip_address(host):
|
|
68
|
+
return None
|
|
69
|
+
if is_domain_name(host):
|
|
70
|
+
return host
|
|
35
71
|
return None
|
|
36
72
|
|
|
37
73
|
def parse_port(port: str):
|
|
@@ -56,8 +92,9 @@ def read_hostname_from_file(path: str):
|
|
|
56
92
|
with open(path, 'r') as f:
|
|
57
93
|
for line in f:
|
|
58
94
|
host_name_str = line.strip()
|
|
59
|
-
|
|
60
|
-
|
|
95
|
+
parsed = parse_host_name(host_name_str)
|
|
96
|
+
if parsed:
|
|
97
|
+
hostnames.append(parsed)
|
|
61
98
|
hostnames = list(dict.fromkeys(hostnames))
|
|
62
99
|
return hostnames
|
|
63
100
|
|
|
@@ -119,8 +156,9 @@ def gen_hostnames_by_sources(sources):
|
|
|
119
156
|
hostnames = []
|
|
120
157
|
for source in sources:
|
|
121
158
|
if not path.exists(source):
|
|
122
|
-
|
|
123
|
-
|
|
159
|
+
parsed = parse_host_name(source)
|
|
160
|
+
if parsed:
|
|
161
|
+
hostnames.append(parsed)
|
|
124
162
|
elif path.isfile(source):
|
|
125
163
|
hostnames += read_hostname_from_file(source)
|
|
126
164
|
return list(dict.fromkeys(hostnames))
|
iup-0.4.dist-info/RECORD
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
iup/__init__.py,sha256=WXPOI9BwESIVzJ-XhG7bIFhsRg98u_v5gp16nY0bcbI,108
|
|
2
|
+
iup/config.py,sha256=Ecg9m83D_Cp_inYrltt--oPcupVvCw9oo8m5ukKyWLA,2862
|
|
3
|
+
iup/main.py,sha256=zp5hwKjakNMbv1ITwlSJuukrtN5kqjAq-jyMegdzMl0,6671
|
|
4
|
+
iup-0.4.dist-info/METADATA,sha256=mPaJ2h7F5i2W-XFXIh6IV3AohZ1gUmyY1ugi_RP0Sho,204
|
|
5
|
+
iup-0.4.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
|
|
6
|
+
iup-0.4.dist-info/entry_points.txt,sha256=ER1eUBmB6bXwudHBT51NoOtDSlnUgBi4T6J9_kA4pwc,68
|
|
7
|
+
iup-0.4.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
|
|
8
|
+
iup-0.4.dist-info/RECORD,,
|
iup/default_config.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
|
-
from configparser import ConfigParser
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
DEFAULT_CONFIG = '''[common]
|
|
8
|
-
host = 192.168.1.1
|
|
9
|
-
port = 22
|
|
10
|
-
username = root
|
|
11
|
-
password = 123457
|
|
12
|
-
refresh = False'''
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def write_default_config(path):
|
|
16
|
-
with open(path, 'w', encoding='utf-8') as f:
|
|
17
|
-
f.write(DEFAULT_CONFIG)
|
|
18
|
-
|
|
19
|
-
def write_config(config: ConfigParser, path):
|
|
20
|
-
with open(path, 'w', encoding='utf-8') as f:
|
|
21
|
-
config.write(f)
|
iup-0.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
iup/__init__.py,sha256=WXPOI9BwESIVzJ-XhG7bIFhsRg98u_v5gp16nY0bcbI,108
|
|
2
|
-
iup/config.py,sha256=Ecg9m83D_Cp_inYrltt--oPcupVvCw9oo8m5ukKyWLA,2862
|
|
3
|
-
iup/default_config.py,sha256=JsNdlf_Imsa8KYlrI7A38fgBCDvn9zTZMotMK2kd0CQ,433
|
|
4
|
-
iup/main.py,sha256=j7-6cFrI6_RFkWR-Y4_LChs3fBVb1JGKQ8aW_w_9kMk,5508
|
|
5
|
-
iup-0.3.dist-info/METADATA,sha256=C50LOOcCcyhAeTMUSei_oImuxkL2h5yCvz2jLV2ScSs,204
|
|
6
|
-
iup-0.3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
7
|
-
iup-0.3.dist-info/entry_points.txt,sha256=ER1eUBmB6bXwudHBT51NoOtDSlnUgBi4T6J9_kA4pwc,68
|
|
8
|
-
iup-0.3.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
|
|
9
|
-
iup-0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|