Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.web._fallback_cgi.WSGIServer Class Reference

List of all members.

Public Member Functions

def __init__
def run

Public Attributes

 application

Detailed Description

Definition at line 17 of file _fallback_cgi.py.


Constructor & Destructor Documentation

def MoinMoin.web._fallback_cgi.WSGIServer.__init__ (   self,
  application 
)

Definition at line 19 of file _fallback_cgi.py.

00019 
00020     def __init__(self, application):
00021         self.application = application


Member Function Documentation

Definition at line 22 of file _fallback_cgi.py.

00022 
00023     def run(self):
00024 
00025         environ = dict(os.environ.items())
00026         environ['wsgi.input']        = sys.stdin
00027         environ['wsgi.errors']       = sys.stderr
00028         environ['wsgi.version']      = (1, 0)
00029         environ['wsgi.multithread']  = False
00030         environ['wsgi.multiprocess'] = True
00031         environ['wsgi.run_once']     = True
00032 
00033         if environ.get('HTTPS', 'off') in ('on', '1'):
00034             environ['wsgi.url_scheme'] = 'https'
00035         else:
00036             environ['wsgi.url_scheme'] = 'http'
00037 
00038         headers_set = []
00039         headers_sent = []
00040 
00041         def write(data):
00042             if not headers_set:
00043                 raise AssertionError("write() before start_response()")
00044 
00045             elif not headers_sent:
00046                 # Before the first output, send the stored headers
00047                 status, response_headers = headers_sent[:] = headers_set
00048                 sys.stdout.write('Status: %s\r\n' % status)
00049                 for header in response_headers:
00050                     sys.stdout.write('%s: %s\r\n' % header)
00051                 sys.stdout.write('\r\n')
00052 
00053             sys.stdout.write(data)
00054             sys.stdout.flush()
00055 
00056         def start_response(status, response_headers, exc_info=None):
00057             if exc_info:
00058                 try:
00059                     if headers_sent:
00060                         # Re-raise original exception if headers sent
00061                         raise exc_info[0], exc_info[1], exc_info[2]
00062                 finally:
00063                     exc_info = None     # avoid dangling circular ref
00064             elif headers_set:
00065                 raise AssertionError("Headers already set!")
00066 
00067             headers_set[:] = [status, response_headers]
00068             return write
00069 
00070         result = self.application(environ, start_response)
00071         try:
00072             for data in result:
00073                 if data:    # don't send headers until body appears
00074                     write(data)
00075             if not headers_sent:
00076                 write('')   # send headers now if body was empty
00077         finally:
00078             if hasattr(result, 'close'):
00079                 result.close()

Member Data Documentation

Definition at line 20 of file _fallback_cgi.py.


The documentation for this class was generated from the following file: