parse-ss-url.py
· 461 B · Python
Неформатований
def parse_url(url):
scheme, loc, path, query, frag = urlsplit(url)
if scheme != "ss":
return None
secret, addr = loc.split("@")
if ":" not in secret:
secret = base64.urlsafe_b64decode(secret).decode("ascii")
cipher, key = secret.split(":", 1)
else:
cipher, key = secret.split(":", 1)
key = unquote(key)
host, port = addr.split(":")
frag = unquote(frag)
return host, port, cipher, key, frag
| 1 | def parse_url(url): |
| 2 | scheme, loc, path, query, frag = urlsplit(url) |
| 3 | if scheme != "ss": |
| 4 | return None |
| 5 | secret, addr = loc.split("@") |
| 6 | if ":" not in secret: |
| 7 | secret = base64.urlsafe_b64decode(secret).decode("ascii") |
| 8 | cipher, key = secret.split(":", 1) |
| 9 | else: |
| 10 | cipher, key = secret.split(":", 1) |
| 11 | key = unquote(key) |
| 12 | host, port = addr.split(":") |
| 13 | frag = unquote(frag) |
| 14 | return host, port, cipher, key, frag |