#!/usr/bin/env pythonimportos,sysimportdjango.core.handlers.wsgidefrun_with_cgi(application):environ=dict(os.environ.items())environ['wsgi.input']=sys.stdinenviron['wsgi.errors']=sys.stderrenviron['wsgi.version']=(1,0)environ['wsgi.multithread']=Falseenviron['wsgi.multiprocess']=Trueenviron['wsgi.run_once']=Trueifenviron.get('HTTPS','off')in('on','1'):environ['wsgi.url_scheme']='https'else:environ['wsgi.url_scheme']='http'headers_set=[]headers_sent=[]defwrite(data):ifnotheaders_set:raiseAssertionError("write() before start_response()")elifnotheaders_sent:# Before the first output, send the stored headersstatus,response_headers=headers_sent[:]=headers_setsys.stdout.write('Status: %s\\r\\n'%status)forheaderinresponse_headers:sys.stdout.write('%s: %s\\r\\n'%header)sys.stdout.write('\\r\\n')sys.stdout.write(data)sys.stdout.flush()defstart_response(status,response_headers,exc_info=None):ifexc_info:try:ifheaders_sent:# Re-raise original exception if headers sentraiseexc_info[0],exc_info[1],exc_info[2]finally:exc_info=None# avoid dangling circular refelifheaders_set:raiseAssertionError("Headers already set!")headers_set[:]=[status,response_headers]returnwriteresult=application(environ,start_response)try:fordatainresult:ifdata:# don't send headers until body appearswrite(data)ifnotheaders_sent:write('')# send headers now if body was emptyfinally:ifhasattr(result,'close'):result.close()# Change this to the directory above your site code.sys.path.append("/py")# Change mysite to the name of your site packageos.environ['DJANGO_SETTINGS_MODULE']='pytest.settings'run_with_cgi(django.core.handlers.wsgi.WSGIHandler())