web/ldt/core/handlers/modwsgi.py
author wakimd
Sun, 14 Nov 2010 20:25:22 +0100
changeset 1 3a30d255c235
permissions -rw-r--r--
First version of API with tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
import os, sys, site
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
def application(environ, start_response):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
    os.environ['DJANGO_SETTINGS_MODULE'] = environ['DJANGO_SETTINGS_MODULE']
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
    os.environ['PY_USE_XMLPLUS'] = environ['PY_USE_XMLPLUS']
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
    prev_sys_path = list(sys.path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
    sys.path.append(environ['PROJECT_PATH'])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
    site.addsitedir(environ['PYTHON_PATH'])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
    new_sys_path = [] 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
    for item in list(sys.path): 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14
        if item not in prev_sys_path: 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    15
            new_sys_path.append(item) 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    16
            sys.path.remove(item) 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    17
    sys.path[:0] = new_sys_path 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    18
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    19
    import django.core.handlers.wsgi
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    20
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    21
    _application = django.core.handlers.wsgi.WSGIHandler()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    22
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    23
    return _application(environ, start_response)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    24