extra refactoring

This commit is contained in:
FUFSoB committed 2026-04-19 12:09:21 +05:00
1 parent 078367d919
commit 744a769e73
14 files changed
+943 -1230

No files matched your search

+6 -6
View File
@@ -8,16 +8,16 @@ import sys
from proxy_parsing import decode_subscription, fetch_raw, parse_subscription
# ---------------------------------------------------------------------------
# CLI
# ---------------------------------------------------------------------------
def main() -> None:
ap = argparse.ArgumentParser(
description="Fetch a proxy subscription URL from stdin and emit a sing-box outbound JSON array."
)
ap.add_argument("--tag-prefix", required=True, dest="tag_prefix",
help="Prefix for outbound tags, e.g. 'my-sub'.")
ap.add_argument(
"--tag-prefix",
required=True,
dest="tag_prefix",
help="Prefix for outbound tags, e.g. 'my-sub'.",
)
ap.add_argument("--routing-mark", type=int, default=None, dest="routing_mark")
args = ap.parse_args()
+1 -6
View File
@@ -175,12 +175,7 @@ def parse_trojan(url: str, tag: str) -> dict:
def parse_shadowsocks(url: str, tag: str) -> dict:
rest = url[len("ss://"):]
rest, _, _ = rest.partition("#")
userinfo, _, rest = rest.partition("@")
hostpart, _, _ = rest.partition("?")
host, _, port = hostpart.rpartition(":")
userinfo, host, port, _ = _parse_url_parts(url, "ss")
pad = "=" * (-len(userinfo) % 4)
try:
+4 -5
View File
@@ -17,15 +17,13 @@ def _make_b64_payload(*uris: str) -> bytes:
return base64.b64encode(text.encode())
def run_fetcher(server_data: bytes, tag_prefix: str = "test", *, routing_mark: int | None = None):
def run_fetcher(
server_data: bytes, tag_prefix: str = "test", *, routing_mark: int | None = None
):
lines = decode_subscription(server_data)
return parse_subscription(lines, tag_prefix, routing_mark)
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
class FetchSubscriptionTests(unittest.TestCase):
def test_base64_payload_mixed_protocols(self):
@@ -59,6 +57,7 @@ class FetchSubscriptionTests(unittest.TestCase):
tag = obs[0]["tag"]
# Tag must contain only safe characters
import re
self.assertRegex(tag, r"^[a-zA-Z0-9_/\-]+$")
def test_tag_deduplication(self):