fishyboteso/fishy/web/decorators.py
DESKTOP-JVKHS7I\Adam 5972aebc7d code cleanup:
- restructured code
- pep8 cleanup
- spelling mistakes fixed
- import fixes
- added cli arg to use local server
- got rid of globals.py
2020-05-14 07:33:13 +05:30

35 lines
747 B
Python

import logging
import traceback
import typing
from functools import wraps
if typing.TYPE_CHECKING:
from fishy.web.web import get_session
def uses_session(f):
@wraps(f)
def wrapper(*args, **kwargs):
if get_session(args[0]) is None:
logging.error("Couldn't create a session")
return None
else:
return f(*args, **kwargs)
return wrapper
def fallback(default):
def inner(f):
# noinspection PyBroadException
@wraps(f)
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception:
traceback.print_exc()
return default
return wrapper
return inner