-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from collections.abc import Iterator | ||
|
||
from litestar.types import AnyCallable | ||
from typing_extensions import TypeVar | ||
|
||
|
||
T = TypeVar("T", bound=AnyCallable) | ||
|
||
|
||
class Router: | ||
"""A helper class to collect handlers""" | ||
|
||
def __init__(self) -> None: | ||
self.__handler: list[AnyCallable] = [] | ||
|
||
def __call__(self, fn: T) -> T: | ||
self.__handler.append(fn) | ||
return fn | ||
|
||
def __iter__(self) -> Iterator[AnyCallable]: | ||
yield from self.__handler |