2017-04-24 21:30:53 +00:00
|
|
|
from typing import Callable, Dict
|
2016-08-14 10:35:14 +00:00
|
|
|
from collections import defaultdict
|
2017-02-04 00:08:12 +00:00
|
|
|
from szurubooru.rest.context import Context, Response
|
2016-08-14 10:35:14 +00:00
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
RouteHandler = Callable[[Context, Dict[str, str]], Response]
|
|
|
|
routes = defaultdict(dict) # type: Dict[str, Dict[str, RouteHandler]]
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-08-14 10:35:14 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def get(url: str) -> Callable[[RouteHandler], RouteHandler]:
|
|
|
|
def wrapper(handler: RouteHandler) -> RouteHandler:
|
2016-08-14 10:35:14 +00:00
|
|
|
routes[url]['GET'] = handler
|
|
|
|
return handler
|
|
|
|
return wrapper
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def put(url: str) -> Callable[[RouteHandler], RouteHandler]:
|
|
|
|
def wrapper(handler: RouteHandler) -> RouteHandler:
|
2016-08-14 10:35:14 +00:00
|
|
|
routes[url]['PUT'] = handler
|
|
|
|
return handler
|
|
|
|
return wrapper
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def post(url: str) -> Callable[[RouteHandler], RouteHandler]:
|
|
|
|
def wrapper(handler: RouteHandler) -> RouteHandler:
|
2016-08-14 10:35:14 +00:00
|
|
|
routes[url]['POST'] = handler
|
|
|
|
return handler
|
|
|
|
return wrapper
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def delete(url: str) -> Callable[[RouteHandler], RouteHandler]:
|
|
|
|
def wrapper(handler: RouteHandler) -> RouteHandler:
|
2016-08-14 10:35:14 +00:00
|
|
|
routes[url]['DELETE'] = handler
|
|
|
|
return handler
|
|
|
|
return wrapper
|