-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
74 lines (55 loc) · 1.86 KB
/
tools.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import inspect
from flask import *
sys.setrecursionlimit(1000)
class FunctionWrapperDecorator:
def __init__(self, cls):
global executed
executed = False
self.cls = cls
def __call__(self, *args, **kwargs):
function_names = [
name for name, value in inspect.getmembers(self.cls, inspect.isfunction)
]
for function_name in function_names:
original_function = getattr(self.cls, function_name)
wrapped_function = self.wrap(original_function)
setattr(self.cls, function_name, wrapped_function)
return self.cls(*args, **kwargs)
def wrap(self, func):
# Wrap the function
def inner(self, *args, **kwargs):
global executed
if not executed:
executed = True
try:
self.verif_file()
except:
pass
# avt la fonction
result = func(self, *args, **kwargs)
# après la fonction
return result
return inner
def format_dictio(dictio):
return {
table: {key: value for x in dictio[table] for key, value in x.items()}
for table in dictio
}
def transform_tuples(lst):
return [value[0] if value[0] is not None else "" for value in lst]
def format_data_for_sql(liste):
return "(" + ", ".join([f"'{item.replace(' ','_')}'" for item in liste]) + ")"
def get_function_name():
return inspect.stack()[1].function
def get_input(_input):
return request.form[_input]
def get_roots():
with open(__file__, "r") as file:
lines = file.readlines()
liste = [
line.replace("def ", "").split("(")[0]
for i, line in enumerate(lines)
if "@app.route" in lines[i - 1] and " " not in line and "app.rou" not in line
]
return liste