iup 0.3__py3-none-any.whl → 0.5__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 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 re.match(HOSTNAME_PATTERN, string):
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
- if is_domain_name(hostname_str) or is_ip_address(hostname_str):
34
- return hostname_str
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
- if is_domain_name(host_name_str):
60
- hostnames.append(host_name_str)
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
- if is_domain_name(source):
123
- hostnames.append(source)
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))
@@ -130,6 +168,7 @@ def main():
130
168
  print('sources:', sources)
131
169
  hostnames = gen_hostnames_by_sources(sources)
132
170
  if hostnames:
171
+ print('待更新的域名列表:', hostnames)
133
172
  update_rule_by_ssh(hostnames, config)
134
173
  else:
135
174
  print('没有读取到有效域名,请检查!!!')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iup
3
- Version: 0.3
3
+ Version: 0.5
4
4
  Summary: ipset updater for openwrt
5
5
  Author: nobitaqaq
6
6
  Author-email: xiaoleigs@gmail.com
@@ -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=fOOFYgsA1Cfhd2dTP3PeRS3CmaQrnctKXwiQ8bwSWaY,6725
4
+ iup-0.5.dist-info/METADATA,sha256=yjkpaZI7amD6Kkz_HNbXqeJwguhmk9aFXuqlsSppQ_Y,204
5
+ iup-0.5.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
6
+ iup-0.5.dist-info/entry_points.txt,sha256=ER1eUBmB6bXwudHBT51NoOtDSlnUgBi4T6J9_kA4pwc,68
7
+ iup-0.5.dist-info/top_level.txt,sha256=abec3YOzJRti4IxzOLIn-uDOPTtYUE-Uv65cAv1v8JY,4
8
+ iup-0.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: setuptools (75.3.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
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