view MoinMoin/request/ @ 4109:e88baf535b48

fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2. cfg.backup_exclude is now just a function of filename, telling whether the file should be excluded. By default, no file is excluded.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 19 Sep 2008 21:41:40 +0200
parents fee546fba271
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - WSGI Request Implementation for std. WSGI web servers.

    @copyright: 2001-2003 Juergen Hermann <>,
                2003-2006 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
import cgi, StringIO

from MoinMoin import log
logging = log.getLogger(__name__)

from MoinMoin.request import RequestBase, RemoteClosedConnection

class Request(RequestBase):
    """ specialized on WSGI requests """
    def __init__(self, env):
            self.env = env
            self.hasContentType = False

            self.stdin = env['wsgi.input']
            self.stdout = StringIO.StringIO()

            # used by MoinMoin.server.server_wsgi:
            self.status = '200 OK'
            self.headers = []

            # used by send_file()
            self._send_file = None
            self._send_bufsize = None

            RequestBase.__init__(self, {})

        except Exception, err:

    def _setup_args_from_cgi_form(self):
        """ Override to create cgi form """
        form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1)
        return RequestBase._setup_args_from_cgi_form(self, form)

    def read(self, n):
        if n is None:
            logging.warning("calling might block")

    def send_file(self, fileobj, bufsize=8192, do_flush=None):
        # For now, we just remember fileobj and bufsize for sending it later:
        self._send_file = fileobj
        self._send_bufsize = bufsize

    def write(self, *data):
        data = self.encode(data)
        except Exception:
            raise RemoteClosedConnection()

    def _emit_http_headers(self, headers):
        """ private method to send out preprocessed list of HTTP headers """
        st_header, other_headers = headers[0], headers[1:]
        self.status = st_header.split(':', 1)[1].lstrip()
        for header in other_headers:
            key, value = header.split(':', 1)
            value = value.lstrip()
            self.headers.append((key, value))

    def flush(self):

    def output(self):
        # called by MoinMoin.server.server_wsgi
        return self.stdout.getvalue()