Skip to content

Commit 0b78ca0

Browse files
committed
Avoid urllib.parse.splitport DeprecationWarning
“DeprecationWarning: urllib.parse.splitport() is deprecated as of 3.8, use urllib.parse.urlparse() instead” Signed-off-by: Anders Kaseorg <[email protected]>
1 parent e2270aa commit 0b78ca0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

bmemcached/protocol.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from datetime import datetime, timedelta
22
import logging
3-
import re
43
import socket
54
import struct
65
import threading
76
try:
8-
from urllib import splitport # type: ignore
7+
from urlparse import SplitResult # type: ignore[import-not-found]
98
except ImportError:
10-
from urllib.parse import splitport # type: ignore
9+
from urllib.parse import SplitResult # type: ignore[import-not-found]
1110

1211
import zlib
1312
from io import BytesIO
@@ -180,13 +179,8 @@ def split_host_port(cls, server):
180179
>>> split_host_port('127.0.0.1')
181180
('127.0.0.1', 11211)
182181
"""
183-
host, port = splitport(server)
184-
if port is None:
185-
port = 11211
186-
port = int(port)
187-
if re.search(':.*$', host):
188-
host = re.sub(':.*$', '', host)
189-
return host, port
182+
u = SplitResult("", server, "", "", "")
183+
return u.hostname, 11211 if u.port is None else u.port
190184

191185
def _read_socket(self, size):
192186
"""

0 commit comments

Comments
 (0)