From 801f344c506ccce20fb0e8d84fac164d7379b79b Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 22 Oct 2024 18:06:43 -0700 Subject: [PATCH 1/2] Use an unofficial setup-python action that still works with 2.7 Signed-off-by: Anders Kaseorg --- .github/workflows/tests-and-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-and-lint.yml b/.github/workflows/tests-and-lint.yml index 3095c95..b513035 100644 --- a/.github/workflows/tests-and-lint.yml +++ b/.github/workflows/tests-and-lint.yml @@ -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-action@v2024.919.163656 with: python-version: ${{ matrix.python-version }} - name: Install Dependencies From 3d44035396e514b70d478bb85d522e478ce5a2a7 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 22 Oct 2024 16:33:44 -0700 Subject: [PATCH 2/2] Avoid urllib.parse.splitport DeprecationWarning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “DeprecationWarning: urllib.parse.splitport() is deprecated as of 3.8, use urllib.parse.urlparse() instead” Signed-off-by: Anders Kaseorg --- bmemcached/protocol.py | 14 ++++---------- test/test_server_parsing.py | 5 ++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/bmemcached/protocol.py b/bmemcached/protocol.py index e45e010..1037888 100644 --- a/bmemcached/protocol.py +++ b/bmemcached/protocol.py @@ -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 @@ -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): """ diff --git a/test/test_server_parsing.py b/test/test_server_parsing.py index a384395..a750562 100644 --- a/test/test_server_parsing.py +++ b/test/test_server_parsing.py @@ -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']))