Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.support.flup.server.cgi.WSGIServer Class Reference

List of all members.

Public Member Functions

def __init__
def run

Public Attributes

 application

Detailed Description

Definition at line 10 of file cgi.py.


Constructor & Destructor Documentation

def MoinMoin.support.flup.server.cgi.WSGIServer.__init__ (   self,
  application 
)

Definition at line 12 of file cgi.py.

00012 
00013     def __init__(self, application):
00014         self.application = application


Member Function Documentation

Definition at line 15 of file cgi.py.

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

Member Data Documentation

Definition at line 13 of file cgi.py.


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