changeset 3071:806cf4814612

get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 22 Feb 2008 21:59:32 +0100
parents db0a4f4b30d3
children 103fd9035d50
files MoinMoin/request/__init__.py MoinMoin/request/request_standalone.py MoinMoin/request/request_wsgi.py MoinMoin/server/server_fastcgi.py MoinMoin/server/server_modpython.py MoinMoin/server/server_twisted.py MoinMoin/server/server_wsgi.py wiki/server/moin.fcg wiki/server/moin.py wiki/server/moin.wsgi wiki/server/moin_flup_wsgi.py wiki/server/moinmodpy.py
diffstat 12 files changed, 105 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/request/__init__.py	Fri Feb 22 21:59:32 2008 +0100
@@ -135,6 +135,10 @@
         self.page = None
         self._dicts = None
 
+        # session handling. users cannot rely on a session being
+        # created, but we should always set request.session
+        self.session = {}
+
         # setuid handling requires an attribute in the request
         # that stores the real user
         self._setuid_real_user = None
@@ -1236,16 +1240,16 @@
                 msg = None
                 # Complain about unknown actions
                 if not action_name in self.getKnownActions():
-                    msg = _("Unknown action %(action_name)s.") % {
+                    msg = _("Unknown action %(action_name)s.", formatted=False) % {
                             'action_name': wikiutil.escape(action_name), }
 
                 # Disallow non available actions
                 elif action_name[0].isupper() and not action_name in self.getAvailableActions(self.page):
-                    msg = _("You are not allowed to do %(action_name)s on this page.") % {
+                    msg = _("You are not allowed to do %(action_name)s on this page.", formatted=False) % {
                             'action_name': wikiutil.escape(action_name), }
                     if not self.user.valid:
                         # Suggest non valid user to login
-                        msg += " " + _("Login and try again.", formatted=0)
+                        msg += " " + _("Login and try again.", formatted=False)
 
                 if msg:
                     self.request.theme.add_msg(msg, "error")
@@ -1255,11 +1259,11 @@
                     from MoinMoin import action
                     handler = action.getHandler(self, action_name)
                     if handler is None:
-                        msg = _("You are not allowed to do %(action_name)s on this page.") % {
+                        msg = _("You are not allowed to do %(action_name)s on this page.", formatted=False) % {
                                 'action_name': wikiutil.escape(action_name), }
                         if not self.user.valid:
                             # Suggest non valid user to login
-                            msg += " " + _("Login and try again.", formatted=0)
+                            msg += " " + _("Login and try again.", formatted=False)
                         self.request.theme.add_msg(msg, "error")
                         self.page.send_page()
                     else:
--- a/MoinMoin/request/request_standalone.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/request/request_standalone.py	Fri Feb 22 21:59:32 2008 +0100
@@ -11,7 +11,7 @@
 from MoinMoin.request import RequestBase
 
 class Request(RequestBase):
-    """ specialized on StandAlone Server (MoinMoin.server.standalone) requests """
+    """ specialized on StandAlone Server (MoinMoin.server.server_standalone) requests """
     script_name = ''
 
     def __init__(self, sa, properties={}):
--- a/MoinMoin/request/request_wsgi.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/request/request_wsgi.py	Fri Feb 22 21:59:32 2008 +0100
@@ -20,7 +20,7 @@
             self.stdin = env['wsgi.input']
             self.stdout = StringIO.StringIO()
 
-            # used by MoinMoin.server.wsgi:
+            # used by MoinMoin.server.server_wsgi:
             self.status = '200 OK'
             self.headers = []
 
@@ -58,7 +58,7 @@
         pass
 
     def output(self):
-        # called by MoinMoin.server.wsgi
+        # called by MoinMoin.server.server_wsgi
         return self.stdout.getvalue()
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/server/server_fastcgi.py	Fri Feb 22 21:59:32 2008 +0100
@@ -0,0 +1,63 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin.server.server_fastcgi
+
+    This is not really a server, it is just so that fastcgi stuff
+    (the real server is likely Apache2) fits the model we have for
+    Twisted and standalone server.
+
+    Minimal usage:
+
+        from MoinMoin.server.server_fastcgi import FastCgiConfig, run
+        
+        class Config(FastCgiConfig):
+            pass
+
+        run(Config)
+        
+    See more options in FastCgiConfig class.
+
+    @copyright: 2007 MoinMoin:ThomasWaldmann
+
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import logging
+
+from MoinMoin.server import Config
+from MoinMoin.request import request_fcgi
+from MoinMoin.support import thfcgi
+
+# Set threads flag, so other code can use proper locking.
+from MoinMoin import config
+config.use_threads = 1
+del config
+
+class FastCgiConfig(Config):
+    """ Set up default server """
+
+    logPath = None # 'moin.log'
+    loglevel_stderr = None # do not write to stderr when using fcgi
+
+    properties = {}
+    # properties = {'script_name': '/'}
+
+    # how many requests shall be handled by a moin fcgi process before it dies,
+    # -1 mean "unlimited lifetime":
+    max_requests = -1
+
+    # how many threads to use (1 means use only main program, non-threaded)
+    max_threads = 5
+
+    # backlog, use in socket.listen(backlog) call
+    backlog = 5
+
+
+def run(ConfigClass=FastCgiConfig):
+    config = ConfigClass()
+
+    handle_request = lambda req, env, form, properties=config.properties: \
+                         request_fcgi.Request(req, env, form, properties=properties).run()
+    fcg = thfcgi.FCGI(handle_request, max_requests=config.max_requests, backlog=config.backlog, max_threads=config.max_threads)
+    fcg.run()
+
--- a/MoinMoin/server/server_modpython.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/server/server_modpython.py	Fri Feb 22 21:59:32 2008 +0100
@@ -39,7 +39,7 @@
 
     logPath = None
     properties = {}
-    
+
     # Set up log handler to log to apache log!
 
 def modpythonHandler(request, ConfigClass=ModpythonConfig):
--- a/MoinMoin/server/server_twisted.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/server/server_twisted.py	Fri Feb 22 21:59:32 2008 +0100
@@ -1,6 +1,6 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin.server.twistedmoin
+    MoinMoin.server.server_twisted
 
     Create standalone twisted based server.
 
--- a/MoinMoin/server/server_wsgi.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/MoinMoin/server/server_wsgi.py	Fri Feb 22 21:59:32 2008 +0100
@@ -24,7 +24,7 @@
 class WsgiConfig(Config):
     """ WSGI default config """
     loglevel_stderr = None # we do not want to write to stderr!
-         
+
 
 def moinmoinApp(environ, start_response):
     request = request_wsgi.Request(environ)
--- a/wiki/server/moin.fcg	Thu Feb 21 21:40:46 2008 +0100
+++ b/wiki/server/moin.fcg	Fri Feb 22 21:59:32 2008 +0100
@@ -27,7 +27,7 @@
 from MoinMoin.server.server_fastcgi import FastCgiConfig, run
 
 class Config(FastCgiConfig):
-    loglevel_file = logging.DEBUG
+    #loglevel_file = logging.DEBUG  # adapt if you don't like the default
     logPath = 'moin.log'
 
     properties = {}
--- a/wiki/server/moin.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/wiki/server/moin.py	Fri Feb 22 21:59:32 2008 +0100
@@ -1,2 +1,24 @@
-# see the toplevel directory for the real moin.py
+#!/usr/bin/env python
+"""
+    Start script for the standalone Wiki server.
 
+    @copyright: 2007 MoinMoin:ForrestVoight
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import sys
+import os
+
+from MoinMoin.script import MoinScript
+
+# Path to MoinMoin package, needed if you installed with --prefix=PREFIX
+# or if you did not use setup.py.
+#sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
+
+moinpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, moinpath)
+os.chdir(moinpath)
+
+if __name__ == '__main__':
+    sys.argv = ["moin.py", "server", "standalone"]
+    MoinScript().run()
--- a/wiki/server/moin.wsgi	Thu Feb 21 21:40:46 2008 +0100
+++ b/wiki/server/moin.wsgi	Fri Feb 22 21:59:32 2008 +0100
@@ -40,7 +40,7 @@
 
 class Config(WsgiConfig):
     logPath = 'moin.log' # adapt this to your needs!
-    #loglevel_file = logging.INFO # adapt this to your needs!
+    #loglevel_file = logging.INFO # adapt if you don't like the default
 
 config = Config() # MUST create an instance to init logging!
 
--- a/wiki/server/moin_flup_wsgi.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/wiki/server/moin_flup_wsgi.py	Fri Feb 22 21:59:32 2008 +0100
@@ -22,7 +22,7 @@
 
 class Config(WsgiConfig):
     logPath = 'moin.log' # adapt to your needs!
-    #loglevel_file = logging.INFO # adapt to your needs!
+    #loglevel_file = logging.INFO # adapt if you don't like the default
 
 config = Config() # MUST create an instance to init logging
 
--- a/wiki/server/moinmodpy.py	Thu Feb 21 21:40:46 2008 +0100
+++ b/wiki/server/moinmodpy.py	Fri Feb 22 21:59:32 2008 +0100
@@ -23,7 +23,7 @@
     (a simple one line change).
 
     TODO: this should be refactored so it uses MoinMoin.server package
-          (see how Twisted, WSGI and Standalone use it)
+          (see how server_twisted, server_wsgi and server_standalone use it)
 
     @copyright: 2004-2005 by Oliver Graf <ograf@bitart.de>
     @license: GNU GPL, see COPYING for details.