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:
parent
1ad7cb4e5e
commit
83add95c8a
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user