extra refactoring
This commit is contained in:
14 files changed
+943
-1230
No files matched your search
@@ -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()
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user