Skip to content

Commit

Permalink
Merge branch 'main' into msgspec-13
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin authored Nov 18, 2024
2 parents c4a050e + 7e56814 commit 2e66994
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,16 @@
"contributions": [
"doc"
]
},
{
"login": "olzhasar",
"name": "Olzhas Arystanov",
"avatar_url": "https://avatars.githubusercontent.com/u/12471703?v=4",
"profile": "https://olzhasar.com",
"contributions": [
"bug",
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ see [the contribution guide](CONTRIBUTING.rst).
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mohammedbabelly20"><img src="https://avatars.githubusercontent.com/u/104768048?v=4?s=100" width="100px;" alt="Mohammed Babelly"/><br /><sub><b>Mohammed Babelly</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=mohammedbabelly20" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://keybase.io/charlesdyfisnet"><img src="https://avatars.githubusercontent.com/u/22370?v=4?s=100" width="100px;" alt="Charles Duffy"/><br /><sub><b>Charles Duffy</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=charles-dyfis-net" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RenameMe1"><img src="https://avatars.githubusercontent.com/u/165988121?v=4?s=100" width="100px;" alt="Evgeny Demchenko"/><br /><sub><b>Evgeny Demchenko</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=RenameMe1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://olzhasar.com"><img src="https://avatars.githubusercontent.com/u/12471703?v=4?s=100" width="100px;" alt="Olzhas Arystanov"/><br /><sub><b>Olzhas Arystanov</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/issues?q=author%3Aolzhasar" title="Bug reports">🐛</a> <a href="https://github.com/litestar-org/litestar/commits?author=olzhasar" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
21 changes: 15 additions & 6 deletions litestar/handlers/websocket_handlers/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ class WebsocketListener(ABC):
"""A sequence of :class:`Guard <.types.Guard>` callables."""
middleware: list[Middleware] | None = None
"""A sequence of :class:`Middleware <.types.Middleware>`."""
on_accept: AnyCallable | None = None
"""Called after a :class:`WebSocket <.connection.WebSocket>` connection has been accepted. Can receive any dependencies"""
on_disconnect: AnyCallable | None = None
"""Called after a :class:`WebSocket <.connection.WebSocket>` connection has been disconnected. Can receive any dependencies"""
receive_mode: WebSocketMode = "text"
""":class:`WebSocket <.connection.WebSocket>` mode to receive data in, either ``text`` or ``binary``."""
send_mode: WebSocketMode = "text"
Expand Down Expand Up @@ -380,6 +376,9 @@ def __init__(self, owner: Router) -> None:
self._owner = owner

def to_handler(self) -> WebsocketListenerRouteHandler:
on_accept = self.on_accept if self.on_accept != WebsocketListener.on_accept else None
on_disconnect = self.on_disconnect if self.on_disconnect != WebsocketListener.on_disconnect else None

handler = WebsocketListenerRouteHandler(
dependencies=self.dependencies,
dto=self.dto,
Expand All @@ -389,8 +388,8 @@ def to_handler(self) -> WebsocketListenerRouteHandler:
send_mode=self.send_mode,
receive_mode=self.receive_mode,
name=self.name,
on_accept=self.on_accept,
on_disconnect=self.on_disconnect,
on_accept=on_accept,
on_disconnect=on_disconnect,
opt=self.opt,
path=self.path,
return_dto=self.return_dto,
Expand All @@ -402,6 +401,16 @@ def to_handler(self) -> WebsocketListenerRouteHandler:
handler.owner = self._owner
return handler

def on_accept(self, *args: Any, **kwargs: Any) -> Any:
"""Called after a :class:`WebSocket <.connection.WebSocket>` connection
has been accepted. Can receive any dependencies
"""

def on_disconnect(self, *args: Any, **kwargs: Any) -> Any:
"""Called after a :class:`WebSocket <.connection.WebSocket>` connection
has been disconnected. Can receive any dependencies
"""

@abstractmethod
def on_receive(self, *args: Any, **kwargs: Any) -> Any:
"""Called after data has been received from the WebSocket.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ known-first-party = ["litestar", "tests", "examples"]
"litestar/_openapi/schema_generation/schema.py" = ["C901"]
"litestar/exceptions/*.*" = ["N818"]
"litestar/handlers/**/*.*" = ["N801"]
"litestar/handlers/websocket_handlers/listener.py" = ["B027"]
"litestar/params.py" = ["N802"]
"test_apps/**/*.*" = ["D", "TRY", "EM", "S", "PTH"]
"tests/**/*.*" = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def some_dependency() -> str:
class Listener(WebsocketListener):
path = "/{name: str}"

def on_accept(self, name: str, state: State, query: dict, some: str) -> None: # type: ignore[override]
def on_accept(self, name: str, state: State, query: dict, some: str) -> None: # pyright: ignore
on_accept_mock(name=name, state=state, query=query, some=some)

def on_disconnect(self, name: str, state: State, query: dict, some: str) -> None: # type: ignore[override]
def on_disconnect(self, name: str, state: State, query: dict, some: str) -> None: # pyright: ignore
on_disconnect_mock(name=name, state=state, query=query, some=some)

def on_receive(self, data: bytes) -> None: # pyright: ignore
Expand Down

0 comments on commit 2e66994

Please sign in to comment.