blob: 419c5f9f4fe4d53ed260dff157c72b66bbeb14ae (
plain)
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
|
from paste.urlparser import StaticURLParser
from wsgiref.util import shift_path_info
from paste.httpserver import serve
# the template of the page
html = '''
<html>
<head>
<script type="text/javascript" src="/static/jquery.pack.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
%s
});
</script>
</head>
<body>
%s
</body>
<html>
'''
# the body of the page
body = """
<button id="sql-button" class="short">SQL</button>
<pre id="sql" class="sql" style="display: none">SELECT * FROM Product</pre>
"""
# the javascript relying on JQuery
js = """
$("#sql-button").toggle(function(event){
$("#sql").hide("slow");
}, function(event){
$("#sql").show("slow");
});
"""
static = StaticURLParser(directory='/tmp')
def application(env, resp):
"""Return the JQuery-enhanced HTML page and dispatch on the
static directory too"""
name = shift_path_info(env)
if name == 'static':
return static(env, resp)
resp('200 OK', [('Content-type', 'text/html')])
return [html % (js, body)]
if __name__ == '__main__':
serve(application, '', 8000)
|