2022-02-14 19:16:09 +09:00
|
|
|
import time
|
2022-02-13 13:00:10 +09:00
|
|
|
from functools import wraps
|
|
|
|
|
2022-02-16 18:55:30 +09:00
|
|
|
def with_timestamp(f):
|
2022-02-13 13:00:10 +09:00
|
|
|
@wraps(f)
|
2022-02-16 18:55:30 +09:00
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
timestamp = int(time.time())
|
|
|
|
return f(timestamp, *args, **kwargs)
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
2022-02-16 18:55:30 +09:00
|
|
|
def with_first_argument(x):
|
|
|
|
def with_x(f):
|
2022-02-13 13:00:10 +09:00
|
|
|
@wraps(f)
|
2022-02-16 18:55:30 +09:00
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
return f(x, *args, **kwargs)
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
return wrapper
|
2022-02-14 19:16:09 +09:00
|
|
|
|
2022-02-16 18:55:30 +09:00
|
|
|
return with_x
|
2022-02-17 21:51:09 +09:00
|
|
|
|
|
|
|
def try_except_log(errors, exception_class):
|
|
|
|
def try_except_log_specific(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
except exception_class as e:
|
|
|
|
errors.append(e)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
return try_except_log_specific
|