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

« back to all changes in this revision

Viewing changes to MoinMoin/server/server_fastcgi.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
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin.server.server_fastcgi
 
4
 
 
5
    This is not really a server, it is just so that fastcgi stuff
 
6
    (the real server is likely Apache2) fits the model we have for
 
7
    Twisted and standalone server.
 
8
 
 
9
    Minimal usage:
 
10
 
 
11
        from MoinMoin.server.server_fastcgi import FastCgiConfig, run
 
12
 
 
13
        class Config(FastCgiConfig):
 
14
            pass
 
15
 
 
16
        run(Config)
 
17
 
 
18
    See more options in FastCgiConfig class.
 
19
 
 
20
    @copyright: 2007 MoinMoin:ThomasWaldmann
 
21
 
 
22
    @license: GNU GPL, see COPYING for details.
 
23
"""
 
24
 
 
25
from MoinMoin.server import Config
 
26
from MoinMoin.request import request_fcgi
 
27
from MoinMoin.support import thfcgi
 
28
 
 
29
# Set threads flag, so other code can use proper locking.
 
30
from MoinMoin import config
 
31
config.use_threads = 1
 
32
del config
 
33
 
 
34
class FastCgiConfig(Config):
 
35
    """ Set up default server """
 
36
    properties = {}
 
37
    # properties = {'script_name': '/'}
 
38
 
 
39
    # how many requests shall be handled by a moin fcgi process before it dies,
 
40
    # -1 mean "unlimited lifetime":
 
41
    max_requests = -1
 
42
 
 
43
    # how many threads to use (1 means use only main program, non-threaded)
 
44
    max_threads = 5
 
45
 
 
46
    # backlog, use in socket.listen(backlog) call
 
47
    backlog = 5
 
48
 
 
49
    # default port
 
50
    port = None
 
51
 
 
52
def run(ConfigClass=FastCgiConfig):
 
53
    config = ConfigClass()
 
54
 
 
55
    handle_request = lambda req, env, form, properties=config.properties: \
 
56
                         request_fcgi.Request(req, env, form, properties=properties).run()
 
57
    fcg = thfcgi.FCGI(handle_request, port=config.port, max_requests=config.max_requests, backlog=config.backlog, max_threads=config.max_threads)
 
58
    fcg.run()
 
59