~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/request/request_fcgi.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - FastCGI Request Implementation for fastcgi and Apache
 
4
    (and maybe others).
 
5
 
 
6
    @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
 
7
                2003-2006 MoinMoin:ThomasWaldmann
 
8
    @license: GNU GPL, see COPYING for details.
 
9
"""
 
10
from MoinMoin import log
 
11
logging = log.getLogger(__name__)
 
12
 
 
13
from MoinMoin.request import RequestBase, RemoteClosedConnection
 
14
 
 
15
class Request(RequestBase):
 
16
    """ specialized on FastCGI requests """
 
17
 
 
18
    def __init__(self, fcgRequest, env, form, properties={}):
 
19
        """ Initializes variables from FastCGI environment and saves
 
20
            FastCGI request and form for further use.
 
21
 
 
22
            @param fcgRequest: the FastCGI request instance.
 
23
            @param env: environment passed by FastCGI.
 
24
            @param form: FieldStorage passed by FastCGI.
 
25
        """
 
26
        try:
 
27
            self.fcgreq = fcgRequest
 
28
            self.fcgenv = env
 
29
            self.fcgform = form
 
30
            self._setup_vars_from_std_env(env)
 
31
            RequestBase.__init__(self, properties)
 
32
 
 
33
        except Exception, err:
 
34
            self.fail(err)
 
35
 
 
36
    def _setup_args_from_cgi_form(self):
 
37
        """ Override to use FastCGI form """
 
38
        # thfcgi used keep_blank_values=1 internally for fcgform
 
39
        return RequestBase._setup_args_from_cgi_form(self, self.fcgform)
 
40
 
 
41
    def read(self, n):
 
42
        """ Read from input stream. """
 
43
        if n is None:
 
44
            logging.warning("calling request.read(None) might block")
 
45
            return self.fcgreq.stdin.read()
 
46
        else:
 
47
            return self.fcgreq.stdin.read(n)
 
48
 
 
49
    def write(self, *data):
 
50
        """ Write to output stream. """
 
51
        data = self.encode(data)
 
52
        try:
 
53
            self.fcgreq.out.write(data)
 
54
        except Exception:
 
55
            raise RemoteClosedConnection()
 
56
 
 
57
    def send_file(self, fileobj, bufsize=8192, do_flush=True):
 
58
        # as thfcgi buffers everything we write until we do a flush, we use
 
59
        # do_flush=True as default here (otherwise the sending of big file
 
60
        # attachments would consume lots of memory)
 
61
        return RequestBase.send_file(self, fileobj, bufsize, do_flush)
 
62
 
 
63
    def flush(self):
 
64
        """ Flush output stream. """
 
65
        self.fcgreq.flush_out()
 
66
 
 
67
    def finish(self):
 
68
        """ Call finish method of FastCGI request to finish handling of this request. """
 
69
        RequestBase.finish(self)
 
70
        self.fcgreq.finish()
 
71
 
 
72
    def _emit_http_headers(self, headers):
 
73
        """ private method to send out preprocessed list of HTTP headers """
 
74
        for header in headers:
 
75
            self.write("%s\r\n" % header)
 
76
        self.write("\r\n")
 
77