diff options
Diffstat (limited to 'dev-python/simple-websocket')
4 files changed, 427 insertions, 0 deletions
diff --git a/dev-python/simple-websocket/Manifest b/dev-python/simple-websocket/Manifest new file mode 100644 index 000000000000..b68f6dffce36 --- /dev/null +++ b/dev-python/simple-websocket/Manifest @@ -0,0 +1 @@ +DIST simple-websocket-1.1.0.gh.tar.gz 19589 BLAKE2B 293fa26af7ea929b4b2acdfe8e63598ac171a6b628f6a72aa1694c880b3db48b20fc7b76854e17cf1896e29a95982fba54c47a6baad3589ffa85d1fe93d6be6f SHA512 89c2c580902af77e8708bf2ae5c40358f3f9fe3052ee58d42bc518a68042c8b0bda1ad0cf3e304b67189590e75ee1bfe085d12f9d18755c443731c0884b1cb92 diff --git a/dev-python/simple-websocket/files/simple-websocket-1.1.0-py314.patch b/dev-python/simple-websocket/files/simple-websocket-1.1.0-py314.patch new file mode 100644 index 000000000000..c20584d98c79 --- /dev/null +++ b/dev-python/simple-websocket/files/simple-websocket-1.1.0-py314.patch @@ -0,0 +1,372 @@ +diff --git a/tests/test_aioclient.py b/tests/test_aioclient.py +index 01a772a..5ec12ff 100644 +--- a/tests/test_aioclient.py ++++ b/tests/test_aioclient.py +@@ -1,15 +1,14 @@ + import asyncio +-import unittest + from unittest import mock + import pytest # noqa: F401 + + from wsproto.events import AcceptConnection, CloseConnection, TextMessage, \ + BytesMessage, Ping + import simple_websocket +-from .helpers import make_sync, AsyncMock + + +-class AioSimpleWebSocketClientTestCase(unittest.TestCase): ++@pytest.mark.asyncio ++class TestAioSimpleWebSocketClient: + async def get_client(self, mock_wsconn, url, events=[], subprotocols=None, + headers=None): + mock_wsconn().events.side_effect = \ +@@ -19,11 +18,10 @@ async def get_client(self, mock_wsconn, url, events=[], subprotocols=None, + return await simple_websocket.AioClient.connect( + url, subprotocols=subprotocols, headers=headers) + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_make_client(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client(mock_wsconn, 'ws://example.com/ws?a=1') +@@ -40,12 +38,11 @@ async def test_make_client(self, mock_wsconn, mock_open_connection): + assert client.port == 80 + assert client.path == '/ws?a=1' + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_make_client_subprotocol(self, mock_wsconn, + mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client(mock_wsconn, 'ws://example.com/ws?a=1', +@@ -55,12 +52,11 @@ async def test_make_client_subprotocol(self, mock_wsconn, + b"Request(host='example.com', target='/ws?a=1', extensions=[], " + b"extra_headers=[], subprotocols=['foo'])") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_make_client_subprotocols(self, mock_wsconn, + mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client(mock_wsconn, 'ws://example.com/ws?a=1', +@@ -70,12 +66,11 @@ async def test_make_client_subprotocols(self, mock_wsconn, + b"Request(host='example.com', target='/ws?a=1', extensions=[], " + b"extra_headers=[], subprotocols=['foo', 'bar'])") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_make_client_headers(self, mock_wsconn, + mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client(mock_wsconn, 'ws://example.com/ws?a=1', +@@ -84,12 +79,11 @@ async def test_make_client_headers(self, mock_wsconn, + b"Request(host='example.com', target='/ws?a=1', extensions=[], " + b"extra_headers=[('Foo', 'Bar')], subprotocols=[])") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_make_client_headers2(self, mock_wsconn, + mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client( +@@ -100,11 +94,10 @@ async def test_make_client_headers2(self, mock_wsconn, + b"extra_headers=[('Foo', 'Bar'), ('Foo', 'Baz')], " + b"subprotocols=[])") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_send(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client(mock_wsconn, 'ws://example.com/ws') +@@ -123,11 +116,10 @@ async def test_send(self, mock_wsconn, mock_open_connection): + b"Message(data=b'hello', frame_finished=True, " + b"message_finished=True)") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client( +@@ -142,12 +134,11 @@ async def test_receive(self, mock_wsconn, mock_open_connection): + assert await client.receive() == b'hello' + assert await client.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_after_close(self, mock_wsconn, + mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client( +@@ -160,11 +151,10 @@ async def test_receive_after_close(self, mock_wsconn, + with pytest.raises(simple_websocket.ConnectionClosed): + await client.receive() + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_ping(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) +@@ -176,11 +166,11 @@ async def test_receive_ping(self, mock_wsconn, mock_open_connection): + await asyncio.sleep(0.01) + wsock.write.assert_any_call(b"Pong(payload=b'hello')") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_empty(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(side_effect=[b'x', b'x', b''])) ++ rsock = mock.MagicMock(read=mock.AsyncMock( ++ side_effect=[b'x', b'x', b''])) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client( +@@ -193,11 +183,10 @@ async def test_receive_empty(self, mock_wsconn, mock_open_connection): + assert await client.receive() == 'hello' + assert await client.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_close(self, mock_wsconn, mock_open_connection): +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + client = await self.get_client( +diff --git a/tests/test_aioserver.py b/tests/test_aioserver.py +index a274019..071e035 100644 +--- a/tests/test_aioserver.py ++++ b/tests/test_aioserver.py +@@ -1,15 +1,14 @@ + import asyncio +-import unittest + from unittest import mock + import pytest # noqa: F401 + + from wsproto.events import Request, CloseConnection, TextMessage, \ + BytesMessage, Ping, Pong + import simple_websocket +-from .helpers import make_sync, AsyncMock + + +-class AioSimpleWebSocketServerTestCase(unittest.TestCase): ++@pytest.mark.asyncio ++class TestAioSimpleWebSocketServer: + async def get_server(self, mock_wsconn, request, events=[], + client_subprotocols=None, server_subprotocols=None, + **kwargs): +@@ -29,12 +28,11 @@ async def get_server(self, mock_wsconn, request, events=[], + return await simple_websocket.AioServer.accept( + aiohttp=request, subprotocols=server_subprotocols, **kwargs) + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_aiohttp(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request) +@@ -53,19 +51,17 @@ async def test_aiohttp(self, mock_wsconn, mock_open_connection): + b'Sec-Websocket-Version: 13\r\n\r\n') + assert server.is_server + +- @make_sync + async def test_invalid_request(self): + with pytest.raises(ValueError): + await simple_websocket.AioServer.accept(aiohttp='foo', asgi='bar') + with pytest.raises(ValueError): + await simple_websocket.AioServer.accept(asgi='bar', sock='baz') + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_send(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request) +@@ -84,12 +80,11 @@ async def test_send(self, mock_wsconn, mock_open_connection): + b"Message(data=b'hello', frame_finished=True, " + b"message_finished=True)") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -103,13 +98,12 @@ async def test_receive(self, mock_wsconn, mock_open_connection): + assert await server.receive() == b'hello' + assert await server.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_after_close(self, mock_wsconn, + mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -121,13 +115,12 @@ async def test_receive_after_close(self, mock_wsconn, + with pytest.raises(simple_websocket.ConnectionClosed): + await server.receive() + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_split_messages(self, mock_wsconn, + mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -151,12 +144,11 @@ async def test_receive_split_messages(self, mock_wsconn, + assert await server.receive() == b'hello' + assert await server.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_ping(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -166,12 +158,11 @@ async def test_receive_ping(self, mock_wsconn, mock_open_connection): + await asyncio.sleep(0.01) + wsock.write.assert_any_call(b"Pong(payload=b'hello')") + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_empty(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -183,12 +174,11 @@ async def test_receive_empty(self, mock_wsconn, mock_open_connection): + assert await server.receive() == 'hello' + assert await server.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_receive_large(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -201,12 +191,11 @@ async def test_receive_large(self, mock_wsconn, mock_open_connection): + assert await server.receive() == 'hello' + assert await server.receive(timeout=0) is None + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_close(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request) +@@ -222,7 +211,6 @@ async def test_close(self, mock_wsconn, mock_open_connection): + b'CloseConnection(code=<CloseReason.NORMAL_CLOSURE: 1000>, ' + b'reason=None)') + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + @mock.patch('simple_websocket.aiows.time') +@@ -230,7 +218,7 @@ async def test_close(self, mock_wsconn, mock_open_connection): + async def test_ping_pong(self, mock_wait_for, mock_time, mock_wsconn, + mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock()) ++ rsock = mock.MagicMock(read=mock.AsyncMock()) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + server = await self.get_server(mock_wsconn, mock_request, events=[ +@@ -246,12 +234,11 @@ async def test_ping_pong(self, mock_wait_for, mock_time, mock_wsconn, + assert wsock.write.call_args_list[2][0][0].startswith(b'Ping') + assert wsock.write.call_args_list[3][0][0].startswith(b'Close') + +- @make_sync + @mock.patch('simple_websocket.aiows.asyncio.open_connection') + @mock.patch('simple_websocket.aiows.WSConnection') + async def test_subprotocols(self, mock_wsconn, mock_open_connection): + mock_request = mock.MagicMock(headers={}) +- rsock = mock.MagicMock(read=AsyncMock(return_value=b'x')) ++ rsock = mock.MagicMock(read=mock.AsyncMock(return_value=b'x')) + wsock = mock.MagicMock() + mock_open_connection.return_value = (rsock, wsock) + +diff --git a/tests/test_server.py b/tests/test_server.py +index 7be5d15..ca5fe99 100644 +--- a/tests/test_server.py ++++ b/tests/test_server.py +@@ -92,7 +92,7 @@ def test_send(self, mock_wsconn): + b"message_finished=True)") + server.connected = True + server.send(b'hello') +- mock_socket.send.assert_called_with( ++ mock_socket.send.assert_any_call( + b"Message(data=b'hello', frame_finished=True, " + b"message_finished=True)") + diff --git a/dev-python/simple-websocket/metadata.xml b/dev-python/simple-websocket/metadata.xml new file mode 100644 index 000000000000..d34971a915e9 --- /dev/null +++ b/dev-python/simple-websocket/metadata.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "https://docs.baldeagleos.com/dtd/metadata.dtd"> +<pkgmetadata> + <maintainer type="project"> + <email>python@gentoo.org</email> + </maintainer> + <stabilize-allarches /> + <origin>baldeagleos-repo</origin> +</pkgmetadata> diff --git a/dev-python/simple-websocket/simple-websocket-1.1.0.ebuild b/dev-python/simple-websocket/simple-websocket-1.1.0.ebuild new file mode 100644 index 000000000000..9a809eaaeee3 --- /dev/null +++ b/dev-python/simple-websocket/simple-websocket-1.1.0.ebuild @@ -0,0 +1,45 @@ +# Copyright 2023-2026 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_USE_PEP517=setuptools +PYTHON_COMPAT=( python3_{13..14} ) + +inherit distutils-r1 + +DESCRIPTION="Simple WebSocket server and client for Python" +HOMEPAGE=" + https://github.com/miguelgrinberg/simple-websocket/ + https://pypi.org/project/simple-websocket/ +" +# upstream refuses to provide working tests in sdist +# https://github.com/miguelgrinberg/simple-websocket/issues/31 +SRC_URI=" + https://github.com/miguelgrinberg/simple-websocket/archive/v${PV}.tar.gz + -> ${P}.gh.tar.gz +" + +LICENSE="MIT" +SLOT="0" +KEYWORDS="~amd64 ~arm64 ~x86" + +RDEPEND=" + dev-python/wsproto[${PYTHON_USEDEP}] +" + +src_prepare() { + local PATCHES=( + # https://github.com/miguelgrinberg/simple-websocket/pull/48 + "${FILESDIR}/${P}-py314.patch" + ) + + distutils-r1_src_prepare + + # fix tests to work offline + # https://github.com/miguelgrinberg/simple-websocket/commit/159e030c7c23060de989cebec6d98d776c75bcbd + sed -i -e 's:example\.com:localhost:g' tests/test_client.py || die +} + +EPYTEST_PLUGINS=( pytest-asyncio ) +distutils_enable_tests pytest |
