-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsgi.py
34 lines (24 loc) · 851 Bytes
/
wsgi.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
from webob import Request, Response
class WebFramework:
def __init__(self):
self.routes = {}
def route(self, path):
def wrapper(handler):
self.routes[path] = handler
return handler
return wrapper
def __call__(self, environ, start_response):
request = Request(environ)
response = self.handle(request)
return response(environ, start_response)
def client_error_response(self, response):
response.status_code = 404
response.text = "Not found."
def handle(self, request):
response = Response()
handler = self.routes.get(request.path)
if handler:
handler(request, response)
return response
self.client_error_response(response)
return response