-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiDecorators.py
More file actions
41 lines (33 loc) · 1.16 KB
/
apiDecorators.py
File metadata and controls
41 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import sys
from pathlib import Path
sys.path.append(os.path.abspath(
Path(__file__).resolve().parent.parent
))
import UAPI
class APIDecorators:
# Add your function decorators here.
# Here's one example for you, for illustrative purpose only.
'''
def decorator1 (arg1=None, default_reason=None):
if (not default_reason):
default_reason = UAPI.UAPIManager.Status.Reason.MY_REASON
def Inner (api_function):
def wrapper (*args, **kwargs):
if (not some_condition):
return UAPI.UAPIManager.createResponse(
status=False,
reason=UAPI.UAPIManager.Status.Reason.INTERNAL_ERROR,
)
# check conditions here ...
ok_condition = UAPI.APIUtilities.my_utility(*args, **kwargs)
if (not ok_condition):
return UAPI.UAPIManager.createResponse(
status=False,
reason=default_reason,
)
elif (ok_condition):
return api_function(*args, **kwargs)
return wrapper
return Inner
'''