view MoinMoin/request/ @ 4133:251827af7ddc

Fixed: cannot check for File.Error in same line like checking import of File
author Florian Krupicka <>
date Tue, 27 May 2008 18:13:17 +0200
parents dc7590f9c3b0
children fee546fba271
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - FastCGI Request Implementation for fastcgi and Apache
    (and maybe others).

    @copyright: 2001-2003 Juergen Hermann <>,
                2003-2006 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
from MoinMoin.request import RequestBase, RemoteClosedConnection

class Request(RequestBase):
    """ specialized on FastCGI requests """

    def __init__(self, fcgRequest, env, form, properties={}):
        """ Initializes variables from FastCGI environment and saves
            FastCGI request and form for further use.

            @param fcgRequest: the FastCGI request instance.
            @param env: environment passed by FastCGI.
            @param form: FieldStorage passed by FastCGI.
            self.fcgreq = fcgRequest
            self.fcgenv = env
            self.fcgform = form
            RequestBase.__init__(self, properties)

        except Exception, err:

    def _setup_args_from_cgi_form(self):
        """ Override to use FastCGI form """
        # thfcgi used keep_blank_values=1 internally for fcgform
        return RequestBase._setup_args_from_cgi_form(self, self.fcgform)

    def read(self, n=None):
        """ Read from input stream. """
        if n is None:

    def write(self, *data):
        """ Write to output stream. """
        data = self.encode(data)
        except Exception:
            raise RemoteClosedConnection()

    def send_file(self, fileobj, bufsize=8192, do_flush=True):
        # as thfcgi buffers everything we write until we do a flush, we use
        # do_flush=True as default here (otherwise the sending of big file
        # attachments would consume lots of memory)
        return RequestBase.send_file(self, fileobj, bufsize, do_flush)

    def flush(self):
        """ Flush output stream. """

    def finish(self):
        """ Call finish method of FastCGI request to finish handling of this request. """

    def _emit_http_headers(self, headers):
        """ private method to send out preprocessed list of HTTP headers """
        for header in headers:
            self.write("%s\r\n" % header)