-
Notifications
You must be signed in to change notification settings - Fork 11
/
zenhttp_tornado.py
56 lines (36 loc) · 1 KB
/
zenhttp_tornado.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
import sys
import os
import signal
import logging
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'vendor')))
from tornado import web
import tornado.ioloop
from zenlines import zenlines
class MainHandler(web.RequestHandler):
def get(self):
letter = self.get_query_argument('q', None)
if not letter:
self.set_status(400)
self.write('Bad Request')
return
try:
zenline = zenlines[letter]
except KeyError:
self.set_status(404)
self.write('Not Found')
return
self.write(zenline)
def set_etag_header(self):
pass
def check_etag_header(self):
return False
app = web.Application([('/', MainHandler)])
app.listen(8080)
logging.getLogger('tornado.access').disabled = True
loop = tornado.ioloop.IOLoop.current()
def stop(signal, frame):
loop.stop()
signal.signal(signal.SIGTERM, stop)
signal.signal(signal.SIGINT, stop)
loop.start()