Skip to content

Commit be0a7d1

Browse files
authored
Merge pull request #257 from andersk/splitport
Avoid `urllib.parse.splitport` DeprecationWarning
2 parents ab1b460 + 3d44035 commit be0a7d1

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

.github/workflows/tests-and-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
20+
uses: LizardByte/setup-python[email protected]
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323
- name: Install Dependencies

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
"""

test/test_server_parsing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ def testNoPortGiven(self):
2727
self.assertEqual(server.port, 11211)
2828

2929
def testInvalidPort(self):
30-
server = bmemcached.protocol.Protocol('{}:blah'.format(os.environ['MEMCACHED_HOST']))
31-
self.assertEqual(server.host, os.environ['MEMCACHED_HOST'])
32-
self.assertEqual(server.port, 11211)
30+
with self.assertRaises(ValueError):
31+
bmemcached.protocol.Protocol('{}:blah'.format(os.environ['MEMCACHED_HOST']))
3332

3433
def testNonStandardPort(self):
3534
server = bmemcached.protocol.Protocol('{}:5000'.format(os.environ['MEMCACHED_HOST']))

0 commit comments

Comments
 (0)