src/ldt/ldt/core/handlers/modwsgi.py
author ymh <ymh.work@gmail.com>
Mon, 16 May 2011 20:00:36 +0200
changeset 111 4535dafa6007
parent 63 93325a5d61f0
child 1362 df60d20f965c
permissions -rw-r--r--
improve releasing of resources when indexing + convert line endings to unix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     1
import os
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     2
import sys
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     3
import site
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     4
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     5
def application(environ, start_response):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     6
    os.environ['DJANGO_SETTINGS_MODULE'] = environ['DJANGO_SETTINGS_MODULE']
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     7
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     8
    prev_sys_path = list(sys.path)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
     9
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    10
    sys.path.append(environ['PROJECT_PATH'])
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    11
    for path in environ.get('PYTHON_PATH', "").split(os.pathsep):
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    12
        if path:
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    13
            site.addsitedir(path)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    14
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    15
    new_sys_path = [] 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    16
    for item in list(sys.path): 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    17
        if item not in prev_sys_path: 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    18
            new_sys_path.append(item) 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    19
            sys.path.remove(item)
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    20
    sys.path[:0] = new_sys_path 
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    21
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    22
    import django.core.handlers.wsgi
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    23
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    24
    _application = django.core.handlers.wsgi.WSGIHandler()
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    25
4535dafa6007 improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    26
    return _application(environ, start_response)