Skip to content

Commit

Permalink
Avoid urllib.parse.splitport DeprecationWarning
Browse files Browse the repository at this point in the history
“DeprecationWarning: urllib.parse.splitport() is deprecated as of 3.8,
use urllib.parse.urlparse() instead”

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Oct 23, 2024
1 parent 801f344 commit a80eb45
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions bmemcached/protocol.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from datetime import datetime, timedelta
import logging
import re
import socket
import struct
import threading
try:
from urllib import splitport # type: ignore
from urlparse import SplitResult # type: ignore[import-not-found]
except ImportError:
from urllib.parse import splitport # type: ignore
from urllib.parse import SplitResult # type: ignore[import-not-found]

import zlib
from io import BytesIO
Expand Down Expand Up @@ -180,13 +179,8 @@ def split_host_port(cls, server):
>>> split_host_port('127.0.0.1')
('127.0.0.1', 11211)
"""
host, port = splitport(server)
if port is None:
port = 11211
port = int(port)
if re.search(':.*$', host):
host = re.sub(':.*$', '', host)
return host, port
u = SplitResult("", server, "", "", "")
return u.hostname, 11211 if u.port is None else u.port

def _read_socket(self, size):
"""
Expand Down

0 comments on commit a80eb45

Please sign in to comment.