This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from lendingblock/master
1.3.0
- Loading branch information
Showing
28 changed files
with
577 additions
and
387 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
"RedirectOutput" | ||
], | ||
"args": [ | ||
"tests/data/test_validator.py" | ||
"tests/test_db_cli.py" | ||
] | ||
} | ||
] | ||
|
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,3 @@ | ||
"""Minimal OpenAPI asynchronous server application""" | ||
|
||
__version__ = '1.2.5' | ||
__version__ = '1.3.0' |
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,51 @@ | ||
from functools import wraps | ||
|
||
|
||
def asynccontextmanager(func): | ||
@wraps(func) | ||
def helper(*args, **kwds): | ||
return _AsyncGeneratorContextManager(func, args, kwds) | ||
return helper | ||
|
||
|
||
class _AsyncGeneratorContextManager: | ||
def __init__(self, func, args, kwds): | ||
self.gen = func(*args, **kwds) | ||
self.func, self.args, self.kwds = func, args, kwds | ||
doc = getattr(func, "__doc__", None) | ||
if doc is None: | ||
doc = type(self).__doc__ | ||
self.__doc__ = doc | ||
|
||
async def __aenter__(self): | ||
try: | ||
return await self.gen.__anext__() | ||
except StopAsyncIteration: | ||
raise RuntimeError("generator didn't yield") from None | ||
|
||
async def __aexit__(self, typ, value, traceback): | ||
if typ is None: | ||
try: | ||
await self.gen.__anext__() | ||
except StopAsyncIteration: | ||
return | ||
else: | ||
raise RuntimeError("generator didn't stop") | ||
else: | ||
if value is None: | ||
value = typ() | ||
try: | ||
await self.gen.athrow(typ, value, traceback) | ||
raise RuntimeError("generator didn't stop after throw()") | ||
except StopAsyncIteration as exc: | ||
return exc is not value | ||
except RuntimeError as exc: | ||
if exc is value: | ||
return False | ||
if isinstance(value, (StopIteration, StopAsyncIteration)): | ||
if exc.__cause__ is value: | ||
return False | ||
raise | ||
except BaseException as exc: | ||
if exc is not value: | ||
raise |
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,13 +1,34 @@ | ||
import os | ||
|
||
from aiohttp.web import Application | ||
|
||
from .commands import db | ||
from ..db.dbmodel import CrudDB | ||
|
||
|
||
def setup_app(app): | ||
store = os.environ.get('DATASTORE') | ||
if not store: | ||
app.logger.warning('DATASTORE not available') | ||
def get_db( | ||
app: Application, | ||
store_url: str = None, | ||
command: bool = True) -> CrudDB: | ||
"""Create an Open API db handler | ||
This function | ||
* add the database to the aiohttp application | ||
* add the db command to the command line client (if command is True) | ||
* add the close handler on shutdown | ||
It returns the database object | ||
""" | ||
store_url = store_url or os.environ.get('DATASTORE') | ||
if not store_url: # pragma: no cover | ||
app.logger.warning('DATASTORE url not available') | ||
else: | ||
app['db'] = CrudDB(store) | ||
app['cli'].add_command(db) | ||
app['db'] = CrudDB(store_url) | ||
app.on_shutdown.append(close_db) | ||
if command: | ||
app['cli'].add_command(db) | ||
return app['db'] | ||
|
||
|
||
async def close_db(app): | ||
await app['db'].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
Oops, something went wrong.