changeset 4273:40dd44a3fcff

Get rid of the mod_python adapter
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 06 Aug 2008 23:56:04 +0200
parents 0b5f28e79da7
children ba0daaf24d63
files MoinMoin/request/request_modpython.py MoinMoin/server/server_modpython.py wiki/server/moinmodpy.htaccess wiki/server/moinmodpy.py
diffstat 4 files changed, 0 insertions(+), 325 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/request_modpython.py	Wed Aug 06 23:53:17 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - mod_python Request Implementation for Apache and mod_python.
-
-    @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
-                2003-2006 MoinMoin:ThomasWaldmann
-    @license: GNU GPL, see COPYING for details.
-"""
-from MoinMoin import log
-logging = log.getLogger(__name__)
-
-from MoinMoin import wikiutil
-from MoinMoin.request import RequestBase, RemoteClosedConnection
-
-class Request(RequestBase):
-    """ specialized on mod_python requests """
-
-    def __init__(self, req, properties={}):
-        """ Saves mod_pythons request and sets basic variables using
-            the req.subprocess_env, cause this provides a standard
-            way to access the values we need here.
-
-            @param req: the mod_python request instance
-        """
-        try:
-            # flags if headers sent out contained content-type or status
-            self._have_ct = 0
-            self._have_status = 0
-
-            req.add_common_vars()
-            self.mpyreq = req
-            # some mod_python 2.7.X has no get method for table objects,
-            # so we make a real dict out of it first.
-            if not hasattr(req.subprocess_env, 'get'):
-                env = dict(req.subprocess_env)
-            else:
-                env = req.subprocess_env
-            self._setup_vars_from_std_env(env)
-            RequestBase.__init__(self, properties)
-
-        except Exception, err:
-            self.fail(err)
-
-    def fixURI(self, env):
-        """ Fix problems with script_name and path_info using
-        PythonOption directive to rewrite URI.
-
-        This is needed when using Apache 1 or other server which does
-        not support adding custom headers per request. With mod_python we
-        can use the PythonOption directive:
-
-            <Location /url/to/mywiki/>
-                PythonOption X-Moin-Location /url/to/mywiki/
-            </location>
-
-        Note that *neither* script_name *nor* path_info can be trusted
-        when Moin is invoked as a mod_python handler with apache1, so we
-        must build both using request_uri and the provided PythonOption.
-        """
-        # Be compatible with release 1.3.5 "Location" option
-        # TODO: Remove in later release, we should have one option only.
-        old_location = 'Location'
-        options_table = self.mpyreq.get_options()
-        if not hasattr(options_table, 'get'):
-            options = dict(options_table)
-        else:
-            options = options_table
-        location = options.get(self.moin_location) or options.get(old_location)
-        if location:
-            env[self.moin_location] = location
-            # Try to recreate script_name and path_info from request_uri.
-            import urlparse
-            scriptAndPath = urlparse.urlparse(self.request_uri)[2]
-            self.script_name = location.rstrip('/')
-            path = scriptAndPath.replace(self.script_name, '', 1)
-            self.path_info = wikiutil.url_unquote(path, want_unicode=False)
-
-        RequestBase.fixURI(self, env)
-
-    def _setup_args_from_cgi_form(self):
-        """ Override to use mod_python.util.FieldStorage
-
-        It's little different from cgi.FieldStorage, so we need to
-        duplicate the conversion code.
-        """
-        from mod_python import util
-        form = util.FieldStorage(self.mpyreq, keep_blank_values=1) # by default this evaluates query string AND body POST data!
-
-        args = {}
-
-        # You cannot get rid of .keys() here
-        for key in form.keys():
-            if key is None:
-                continue
-            values = form[key]
-            if not isinstance(values, list):
-                values = [values]
-            fixedResult = []
-            for item in values:
-                if isinstance(item, util.StringField):
-                    fixedResult.append(item.value)
-                elif isinstance(item, util.Field) and item.filename:
-                    fixedResult.append(item.file)
-                    # Remember filenames with a name hack
-                    args[key + '__filename__'] = item.filename
-                    # XXX Now it gets extremely dirty to work around a problem in mod_python 3.3.1: XXX
-                    # Without the next line, item.file will be closed when item/form leaves this scope.
-                    # I guess some reference counting is not implemented correctly for item.file,
-                    # so we just keep a reference to item to keep it alive...
-                    fixedResult.append(item)  # we are lucky, nobody uses the 2nd list item anyway
-                    # If you are reading this, please switch to mod_wsgi. :)
-                elif isinstance(item, str):
-                    # mod_python 2.7 might return strings instead of Field objects.
-                    fixedResult.append(item)
-            args[key] = fixedResult
-
-        result = self.decodeArgs(args)
-        return result  # XXX without the hack above, item.file gets closed when returning! XXX
-
-    def run(self, req):
-        """ mod_python calls this with its request object. We don't
-            need it cause its already passed to __init__. So ignore
-            it and just return RequestBase.run.
-
-            @param req: the mod_python request instance
-        """
-        return RequestBase.run(self)
-
-    def read(self, n):
-        """ Read from input stream. """
-        if n is None:
-            logging.warning("calling request.read(None) might block")
-            return self.mpyreq.read()
-        else:
-            return self.mpyreq.read(n)
-
-    def write(self, *data):
-        """ Write to output stream. """
-        data = self.encode(data)
-        try:
-            self.mpyreq.write(data)
-        except Exception:
-            raise RemoteClosedConnection()
-
-    def flush(self):
-        """ We can't flush it, so do nothing. """
-        pass
-
-    def finish(self):
-        """ Just return apache.OK. Status is set in req.status. """
-        RequestBase.finish(self)
-        # is it possible that we need to return something else here?
-        from mod_python import apache
-        return apache.OK
-
-    def _emit_http_headers(self, headers):
-        """ private method to send out preprocessed list of HTTP headers """
-        st_header, ct_header, other_headers = headers[0], headers[1], headers[2:]
-        status = st_header.split(':', 1)[1].lstrip()
-        self.mpyreq.status = int(status.split(' ', 1)[0])
-        self.mpyreq.content_type = ct_header.split(':', 1)[1].lstrip()
-        for header in other_headers:
-            key, value = header.split(':', 1)
-            value = value.lstrip()
-            self.mpyreq.headers_out[key] = value
-        # this is for mod_python 2.7.X, for 3.X it's a NOP
-        self.mpyreq.send_http_header()
-
--- a/MoinMoin/server/server_modpython.py	Wed Aug 06 23:53:17 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin.server.server_modpython
-
-    This is not really a server, it is just so that modpython stuff
-    (the real server is likely Apache2) fits the model we have for
-    Twisted and standalone server.
-
-    Minimal usage:
-
-        from MoinMoin.server.server_modpython import CgiConfig, run
-
-        class Config(CgiConfig):
-            pass
-
-        run(Config)
-
-    See more options in CgiConfig class.
-
-    @copyright: 2006 MoinMoin:ThomasWaldmann
-    @license: GNU GPL, see COPYING for details.
-"""
-
-from MoinMoin.server import Config
-from MoinMoin.request import request_modpython
-
-# Set threads flag, so other code can use proper locking.
-# TODO: It seems that modpy does not use threads, so we don't need to
-# set it here. Do we have another method to check this?
-from MoinMoin import config
-config.use_threads = 1
-del config
-
-# Server globals
-config = None
-
-class ModpythonConfig(Config):
-    """ Set up default server """
-    properties = {}
-
-
-def modpythonHandler(request, ConfigClass=ModpythonConfig):
-    config = ConfigClass()
-    moinreq = request_modpython.Request(request, config.properties)
-    return moinreq.run(request)
-
--- a/wiki/server/moinmodpy.htaccess	Wed Aug 06 23:53:17 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-##
-## (c) 2004 by Oliver Graf <ograf@bitart.de>
-##
-## .htaccess file for using mod_python with MoinMoin
-##
-## copy this file to the path below which you want to have your wiki
-## instance and edit the paths to match your configuration.
-##
-# With which name should the wiki be accessible? (wiki)
-<Files wiki>
-
-  # Use mod_python as handler
-  SetHandler python-program
-
-  # add the path where the moinmodpy.py wrapper can be found
-  PythonPath "['/path/to/share/moin/server']+sys.path"
-
-  # use the moinmodpy wrapper to handle requests
-  PythonHandler moinmodpy
-
-</Files>
-# voila.
-
-##
-## NOTE: due to a bug in mod_python < 3.1.3 you 
-##       need to use the wrapper above.
-##
-##       If you fix this bug, you can use MoinMoin without the
-##       wrapper. See MoinMoin INSTALL.html how to fix the bug.
-##       Use the following htaccess with a fixed mod_python:
-##
-# With which name should the wiki be accessible? (wiki)
-#<Files wiki>
-#
-#  # Use mod_python as handler
-#  SetHandler python-program
-#
-#  # set code search path to find farmconfig, wikiconfig and MoinMoin code package
-#  PythonPath "['/path/to/farmconfigdir', '/path/to/wikiconfigdir', '/path/to/moin/lib/python']+sys.path"
-#
-#  # choose the ModPy Request class as handler
-#  PythonHandler MoinMoin.request.request_modpython::Request.run
-#
-#</Files>
-
--- a/wiki/server/moinmodpy.py	Wed Aug 06 23:53:17 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - mod_python wrapper for broken mod_python versions
-
-    add a .htaccess to the path below which you want to have your
-    wiki instance:
-
-    <Files wiki>
-      SetHandler python-program
-      PythonPath "['/path/to/share/moin/server'] + sys.path"
-      PythonHandler moinmodpy
-    </Files>
-
-    Note: this is a wrapper needed because of a bug in
-          mod_python < 3.1.3
-
-
-    mod_python.apache.resolve_object fails to parse a object with dots.
-
-    If you have a newer version, take a look at moinmodpy.htaccess
-    to see how to use MoinMoin without this wrapper. You can also
-    look into INSTALL.html to see how you can fix the bug on your own
-    (a simple one line change).
-
-    @copyright: 2004-2005 by Oliver Graf <ograf@bitart.de>
-    @license: GNU GPL, see COPYING for details.
-"""
-
-import sys, os
-
-# a) Configuration of Python's code search path
-#    If you already have set up the PYTHONPATH environment variable for the
-#    stuff you see below, you don't need to do a1) and a2).
-
-# a1) Path of the directory where the MoinMoin code package is located.
-#     Needed if you installed with --prefix=PREFIX or you didn't use setup.py.
-#sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
-
-# a2) Path of the directory where wikiconfig.py / farmconfig.py is located.
-#     See wiki/config/... for some sample config files.
-#sys.path.insert(0, '/path/to/wikiconfigdir')
-#sys.path.insert(0, '/path/to/farmconfigdir')
-
-# b) Configuration of moin's logging
-#    If you have set up MOINLOGGINGCONF environment variable, you don't need this!
-#    You also don't need this if you are happy with the builtin defaults.
-#    See wiki/config/logging/... for some sample config files.
-#from MoinMoin import log
-#log.load_config('/path/to/logging_configuration_file')
-
-# Debug mode - show detailed error reports
-#os.environ['MOIN_DEBUG'] = '1'
-
-
-from MoinMoin.server.server_modpython import ModpythonConfig, modpythonHandler
-
-class MyConfig(ModpythonConfig):
-    """ Set up local server-specific stuff here """
-    # Properties
-    # Allow overriding any request property by the value defined in
-    # this dict e.g properties = {'script_name': '/mywiki'}.
-    ## properties = {}
-
-def handler(request):
-    return modpythonHandler(request, MyConfig)
-