~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/server/server_wsgi.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
    MoinMoin - WSGI application
 
3
 
 
4
    Minimal code for using this:
 
5
 
 
6
    from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp
 
7
 
 
8
    class Config(WsgiConfig):
 
9
        pass
 
10
 
 
11
    config = Config() # you MUST create an instance
 
12
    # use moinmoinApp here with your WSGI server / gateway
 
13
 
 
14
    @copyright: 2005 Anakim Border <akborder@gmail.com>,
 
15
                2007 MoinMoin:ThomasWaldmann
 
16
    @license: GNU GPL, see COPYING for details.
 
17
"""
 
18
 
 
19
from MoinMoin.server import Config
 
20
from MoinMoin.request import request_wsgi
 
21
 
 
22
class WsgiConfig(Config):
 
23
    """ WSGI default config """
 
24
    pass
 
25
 
 
26
 
 
27
def moinmoinApp(environ, start_response):
 
28
    request = request_wsgi.Request(environ)
 
29
    request.run()
 
30
    start_response(request.status, request.headers)
 
31
    if request._send_file is not None:
 
32
        # moin wants to send a file (e.g. AttachFile.do_get)
 
33
        def simple_wrapper(fileobj, bufsize):
 
34
            return iter(lambda: fileobj.read(bufsize), '')
 
35
        file_wrapper = environ.get('wsgi.file_wrapper', simple_wrapper)
 
36
        return file_wrapper(request._send_file, request._send_bufsize)
 
37
    else:
 
38
        return [request.output()] # don't we have a filelike there also!?
 
39