pleroma-ebooks/utils.py

19 lines
417 B
Python
Raw Normal View History

# SPDX-License-Identifier: AGPL-3.0-only
import anyio
2021-07-25 23:29:20 -07:00
from functools import wraps
def shield(f):
2021-07-25 23:29:20 -07:00
@wraps(f)
async def shielded(*args, **kwargs):
2021-07-25 23:29:20 -07:00
with anyio.CancelScope(shield=True):
return await f(*args, **kwargs)
return shielded
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