Back to index

moin  1.9.0~rc2
wsgi.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004 FCKeditor - The text editor for Internet - http://www.fckeditor.net
00005 Copyright (C) 2003-2009 Frederico Caldeira Knabben
00006 
00007 == BEGIN LICENSE ==
00008 
00009 Licensed under the terms of any of the following licenses at your
00010 choice:
00011 
00012  - GNU General Public License Version 2 or later (the "GPL")
00013    http://www.gnu.org/licenses/gpl.html
00014 
00015  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
00016    http://www.gnu.org/licenses/lgpl.html
00017 
00018  - Mozilla Public License Version 1.1 or later (the "MPL")
00019    http://www.mozilla.org/MPL/MPL-1.1.html
00020 
00021 == END LICENSE ==
00022 
00023 Connector/QuickUpload for Python (WSGI wrapper).
00024 
00025 See config.py for configuration settings
00026 
00027 """
00028 
00029 from connector import FCKeditorConnector
00030 from upload import FCKeditorQuickUpload
00031 
00032 import cgitb
00033 from cStringIO import StringIO
00034 
00035 # Running from WSGI capable server (recomended)
00036 def App(environ, start_response):
00037        "WSGI entry point. Run the connector"
00038        if environ['SCRIPT_NAME'].endswith("connector.py"):
00039               conn = FCKeditorConnector(environ)
00040        elif environ['SCRIPT_NAME'].endswith("upload.py"):
00041               conn = FCKeditorQuickUpload(environ)
00042        else:
00043               start_response ("200 Ok", [('Content-Type','text/html')])
00044               yield "Unknown page requested: "
00045               yield environ['SCRIPT_NAME']
00046               return
00047        try:
00048               # run the connector
00049               data = conn.doResponse()
00050               # Start WSGI response:
00051               start_response ("200 Ok", conn.headers)
00052               # Send response text
00053               yield data
00054        except:
00055               start_response("500 Internal Server Error",[("Content-type","text/html")])
00056               file = StringIO()
00057               cgitb.Hook(file = file).handle()
00058               yield file.getvalue()