annotate MoinMoin/request/request_modpython.py @ 4133:251827af7ddc

Fixed: cannot check for File.Error in same line like checking import of File
author Florian Krupicka <florian.krupicka@googlemail.com>
date Tue, 27 May 2008 18:13:17 +0200
parents 6fe1ea4d9d1a
children fee546fba271
rev   line source
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - mod_python Request Implementation for Apache and mod_python.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 2003-2006 MoinMoin:ThomasWaldmann
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9 from MoinMoin import wikiutil
3412
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
10 from MoinMoin.request import RequestBase, RemoteClosedConnection
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 class Request(RequestBase):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 """ specialized on mod_python requests """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14
2975
ea78a739b5ad imported patch fix-modpython-patch (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
15 def __init__(self, req, properties={}):
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 """ Saves mod_pythons request and sets basic variables using
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 the req.subprocess_env, cause this provides a standard
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 way to access the values we need here.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 @param req: the mod_python request instance
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 try:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 # flags if headers sent out contained content-type or status
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 self._have_ct = 0
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 self._have_status = 0
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 req.add_common_vars()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 self.mpyreq = req
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 # some mod_python 2.7.X has no get method for table objects,
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 # so we make a real dict out of it first.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 if not hasattr(req.subprocess_env, 'get'):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 env = dict(req.subprocess_env)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 else:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 env = req.subprocess_env
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 self._setup_vars_from_std_env(env)
2975
ea78a739b5ad imported patch fix-modpython-patch (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
36 RequestBase.__init__(self, properties)
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 except Exception, err:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 self.fail(err)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 def fixURI(self, env):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 """ Fix problems with script_name and path_info using
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 PythonOption directive to rewrite URI.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 This is needed when using Apache 1 or other server which does
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 not support adding custom headers per request. With mod_python we
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 can use the PythonOption directive:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 <Location /url/to/mywiki/>
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 PythonOption X-Moin-Location /url/to/mywiki/
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 </location>
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 Note that *neither* script_name *nor* path_info can be trusted
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 when Moin is invoked as a mod_python handler with apache1, so we
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 must build both using request_uri and the provided PythonOption.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 # Be compatible with release 1.3.5 "Location" option
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 # TODO: Remove in later release, we should have one option only.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 old_location = 'Location'
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 options_table = self.mpyreq.get_options()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 if not hasattr(options_table, 'get'):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 options = dict(options_table)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 else:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 options = options_table
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 location = options.get(self.moin_location) or options.get(old_location)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 if location:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 env[self.moin_location] = location
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 # Try to recreate script_name and path_info from request_uri.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 import urlparse
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 scriptAndPath = urlparse.urlparse(self.request_uri)[2]
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 self.script_name = location.rstrip('/')
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 path = scriptAndPath.replace(self.script_name, '', 1)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 self.path_info = wikiutil.url_unquote(path, want_unicode=False)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 RequestBase.fixURI(self, env)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 def _setup_args_from_cgi_form(self):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 """ Override to use mod_python.util.FieldStorage
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80 It's little different from cgi.FieldStorage, so we need to
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 duplicate the conversion code.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 from mod_python import util
3209
799875c9fe2d when setting up the request.form dict, make all request methods consistently use keep_blank_values=1 (see cgi.FieldStorage)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2975
diff changeset
84 form = util.FieldStorage(self.mpyreq, keep_blank_values=1) # by default this evaluates query string AND body POST data!
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 args = {}
2975
ea78a739b5ad imported patch fix-modpython-patch (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
87
ea78a739b5ad imported patch fix-modpython-patch (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
88 # You cannot get rid of .keys() here
ea78a739b5ad imported patch fix-modpython-patch (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2338
diff changeset
89 for key in form.keys():
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
90 if key is None:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
91 continue
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
92 values = form[key]
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
93 if not isinstance(values, list):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
94 values = [values]
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
95 fixedResult = []
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
96 for item in values:
3568
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
97 if isinstance(item, util.StringField):
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
98 fixedResult.append(item.value)
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
99 elif isinstance(item, util.Field) and item.filename:
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
100 fixedResult.append(item.file)
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
101 # Remember filenames with a name hack
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
102 args[key + '__filename__'] = item.filename
3568
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
103 elif isinstance(item, str):
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
104 # mod_python 2.7 might return strings instead of Field objects.
6fe1ea4d9d1a use the open temporary file for file uploads (fixes big memory consumption for big file uploads) - Twisted and mod_python is completely untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3412
diff changeset
105 fixedResult.append(item)
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
106 args[key] = fixedResult
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
107
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
108 return self.decodeArgs(args)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
109
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
110 def run(self, req):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
111 """ mod_python calls this with its request object. We don't
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
112 need it cause its already passed to __init__. So ignore
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
113 it and just return RequestBase.run.
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
114
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
115 @param req: the mod_python request instance
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
116 """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
117 return RequestBase.run(self)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
118
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
119 def read(self, n=None):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
120 """ Read from input stream. """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
121 if n is None:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
122 return self.mpyreq.read()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
123 else:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
124 return self.mpyreq.read(n)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
125
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
126 def write(self, *data):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
127 """ Write to output stream. """
3412
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
128 data = self.encode(data)
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
129 try:
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
130 self.mpyreq.write(data)
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
131 except Exception:
91d38a790d8e request framework: handle connection aborts gracefully
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3209
diff changeset
132 raise RemoteClosedConnection()
2338
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
133
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
134 def flush(self):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
135 """ We can't flush it, so do nothing. """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
136 pass
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
137
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
138 def finish(self):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
139 """ Just return apache.OK. Status is set in req.status. """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
140 RequestBase.finish(self)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
141 # is it possible that we need to return something else here?
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
142 from mod_python import apache
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
143 return apache.OK
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
144
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
145 def _emit_http_headers(self, headers):
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
146 """ private method to send out preprocessed list of HTTP headers """
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
147 st_header, ct_header, other_headers = headers[0], headers[1], headers[2:]
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
148 status = st_header.split(':', 1)[1].lstrip()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
149 self.mpyreq.status = int(status.split(' ', 1)[0])
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
150 self.mpyreq.content_type = ct_header.split(':', 1)[1].lstrip()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
151 for header in other_headers:
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
152 key, value = header.split(':', 1)
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
153 value = value.lstrip()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
154 self.mpyreq.headers_out[key] = value
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
155 # this is for mod_python 2.7.X, for 3.X it's a NOP
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
156 self.mpyreq.send_http_header()
b902f2397c68 rename server and request Implementations by adding a prefix server_, request_
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
157