-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpython_dispatcher.py
36 lines (31 loc) · 1.29 KB
/
python_dispatcher.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
import traceback
from routes import Mapper
import ppp_core
import example_ppp_module as flower
import ppp_questionparsing_grammatical as qp_grammatical
import ppp_cas
import ppp_spell_checker
#import ppp_nlp_ml_standalone
class Application:
def __init__(self):
self.mapper = Mapper()
self.mapper.connect('core', '/core/', app=ppp_core.app)
self.mapper.connect('qp_grammatical', '/qp_grammatical/', app=qp_grammatical.app)
self.mapper.connect('flower', '/flower/', app=flower.app)
self.mapper.connect('cas', '/cas/', app=ppp_cas.app)
self.mapper.connect('spellcheck', '/spell_checker/', app=ppp_spell_checker.app)
#self.mapper.connect('nlp_ml_standalone', '/nlp_ml_standalone/', app=ppp_nlp_ml_standalone.app)
def __call__(self, environ, start_response):
match = self.mapper.routematch(environ=environ)
app = match[0]['app'] if match else self.not_found
try:
return app(environ, start_response)
except KeyboardInterrupt:
raise
except Exception as e:
traceback.print_exc(e)
def not_found(self, environ, start_response):
headers = [('Content-Type', 'text/plain')]
start_response('404 Not Found', headers)
return [b'Not found.']
app = Application()