-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·67 lines (55 loc) · 2.01 KB
/
server.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
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
That is http/cherrypy frontend to the Satory-17.
CherryPy converts incoming http requests into calls to the engine.
"""
from __future__ import with_statement
import sys
import os
import cgi
import traceback
import cherrypy
import satory17
from satory17.core import PLUG
class FrontPage:
@cherrypy.expose
@cherrypy.tools.encode()
@cherrypy.tools.decode()
def default(self, paper="frontpage", *args, **KWs):
"""Frontend: shows entire paper or redirects to a special page."""
cherrypy.response.headers['Content-Type'] = "text/html"
wrapper = satory17.html_page(ID=unicode(paper))
return wrapper.full_page()
@cherrypy.expose
@cherrypy.tools.encode()
def debug(self, ID=None, *args, **KWs):
"""Debug environment."""
cherrypy.response.headers['Content-Type'] = "text/html"
return u"Debugging '%s'<hr/>Args: %s<hr/>KWs: %s" % (ID, args, KWs)
@cherrypy.expose
@cherrypy.tools.encode()
@cherrypy.tools.decode()
def _(self, ID, method="html", *args, **kws):
"""AJAX backend: forwards requests to handlers."""
cherrypy.response.headers['Content-Type'] = "text/html"
try:
satory17.say.warning('args: ' + str(args))
satory17.say.warning('kws: ' + str(kws))
res = PLUG(ID, method, *args, **kws)
except:
# Reporting an exeption inside of ajax call.
esc = cgi.escape
args = ["%s : %s" % (esc(k), esc(kws[k])) for k in kws]
res = """ <h2>AJAX error:</h2>
%s<hr />
<pre>%s</pre>
""" % ("<br>".join(args), traceback.format_exc())
return res
# Contacts cherrypy's config file.
root_dir = os.path.dirname(__file__)
cfg_file = os.path.join(root_dir, 'server.conf')
if __name__ == '__main__':
cherrypy.quickstart(FrontPage(), config=os.path.join(root_dir, 'server.conf'))
else:
cherrypy.tree.mount(FrontPage(), config=cfg_file)