2021-07-25 21:52:13 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import anyio
|
2021-07-25 23:29:20 -07:00
|
|
|
from functools import wraps
|
2021-07-25 21:52:13 -07:00
|
|
|
|
|
|
|
def shield(f):
|
2021-07-25 23:29:20 -07:00
|
|
|
@wraps(f)
|
2021-07-25 21:52:13 -07:00
|
|
|
async def shielded(*args, **kwargs):
|
2021-07-25 23:29:20 -07:00
|
|
|
with anyio.CancelScope(shield=True):
|
2021-07-25 21:52:13 -07:00
|
|
|
return await f(*args, **kwargs)
|
|
|
|
return shielded
|
2021-08-19 03:40:57 -07:00
|
|
|
|
|
|
|
def removeprefix(s, prefix):
|
|
|
|
try:
|
|
|
|
return s.removeprefix(prefix)
|
|
|
|
except AttributeError:
|
|
|
|
# compatibility for pre-3.9
|
|
|
|
return s[len(prefix):] if s.startswith(prefix) else s
|