import sys
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World! instant change test xxx from ' + __file__
    if not environ['mod_wsgi.process_group']:
		output += '\nWSGI RUNNING EMBEDDED MODE'
    else:
		output += '\nWSGI RUNNING DAEMON MODE'

    cookies = environ.get('HTTP_COOKIE', None)
    output +='\nCOOKIES  acc_session1=%s %s' % (str(cookies), type(cookies) )
    #output += '\n%s' % dir(environ)
    temp = environ.items()
    temp.sort()
    temp = ['%-20s\t%s' % x for x in temp]
    paths = '\n'.join(temp)
    output += '\n'+paths
    
   

    response_headers = [ ('Content-type', 'text/plain'),
                         ('Content-Length', str(len(output)))
                         ]
    start_response(status, response_headers)
    return [output]

    
import pprint

class LoggingMiddleware:

    def __init__(self, application):
        self.__application = application

    def __call__(self, environ, start_response):
        errors = environ['wsgi.errors']
        pprint.pprint(('ppREQUEST', environ), stream=errors)

        def _start_response(status, headers):
            pprint.pprint(('ppRESPONSE', status, headers), stream=errors)
            return start_response(status, headers)

        return self.__application(environ, _start_response)

application = LoggingMiddleware(application)