add basic migration support
This commit is contained in:
parent
191214dbd6
commit
b906abe2b1
3 changed files with 41 additions and 1 deletions
18
utils.py
18
utils.py
|
|
@ -1,7 +1,25 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import anyio
|
||||
import contextlib
|
||||
from functools import wraps
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def as_corofunc(f):
|
||||
@wraps(f)
|
||||
async def wrapped(*args, **kwargs):
|
||||
# can't decide if i want an `anyio.sleep(0)` here.
|
||||
return f(*args, **kwargs)
|
||||
return wrapped
|
||||
|
||||
def as_async_cm(cls):
|
||||
@wraps(cls, updated=()) # cls.__dict__ doesn't support .update()
|
||||
class wrapped(cls, contextlib.AbstractAsyncContextManager):
|
||||
__aenter__ = as_corofunc(cls.__enter__)
|
||||
__aexit__ = as_corofunc(cls.__exit__)
|
||||
return wrapped
|
||||
|
||||
suppress = as_async_cm(contextlib.suppress)
|
||||
|
||||
def shield(f):
|
||||
@wraps(f)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue