equal
deleted
inserted
replaced
1 #!/usr/bin/python2.5 |
1 #!/usr/bin/python2.5 |
2 # :set filetype=py encoding=utf8 |
|
3 |
2 |
4 """ |
3 """ |
5 CGI implementation |
4 CGI mode using qmsk.web.cgi |
6 """ |
5 """ |
7 |
6 |
8 # CGI handler for WSGI |
7 def main () : |
9 import wsgiref.handlers |
|
10 |
|
11 def cgi_error () : |
|
12 """ |
8 """ |
13 Dumps out a raw traceback of the current exception to stdout, intended for use from except |
9 Build our wsgi.Application and run |
14 """ |
|
15 |
|
16 import traceback, sys |
|
17 |
|
18 print 'Status: 500 Internal Server Error\r' |
|
19 print 'Content-type: text/plain\r' |
|
20 print '\r' |
|
21 |
|
22 traceback.print_exc(100, sys.stdout) |
|
23 |
|
24 def cgi_main () : |
|
25 """ |
|
26 Run in CGI mode |
|
27 """ |
10 """ |
28 |
11 |
29 try : |
12 try : |
30 from qmsk.web import wsgi |
13 from qmsk.web import wsgi, cgi_main |
31 import urls |
14 import urls |
32 |
|
33 # create handler |
|
34 cgi_handler = wsgiref.handlers.CGIHandler() |
|
35 |
15 |
36 # create app |
16 # create app |
37 app = wsgi.Application(urls.mapper) |
17 app = wsgi.Application(urls.mapper) |
38 |
18 |
39 # run once |
19 # run once |
40 cgi_handler.run(app) |
20 cgi_main.run(app) |
41 |
21 |
42 except : |
22 except : |
43 cgi_error() |
23 # display error on stdout |
|
24 cgi_main.error() |
44 |
25 |
45 if __name__ == '__main__' : |
26 if __name__ == '__main__' : |
46 cgi_main() |
27 main() |
|
28 |