changeset 4281:27ea0a15a347

Removed outdated twisted code
author Florian Krupicka <florian.krupicka@googlemail.com>
date Thu, 07 Aug 2008 23:12:22 +0200
parents 31f221fe7460
children 310ab489e119
files MoinMoin/request/request_twisted.py MoinMoin/server/server_twisted.py wiki/server/mointwisted wiki/server/mointwisted.cmd wiki/server/mointwisted.py
diffstat 5 files changed, 0 insertions(+), 578 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/request_twisted.py	Thu Aug 07 20:46:33 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - Twisted Request Implementation
-
-    @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.request import RequestBase, MoinMoinFinish, RemoteClosedConnection
-
-class Request(RequestBase):
-    """ specialized on Twisted requests """
-
-    def __init__(self, twistedRequest, pagename, reactor, properties={}):
-        try:
-            self.twistd = twistedRequest
-            self.reactor = reactor
-
-            # Copy headers
-            self.http_accept_language = self.twistd.getHeader('Accept-Language')
-            self.saved_cookie = self.twistd.getHeader('Cookie')
-            self.http_user_agent = self.twistd.getHeader('User-Agent')
-            try:
-                self.content_length = int(self.twistd.getHeader('Content-Length'))
-            except (TypeError, ValueError):
-                self.content_length = None
-            self.if_modified_since = self.twistd.getHeader('If-Modified-Since')
-            self.if_none_match = self.twistd.getHeader('If-None-Match')
-
-            # Copy values from twisted request
-            self.server_protocol = self.twistd.clientproto
-            self.server_name = self.twistd.getRequestHostname().split(':')[0]
-            self.server_port = str(self.twistd.getHost()[2])
-            self.is_ssl = self.twistd.isSecure()
-            self.path_info = '/' + '/'.join([pagename] + self.twistd.postpath)
-            self.request_method = self.twistd.method
-            self.remote_addr = self.twistd.getClientIP()
-            self.request_uri = self.twistd.uri
-            self.script_name = "/" + '/'.join(self.twistd.prepath[:-1])
-
-            # Values that need more work
-            self.query_string = self.splitURI(self.twistd.uri)[1]
-            self.setHttpReferer(self.twistd.getHeader('Referer'))
-            self.setHost()
-            self.setURL(self.twistd.getAllHeaders())
-
-            ##self.debugEnvironment(twistedRequest.getAllHeaders())
-
-            RequestBase.__init__(self, properties)
-
-        except MoinMoinFinish: # might be triggered by http_redirect
-            self.emit_http_headers() # send headers (important for sending MOIN_ID cookie)
-            self.finish()
-
-        except Exception, err:
-            # Wrap err inside an internal error if needed
-            from MoinMoin import error
-            if isinstance(err, error.FatalError):
-                self.delayedError = err
-            else:
-                self.delayedError = error.InternalError(str(err))
-
-    def run(self):
-        """ Handle delayed errors then invoke base class run """
-        if hasattr(self, 'delayedError'):
-            self.fail(self.delayedError)
-            return self.finish()
-        RequestBase.run(self)
-
-    def setup_args(self):
-        """ Return args dict
-
-        Twisted already parsed args, including __filename__ hacking,
-        but did not decode the values.
-        """
-        # All of the arguments, including URL and POST arguments (using keep_blank_values=1 internally).
-        return self.decodeArgs(self.twistd.args)
-
-    def read(self, n):
-        """ Read from input stream. """
-        # XXX why is that wrong?:
-        #rd = self.reactor.callFromThread(self.twistd.read)
-
-        # XXX do we need self.reactor.callFromThread with that?
-        # XXX if yes, why doesn't it work?
-        self.twistd.content.seek(0, 0)
-        if n is None:
-            logging.warning("calling request.read(None) might block")
-            rd = self.twistd.content.read()
-        else:
-            rd = self.twistd.content.read(n)
-        #print "request.RequestTwisted.read: data=\n" + str(rd)
-        return rd
-
-    def write(self, *data):
-        """ Write to output stream. """
-        #print "request.RequestTwisted.write: data=\n" + wd
-        data = self.encode(data)
-        try:
-            self.reactor.callFromThread(self.twistd.write, data)
-        except Exception:
-            raise RemoteClosedConnection()
-
-    def flush(self):
-        pass # XXX is there a flush in twisted?
-
-    def finish(self):
-        RequestBase.finish(self)
-        self.reactor.callFromThread(self.twistd.finish)
-
-    # Headers ----------------------------------------------------------
-
-    def _emit_http_headers(self, headers):
-        """ private method to send out preprocessed list of HTTP headers """
-        st_header, other_headers = headers[0], headers[1:]
-        status = st_header.split(':', 1)[1].lstrip()
-        status_code, status_msg = status.split(' ', 1)
-        self.twistd.setResponseCode(int(status_code), status_msg)
-        for header in other_headers:
-            key, value = header.split(':', 1)
-            value = value.lstrip()
-            if key.lower() == 'set-cookie':
-                key, value = value.split('=', 1)
-                self.twistd.addCookie(key, value)
-            else:
-                self.twistd.setHeader(key, value)
-
-    def http_redirect(self, url):
-        """ Redirect to a fully qualified, or server-rooted URL
-
-        @param url: relative or absolute url, ascii using url encoding.
-        """
-        url = self.getQualifiedURL(url)
-        self.twistd.redirect(url)
-        # calling finish here will send the rest of the data to the next
-        # request. leave the finish call to run()
-        #self.twistd.finish()
-        raise MoinMoinFinish
-
--- a/MoinMoin/server/server_twisted.py	Thu Aug 07 20:46:33 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,283 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin.server.server_twisted
-
-    Create standalone twisted based server.
-
-    Minimal usage:
-
-        from MoinMoin.server.server_twisted import TwistedConfig, makeApp
-
-        class Config(TwistedConfig):
-            docs = '/usr/share/moin/wiki/htdocs'
-            user = 'www-data'
-            group = 'www-data'
-
-        application = makeApp(Config)
-
-    Then run this code with twistd -y yourcode.py. See moin_twisted script.
-
-    @copyright: 2004 Thomas Waldmann, Oliver Graf, Nir Soffer
-    @license: GNU GPL, see COPYING for details.
-"""
-
-from twisted.application import internet, service
-from twisted.web import static, server, vhost, resource
-from twisted.internet import threads, reactor
-
-try:
-    from twisted.internet import ssl
-except ImportError:
-    ssl = None
-
-# Enable threads
-from twisted.python import threadable
-threadable.init(1)
-
-# MoinMoin imports
-from MoinMoin.request import request_twisted
-from MoinMoin.server import Config
-
-# Set threads flag, so other code can use proper locking
-from MoinMoin import config
-config.use_threads = True
-del config
-
-# Server globals
-config = None
-
-
-class WikiResource(resource.Resource):
-    """ Wiki resource """
-    isLeaf = 1
-
-    def render(self, request):
-        return server.NOT_DONE_YET
-
-
-class WikiRoot(resource.Resource):
-    """ Wiki root resource """
-
-    def getChild(self, name, request):
-        # Serve images and css from url_prefix_static
-        if request.prepath == [] and name == config.url_prefix_static[1:]:
-            return resource.Resource.getChild(self, name, request)
-
-        # Serve special 'root' files from url_prefix_static
-        elif name in ['favicon.ico', 'robots.txt'] and request.postpath == []:
-            return self.children[config.url_prefix_static[1:]].getChild(name, request)
-
-        # All other through moin
-
-        # TODO: fix profile code to include the request init and ignore
-        # first request. I'm not doing this now since its better done
-        # with the new twisted code waiting in fix branch. --Nir
-        else:
-            if config.memoryProfile:
-                config.memoryProfile.addRequest()
-            req = request_twisted.Request(request, name, reactor, properties=config.properties)
-            if config.hotshotProfile:
-                threads.deferToThread(config.hotshotProfile.runcall, req.run)
-            else:
-                threads.deferToThread(req.run)
-            return WikiResource()
-
-
-class MoinRequest(server.Request):
-    """ MoinMoin request
-
-    Enable passing of file-upload filenames
-    """
-
-    def requestReceived(self, command, path, version):
-        """ Called by channel when all data has been received.
-
-        Override server.Request method for POST requests, to fix file
-        uploads issue.
-        """
-        if command == 'POST':
-            self.requestReceivedPOST(path, version)
-        else:
-            server.Request.requestReceived(self, command, path, version)
-
-    def requestReceivedPOST(self, path, version):
-        """ Handle POST requests
-
-        This is a modified copy of server.Request.requestRecived,
-        modified to use cgi.FieldStorage to handle file uploads
-        correctly.
-
-        Creates an extra member extended_args which also has
-        filenames of file uploads ( FIELDNAME__filename__ ).
-        """
-        import cgi
-
-        self.content.seek(0, 0)
-        self.args = {}
-        self.extended_args = {}
-        self.stack = []
-
-        self.method = 'POST'
-        self.uri = path
-        self.clientproto = version
-        x = self.uri.split('?')
-
-        argstring = ""
-        if len(x) == 1:
-            self.path = self.uri
-        else:
-            if len(x) != 2:
-                from twisted.python import log
-                log.msg("May ignore parts of this invalid URI: %s"
-                        % repr(self.uri))
-            self.path, argstring = x[0], x[1]
-
-        # cache the client and server information, we'll need this later to be
-        # serialized and sent with the request so CGIs will work remotely
-        self.client = self.channel.transport.getPeer()
-        self.host = self.channel.transport.getHost()
-
-        # create dummy env for cgi.FieldStorage
-        env = {
-            'REQUEST_METHOD': self.method,
-            'QUERY_STRING': argstring,
-            }
-        form = cgi.FieldStorage(fp=self.content,
-                                environ=env,
-                                headers=self.received_headers)
-
-        # Argument processing
-
-        args = self.args
-        try:
-            keys = form.keys()
-        except TypeError:
-            pass
-        else:
-            for key in keys:
-                values = form[key]
-                if not isinstance(values, list):
-                    values = [values]
-                fixedResult = []
-                for i in values:
-                    if isinstance(i, cgi.FieldStorage) and i.filename:
-                        fixedResult.append(i.file)
-                        # multiple uploads to same form field are stupid!
-                        args[key + '__filename__'] = i.filename
-                    else:
-                        fixedResult.append(i.value)
-                args[key] = fixedResult
-
-        self.process()
-
-
-class MoinSite(server.Site):
-    """ Moin site """
-    requestFactory = MoinRequest
-
-    def startFactory(self):
-        """ Setup before starting """
-        # Memory profile
-        if config.memoryProfile:
-            config.memoryProfile.sample()
-
-        # hotshot profile
-        if config.hotshotProfile:
-            import hotshot
-            config.hotshotProfile = hotshot.Profile(config.hotshotProfile)
-        server.Site.startFactory(self)
-
-    def stopFactory(self):
-        """ Cleaup before stoping """
-        server.Site.stopFactory(self)
-        if config.hotshotProfile:
-            config.hotshotProfile.close()
-
-
-class TwistedConfig(Config):
-    """ Twisted server default config """
-
-    name = 'mointwisted'
-    properties = {}
-    docs = '/usr/share/moin/htdocs'
-    user = 'www-data'
-    group = 'www-data'
-    port = 8080
-    interfaces = ['']
-    threads = 10
-    timeout = 15 * 60 # 15 minutes
-    logPath_twisted = None # Twisted log file
-    virtualHosts = None
-    memoryProfile = None
-    hotshotProfile = None
-
-    # sslcert = ('/whereever/cert/sitekey.pem', '/whereever/cert/sitecert.pem')
-    sslcert = None
-
-    def __init__(self):
-        Config.__init__(self)
-
-        # Check for '' in interfaces, then ignore other
-        if '' in self.interfaces:
-            self.interfaces = ['']
-
-
-def makeApp(ConfigClass):
-    """ Generate and return an application
-
-    See MoinMoin.server.Config for config options
-
-    @param ConfigClass: config class
-    @rtype: application object
-    @return twisted application, needed by twistd
-    """
-    # Create config instance (raise RuntimeError if config invalid)
-    global config
-    config = ConfigClass()
-
-    # Set number of threads
-    reactor.suggestThreadPoolSize(config.threads)
-
-    # The root of the HTTP hierarchy
-    default = WikiRoot()
-
-    # Here is where img and css and some special files come from
-    default.putChild(config.url_prefix_static[1:], static.File(config.docs))
-
-    # Generate the Site factory
-    # TODO: Maybe we can use WikiRoot instead of this
-    # ----------------------------------------------
-    root = vhost.NameVirtualHost()
-    root.default = default
-    # ----------------------------------------------
-    site = MoinSite(root, logPath=config.logPath_twisted, timeout=config.timeout)
-
-    # Make application
-    application = service.Application("web", uid=config.uid, gid=config.gid)
-    sc = service.IServiceCollection(application)
-
-    # Listen to all interfaces in config.interfaces
-    for entry in config.interfaces:
-        # Add a TCPServer for each interface.
-
-        # This is an hidden experimantal feature: each entry in
-        # interface may contain a port, using 'ip:port'.
-        # Note: the format is subject to change!
-        try:
-            interface, port = entry.split(':', 1)
-        except ValueError:
-            interface, port = entry, config.port
-
-        # Might raise ValueError if not integer.
-        # TODO: check if we can use string port, like 'http'
-        port = int(port)
-
-        if port == 443 and ssl and ssl.supported and config.sslcert:
-            sslContext = ssl.DefaultOpenSSLContextFactory(*config.sslcert)
-            s = internet.SSLServer(port, site, sslContext, interface=interface)
-        else:
-            s = internet.TCPServer(port, site, interface=interface)
-        s.setServiceParent(sc)
-
-    return application
-
--- a/wiki/server/mointwisted	Thu Aug 07 20:46:33 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-#!/usr/bin/env python
-"""
-    mointwisted - control MoinMoin Twisted server
-
-    @copyright: 2004-2005 Thomas Waldmann, Nir Soffer
-    @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 mointwisted.py is located.
-#sys.path.insert(0, '/path/to/mointwisted')
-
-# 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 import daemon
-from mointwisted import Config
-
-
-class TwistedScript(daemon.DaemonScript):
-
-    def do_start(self):
-        """ Override to use twistd daemonizer """
-        os.system('twistd --python mointwisted.py --pidfile %s' % self.pidFile)
-
-
-script = TwistedScript(Config.name, None)
-script.run()
-
--- a/wiki/server/mointwisted.cmd	Thu Aug 07 20:46:33 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-@echo off
-
-rem moin twisted server startup script for Windows
-rem
-rem @copyright: 2004 Alexander Schremmer
-rem @license: GNU GPL, see COPYING for details.
-
-rem update the path of the scripts directory if needed
-"C:\Program Files\python23\Scripts\twistd" --python mointwisted.py
-
-
--- a/wiki/server/mointwisted.py	Thu Aug 07 20:46:33 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-"""
-    twisted.web based wiki server
-
-    Run this server with mointwisted script on Linux or Mac OS X, or
-    mointwisted.cmd on Windows.
-
-    @copyright: 2004-2005 Thomas Waldmann, Oliver Graf, Nir Soffer
-    @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_twisted import TwistedConfig, makeApp
-
-
-class Config(TwistedConfig):
-
-    # Server name - used to create .pid and .prof files
-    name = 'moin'
-
-    # Path to moin shared files (default '/usr/share/moin/wiki/htdocs')
-    docs = '/usr/share/moin/htdocs'
-
-    # URL prefix for the static stuff (used to access stuff in docs) - you
-    # usually should not need to change this because Twisted moin uses
-    # matching defaults for here and for wikiconfig.py:
-    #url_prefix_static = '/moin_static180'
-
-    # The server will run with as this user and group (default 'www-data')
-    user = 'www-data'
-    group = 'www-data'
-
-    # Port (default 8080)
-    # To serve privileged port under 1024 you will have to run as root
-    port = 8080
-
-    # Interfaces (default [''])
-    # The interfaces the server will listen to.
-    # [''] - listen to all interfaces defined on the server
-    # ['red.wikicolors.org', 'blue.wikicolors.org'] - listen to some
-    # If '' is in the list, other ignored.
-    interfaces = ['']
-
-    # How many threads to use (default 10, max 20)
-    # The more threads you use, the more memory moin uses. All thread
-    # use one CPU, and will not run faster, but might be more responsive
-    # on a very busy server.
-    threads = 10
-
-    # Set logfile name (default commented)
-    # This is the *Apache compatible* log file, not the twisted-style logfile.
-    # Leaving this as None will have no Apache compatible log file. Apache
-    # compatible logfiles are useful because there are quite a few programs
-    # which analyze them and display statistics.
-    ## logPath_twisted = 'mointwisted.log'
-
-    # Memory profile (default commented)
-    # Useful only if you are a developer or interested in moin memory usage
-    ## from MoinMoin.util.profile import TwistedProfiler
-    ## memoryProfile = TwistedProfiler('mointwisted',
-    ##                            requestsPerSample=100,
-    ##                            collect=0)
-
-    # Hotshot profile (default commented)
-    # Not compatible with threads.
-    ## hotshotProfile = name + '.prof'
-
-
-# Create the application
-application = makeApp(Config)
-