Skip to content

Commit

Permalink
Merge pull request #257 from andersk/splitport
Browse files Browse the repository at this point in the history
Avoid `urllib.parse.splitport` DeprecationWarning
  • Loading branch information
jaysonsantos authored Oct 23, 2024
2 parents ab1b460 + 3d44035 commit be0a7d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: LizardByte/setup-python[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
Expand Down
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
5 changes: 2 additions & 3 deletions test/test_server_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def testNoPortGiven(self):
self.assertEqual(server.port, 11211)

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

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

0 comments on commit be0a7d1

Please sign in to comment.