150
149
self.title = None # Will be set by dispatch before passing to app
151
150
self.write_html_head_foot = False
153
def __writeheaders(self):
154
"""Writes out the HTTP and HTML headers before any real data is
156
self.headers_written = True
157
# Prepare the HTTP and HTML headers before the first write is made
158
if self.content_type != None:
159
self.apache_req.content_type = self.content_type
160
self.apache_req.status = self.status
161
if self.location != None:
162
self.apache_req.headers_out['Location'] = self.location
163
if self.write_html_head_foot:
164
# Write the HTML header, pass "self" (request object)
165
self.func_write_html_head(self)
167
def ensure_headers_written(self):
168
"""Writes out the HTTP and HTML headers if they haven't already been
170
if not self.headers_written:
171
self.__writeheaders()
173
152
def write(self, string, flush=1):
174
153
"""Writes string directly to the client, then flushes the buffer,
175
154
unless flush is 0."""
177
156
if not self.headers_written:
178
self.__writeheaders()
157
self.headers_written = True
158
# Prepare the HTTP and HTML headers before the first write is made
159
if self.content_type != None:
160
self.apache_req.content_type = self.content_type
161
self.apache_req.status = self.status
162
if self.location != None:
163
self.apache_req.headers_out['Location'] = self.location
164
if self.write_html_head_foot:
165
# Write the HTML header, pass "self" (request object)
166
self.func_write_html_head(self)
179
168
self.apache_req.write(string, flush)
182
171
"""Flushes the output buffer."""
183
172
self.apache_req.flush()
185
def sendfile(self, filename):
186
"""Sends the named file directly to the client."""
187
if not self.headers_written:
188
self.__writeheaders()
189
self.apache_req.sendfile(filename)
191
def read(self, len=None):
192
"""Reads at most len bytes directly from the client. (See mod_python
195
self.apache_req.read()
197
self.apache_req.read(len)
199
def throw_error(self, httpcode):
200
"""Writes out an HTTP error of the specified code. Raises an exception
201
which is caught by the dispatch or web server, so any code following
202
this call will not be executed.
204
httpcode: An HTTP response status code. Pass a constant from the
207
raise mod_python.apache.SERVER_RETURN, httpcode
209
def throw_redirect(self, location):
210
"""Writes out an HTTP redirect to the specified URL. Raises an
211
exception which is caught by the dispatch or web server, so any
212
code following this call will not be executed.
214
httpcode: An HTTP response status code. Pass a constant from the
217
mod_python.util.redirect(self.apache_req, location)