formatting

This commit is contained in:
FUFSoB committed 2026-04-19 12:11:01 +05:00
1 parent 744a769e73
commit 4d6802e194
21 files changed
+843 -582

No files matched your search

+24 -10
View File
@@ -12,6 +12,7 @@ BUILTIN_ACTIVATION_FALLBACKS = {
"list-twitter.txt": "general",
}
def _hostlist_remove_pattern(stem: str) -> str:
escaped = re.escape(stem)
return rf'\s+--hostlist=(?:"[^"]*/hostlists/{escaped}\.txt"|[^ ]*/hostlists/{escaped}\.txt)'
@@ -25,11 +26,11 @@ def _mk_family(match_stems: list[str], remove_stems: list[str]) -> dict:
FAMILY_PATTERNS = {
"general": _mk_family(["general", "general-user"], ["general", "general-user"]),
"google": _mk_family(["google"], ["google"]),
"instagram": _mk_family(["instagram"], ["instagram"]),
"general": _mk_family(["general", "general-user"], ["general", "general-user"]),
"google": _mk_family(["google"], ["google"]),
"instagram": _mk_family(["instagram"], ["instagram"]),
"soundcloud": _mk_family(["soundcloud"], ["soundcloud"]),
"twitter": _mk_family(["twitter"], ["twitter"]),
"twitter": _mk_family(["twitter"], ["twitter"]),
}
@@ -112,8 +113,13 @@ def clone_family_lines(
if any(marker in line for marker in FAMILY_PATTERNS[family]["match"])
]
if not matches:
raise ValueError(f"Preset family '{family}' is not present in the selected zapret config")
return [render_preset_clone(line, family, hostlist_path, standard_excludes) for line in matches]
raise ValueError(
f"Preset family '{family}' is not present in the selected zapret config"
)
return [
render_preset_clone(line, family, hostlist_path, standard_excludes)
for line in matches
]
def activate_builtin_hostlists(
@@ -139,8 +145,12 @@ def main() -> int:
parser = argparse.ArgumentParser(
description="Append proxy-suite custom hostlist rules to a zapret config."
)
parser.add_argument("--config", required=True, help="Path to the selected zapret config file")
parser.add_argument("--spec", required=True, help="JSON file describing custom hostlist rules")
parser.add_argument(
"--config", required=True, help="Path to the selected zapret config file"
)
parser.add_argument(
"--spec", required=True, help="JSON file describing custom hostlist rules"
)
args = parser.parse_args()
config_path = Path(args.config)
@@ -171,10 +181,14 @@ def main() -> int:
preset = entry.get("preset")
if preset:
generated_lines.extend(
clone_family_lines(nfqws_lines, preset, hostlist_path, standard_excludes)
clone_family_lines(
nfqws_lines, preset, hostlist_path, standard_excludes
)
)
for fragment in entry.get("nfqwsArgs", []):
generated_lines.append(render_custom_args(fragment, hostlist_path, standard_excludes))
generated_lines.append(
render_custom_args(fragment, hostlist_path, standard_excludes)
)
updated_lines = lines[:end] + generated_lines + lines[end:]
config_path.write_text("\n".join(updated_lines) + "\n", encoding="utf-8")
+3 -1
View File
@@ -62,7 +62,9 @@ def make_tag(prefix: str, remark: str, index: int) -> str:
return f"{prefix}-{index}"
def parse_subscription(lines: list[str], tag_prefix: str, routing_mark: int | None) -> list[dict]:
def parse_subscription(
lines: list[str], tag_prefix: str, routing_mark: int | None
) -> list[dict]:
outbounds = []
seen_tags: set[str] = set()
+11 -5
View File
@@ -10,7 +10,7 @@ def _qs(query: str) -> dict:
def _parse_url_parts(url: str, scheme: str) -> tuple[str, str, str, dict]:
rest = url[len(f"{scheme}://"):]
rest = url[len(f"{scheme}://") :]
rest, _, _ = rest.partition("#")
if "@" in rest:
userinfo, _, rest = rest.partition("@")
@@ -47,7 +47,9 @@ def _mk_transport(
return None
def _mk_tls(server_name: str, fp: "str | None" = None, alpn: "str | None" = None) -> dict:
def _mk_tls(
server_name: str, fp: "str | None" = None, alpn: "str | None" = None
) -> dict:
tls: dict = {"enabled": True, "server_name": server_name}
if fp:
tls["utls"] = {"enabled": True, "fingerprint": fp}
@@ -85,7 +87,9 @@ def parse_vless(url: str, tag: str) -> dict:
"short_id": params.get("sid", ""),
}
elif security == "tls":
ob["tls"] = _mk_tls(params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn"))
ob["tls"] = _mk_tls(
params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn")
)
tr = _mk_transport(
transport,
@@ -104,7 +108,7 @@ def parse_vless(url: str, tag: str) -> dict:
def parse_vmess(url: str, tag: str) -> dict:
b64 = url[len("vmess://"):]
b64 = url[len("vmess://") :]
pad = "=" * (-len(b64) % 4)
try:
data = json.loads(base64.b64decode(b64 + pad))
@@ -159,7 +163,9 @@ def parse_trojan(url: str, tag: str) -> dict:
"server": host,
"server_port": int(port),
"password": urllib.parse.unquote(userinfo),
"tls": _mk_tls(params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn")),
"tls": _mk_tls(
params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn")
),
}
tr = _mk_transport(
+5 -1
View File
@@ -46,7 +46,11 @@ class BuildOutboundTests(unittest.TestCase):
self.assertEqual(ob["tls"]["server_name"], "tls.example.com")
def test_shadowsocks(self):
credentials = base64.urlsafe_b64encode(b"chacha20-ietf-poly1305:passw0rd").decode().rstrip("=")
credentials = (
base64.urlsafe_b64encode(b"chacha20-ietf-poly1305:passw0rd")
.decode()
.rstrip("=")
)
ob = run_parser(f"ss://{credentials}@ss.example.com:8388")
self.assertEqual(ob["type"], "shadowsocks")
self.assertEqual(ob["method"], "chacha20-ietf-poly1305")