-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow creation outside loop * Add Quart * Make pretty * pyproject additions * Add checks for when framework not installed * Simplify exception * Make pretty
- Loading branch information
Showing
11 changed files
with
197 additions
and
18 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from .quart_extension import QuartMayimExtension | ||
from .sanic_extension import SanicMayimExtension | ||
|
||
__all__ = ("SanicMayimExtension",) | ||
__all__ = ( | ||
"QuartMayimExtension", | ||
"SanicMayimExtension", | ||
) |
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,57 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional, Sequence, Type, Union | ||
|
||
from mayim import Executor, Hydrator, Mayim | ||
from mayim.exception import MayimError | ||
from mayim.interface.base import BaseInterface | ||
from mayim.registry import InterfaceRegistry, Registry | ||
|
||
try: | ||
from quart import Quart | ||
|
||
QUART_INSTALLED = True | ||
except ModuleNotFoundError: | ||
QUART_INSTALLED = False | ||
Quart = type("Quart", (), {}) # type: ignore | ||
|
||
|
||
class QuartMayimExtension: | ||
name = "mayim" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
executors: Optional[Sequence[Union[Type[Executor], Executor]]] = None, | ||
dsn: str = "", | ||
hydrator: Optional[Hydrator] = None, | ||
pool: Optional[BaseInterface] = None, | ||
app: Optional[Quart] = None, | ||
): | ||
if not QUART_INSTALLED: | ||
raise MayimError( | ||
"Could not locate Quart. It must be installed to use " | ||
"QuartMayimExtension. Try: pip install quart" | ||
) | ||
self.executors = executors or [] | ||
for executor in self.executors: | ||
Registry().register(executor) | ||
self.mayim_kwargs = { | ||
"dsn": dsn, | ||
"hydrator": hydrator, | ||
"pool": pool, | ||
} | ||
if app is not None: | ||
self.init_app(app) | ||
|
||
def init_app(self, app: Quart) -> None: | ||
@app.while_serving | ||
async def lifespan(): | ||
Mayim(executors=self.executors, **self.mayim_kwargs) | ||
for interface in InterfaceRegistry(): | ||
await interface.open() | ||
|
||
yield | ||
|
||
for interface in InterfaceRegistry(): | ||
await interface.close() |
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