-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplay-with-flask.py
57 lines (40 loc) · 1.18 KB
/
play-with-flask.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
from functools import wraps
from flask import Flask
app = Flask(__name__)
def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
return "La LA LA"
# return f(*args, **kwargs)
return decorated_function
@app.route('/')
@login_required
def bismillah():
return "Bismillah Project"
@app.route("/login", methods=["POST"])
def login():
return "Return Login Params"
@app.route("/with-url/<name>")
def with_name(name):
return "With URL " + name
def get_decorators(function):
if not function.func_closure:
return [function]
decorators = []
for closure in function.func_closure:
decorators.extend(get_decorators(closure.cell_contents))
return [function] + decorators
@app.route("/swagger")
def swagger():
ignore_verbs = {"HEAD", "OPTIONS"}
for rule in app.url_map.iter_rules():
endpoint = app.view_functions[rule.endpoint]
# get_decorators(endpoint)
for verb in rule.methods.difference(ignore_verbs):
print(rule.rule + " " + verb)
return "Swagger"
if __name__ == '__main__':
app.run()