2020-05-14 02:03:13 +00:00
|
|
|
import logging
|
|
|
|
import traceback
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
|
|
|
|
def uses_session(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapper(*args, **kwargs):
|
2020-05-14 23:51:55 +00:00
|
|
|
from .web import get_session
|
2020-05-14 02:03:13 +00:00
|
|
|
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
|