-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
52 lines (40 loc) · 1.18 KB
/
test.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
from datetime import datetime
import teapot
import teapot.mime
import teapot.wsgi
import teapot.response
last_modified = datetime.utcnow()
last_modified = datetime(
last_modified.year,
last_modified.month,
last_modified.day,
last_modified.hour,
last_modified.minute,
last_modified.second)
@teapot.rebase("/")
class Test(metaclass=teapot.routing.RoutableMeta):
def __init__(self, a, b):
self._a = a
self._b = b
@teapot.route("", "index")
def index(self):
response = teapot.response.Response(
teapot.mime.Type.text_plain,
body="{}".format(self._a),
last_modified=last_modified)
return response
@teapot.route("foo")
def foo(self):
response = teapot.response.Response(
teapot.mime.Type.text_plain.with_charset("utf8"),
last_modified=last_modified)
yield response
yield "{}".format(self._b).encode(
response.content_type.charset)
test = Test(10, 20)
import wsgiref.simple_server
httpd = wsgiref.simple_server.make_server(
'', 8000,
teapot.wsgi.Application(
teapot.routing.Router(test)))
httpd.serve_forever()