-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgihandler.wsgi
64 lines (47 loc) · 1.54 KB
/
wsgihandler.wsgi
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Apache HTTP Server `mod_wsgi` handler
needs apache2x, mod_wsgi, python-virtualenv(optional)
Generate Python Virtual Environment (virtualenv)
# cd /usr/share
# mkdir python-wsgi
# cd $_
# virtualenv --no-site-packages wsgi-baseline-python
Example Configuaration which has to be added into apache config file
(httpd.conf):
LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi
WSGIPythonHome /usr/share/python-wsgi/wsgi-baseline-python
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
"""
import os, sys
import BaseHTTPServer
#current directory
current_directory = os.path.dirname(os.path.abspath(__file__))
# set script directory as current directory
os.chdir(current_directory)
# put this script directory into import path
try:
sys.path.remove(current_directory)
except(ValueError):
pass
sys.path.insert(0, current_directory)
from appserver import apphandler
statuscodes=BaseHTTPServer.BaseHTTPRequestHandler.responses
def application(environ, start_response):
response_headers = []
# custom environment variables
environ.update({
"APP_SERVER": "MOD_WSGI",
})
status, headers, output = apphandler(environ)
for headertype in headers.keys():
response_headers.append((
str(headertype),
str(headers[headertype]),
))
status = "%s %s" % (str(status),
statuscodes[status][0])
start_response(status, response_headers)
return [output]