feat: Rename the disconnect method of each SHSEndpoint to close

The two verbs have the same meaning in this context, and this unifies the two interfaces, which helps type checking in
code using this library.
This commit is contained in:
Gergely Polonkai 2023-11-13 06:29:06 +01:00
parent 1ad7cb4e5e
commit 83add95c8a
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 16 additions and 9 deletions

View File

@ -27,7 +27,7 @@ from typing import AsyncIterator, Awaitable, Callable, List, Optional
from nacl.public import PrivateKey
from nacl.signing import SigningKey
from typing_extensions import Self
from typing_extensions import Self, deprecated
from .boxstream import BoxStream, UnboxStream, get_stream_pair
from .crypto import SHSClientCrypto, SHSCryptoBase, SHSServerCrypto
@ -91,10 +91,16 @@ class SHSEndpoint:
self._on_connect = cb
def disconnect(self) -> None: # pragma: no cover
def close(self) -> None: # pragma: no cover
"""Disconnect the endpoint"""
raise NotImplementedError
raise NotImplementedError()
@deprecated("Use close instead")
def disconnect(self) -> None:
"""Disconnect the endpoint"""
self.close()
class SHSServer(SHSEndpoint):
@ -145,10 +151,14 @@ class SHSServer(SHSEndpoint):
await start_server(self.handle_connection, self.host, self.port)
def disconnect(self) -> None:
def close(self) -> None:
for connection in self.connections:
connection.close()
@deprecated("Use close instead")
def disconnect(self) -> None:
self.close()
class SHSServerConnection(SHSDuplexStream):
"""SHS server connection"""
@ -221,6 +231,3 @@ class SHSClient(SHSDuplexStream, SHSEndpoint):
if self._on_connect:
await self._on_connect(self)
def disconnect(self) -> None:
self.close()

View File

@ -145,7 +145,7 @@ async def test_client(mocker: MockerFixture) -> None:
await client.open()
reader.append(b"TEST")
assert (await client.read()) == b"TEST"
client.disconnect()
client.close()
@pytest.mark.asyncio
@ -155,7 +155,7 @@ async def test_server(mocker: MockerFixture) -> None:
resolve = Event()
async def _on_connect(_: Any) -> None:
server.disconnect()
server.close()
resolve.set()
_, _, _create_mock_server = _server_stream_mocker()