-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (33 loc) · 1.07 KB
/
app.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
from litestar import Litestar
from litestar import get
@get("/")
async def index() -> str:
return "Hello, world!"
@get("/books/{book_id:int}")
async def get_book(book_id: int) -> dict[str, int]:
return {"book_id": book_id}
import json
from litestar import post
@post("/parse")
async def parse(data: str) -> dict[str, str]:
return json.loads(data)[0]
from dateutil import parser as date_parser
@post("/parse_du")
async def parse_du(data: str) -> dict[str, str]:
val = json.loads(data)[0]["datetime"]
res = date_parser.parse(val)
return {"datetime": str(res)}
import datetime as dt
@post("/parse_iso")
async def parse_iso(data: str) -> dict[str, str]:
val = json.loads(data)[0]["datetime"]
res = dt.datetime.fromisoformat(val)
return {"datetime": str(res)}
GLOBAL_VAR = []
@get("/leak")
async def leak() -> str:
return GLOBAL_VAR.append(["Hello, world!"*len(GLOBAL_VAR)*10])
app = Litestar([index, get_book, parse, parse_du, parse_iso, leak])
import uvicorn
if __name__ == "__main__":
uvicorn.run(app, host='0.0.0.0', port=5000)