Skip to content

Commit 64842aa

Browse files
committed
Remove dependency on unmaintained URI library
1 parent 7d20497 commit 64842aa

File tree

3 files changed

+52
-245
lines changed

3 files changed

+52
-245
lines changed

adbproxy/util.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import random
33
import string
44

5-
import uri
5+
from urllib.parse import urlparse
66

77

88
async def check_call(program, *args, **kwargs):
@@ -13,12 +13,12 @@ async def check_call(program, *args, **kwargs):
1313

1414

1515
def sock_addr(addr):
16-
parsed = uri.URI("//" + addr + "/")
16+
parsed = urlparse("//" + addr + "/")
1717
return parsed.hostname, parsed.port
1818

1919

2020
def ssh_addr(config):
21-
parsed = uri.URI("//" + config + "/")
21+
parsed = urlparse("//" + config + "/")
2222
ret = {
2323
"known_hosts": None,
2424
}
@@ -38,19 +38,21 @@ def hostport(sockaddr):
3838

3939

4040
def ssh_uri(sockaddr, hide_pwd: bool = True):
41-
if sockaddr.get("password") is None:
42-
password = None
43-
elif hide_pwd:
44-
password = "***"
45-
else:
46-
password = sockaddr.get("password")
47-
48-
return uri.URI(
49-
username=sockaddr.get("username"),
50-
password=password,
51-
hostname=sockaddr.get("host"),
52-
port=sockaddr.get("port"),
53-
).uri[2:-1]
41+
ret = ""
42+
if sockaddr.get("username") is not None:
43+
ret += sockaddr.get("username")
44+
if sockaddr.get("password") is not None:
45+
ret += ":" + ("***" if hide_pwd else sockaddr.get("password"))
46+
47+
if ret:
48+
ret += "@"
49+
50+
ret += sockaddr.get("host")
51+
52+
if sockaddr.get("port") is not None:
53+
ret += f":{sockaddr.get("port")}"
54+
55+
return ret
5456

5557

5658
def random_str(size=6, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):

0 commit comments

Comments
 (0)