1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Module: dispatch.request
22
# Builds an IVLE request object from a mod_python request object.
23
# See design notes/apps/dispatch.txt for a full specification of this request
27
"""An IVLE request object. This is presented to the IVLE apps as a way of
28
interacting with the web server and the dispatcher."""
30
# Special code for "everything's OK" (somehow different to 200).
36
HTTP_SWITCHING_PROTOCOLS = 101
41
HTTP_NON_AUTHORITATIVE = 203
43
HTTP_RESET_CONTENT = 205
44
HTTP_PARTIAL_CONTENT = 206
45
HTTP_MULTI_STATUS = 207
46
HTTP_MULTIPLE_CHOICES = 300
47
HTTP_MOVED_PERMANENTLY = 301
48
HTTP_MOVED_TEMPORARILY = 302
50
HTTP_NOT_MODIFIED = 304
52
HTTP_TEMPORARY_REDIRECT = 307
53
HTTP_BAD_REQUEST = 400
54
HTTP_UNAUTHORIZED = 401
55
HTTP_PAYMENT_REQUIRED = 402
58
HTTP_METHOD_NOT_ALLOWED = 405
59
HTTP_NOT_ACCEPTABLE = 406
60
HTTP_PROXY_AUTHENTICATION_REQUIRED= 407
61
HTTP_REQUEST_TIME_OUT = 408
64
HTTP_LENGTH_REQUIRED = 411
65
HTTP_PRECONDITION_FAILED = 412
66
HTTP_REQUEST_ENTITY_TOO_LARGE = 413
67
HTTP_REQUEST_URI_TOO_LARGE = 414
68
HTTP_UNSUPPORTED_MEDIA_TYPE = 415
69
HTTP_RANGE_NOT_SATISFIABLE = 416
70
HTTP_EXPECTATION_FAILED = 417
71
HTTP_UNPROCESSABLE_ENTITY = 422
73
HTTP_FAILED_DEPENDENCY = 424
74
HTTP_INTERNAL_SERVER_ERROR = 500
75
HTTP_NOT_IMPLEMENTED = 501
76
HTTP_BAD_GATEWAY = 502
77
HTTP_SERVICE_UNAVAILABLE = 503
78
HTTP_GATEWAY_TIME_OUT = 504
79
HTTP_VERSION_NOT_SUPPORTED = 505
80
HTTP_VARIANT_ALSO_VARIES = 506
81
HTTP_INSUFFICIENT_STORAGE = 507
82
HTTP_NOT_EXTENDED = 510
84
def __init__(self, req):
85
"""Builds an IVLE request object from a mod_python request object.
86
This results in an object with all of the necessary methods and
89
req: A mod_python request object.
92
# Methods are mostly wrappers around the Apache request object
95
# Inherit values for the input members
98
# Default values for the output members
99
self.status = Request.OK
100
self.content_type = None # Use Apache's default
102
self.title = None # Will be set by dispatch before passing to app
103
self.write_html_head_foot = False
105
def write(self, string, flush=1):
106
"""Writes string directly to the client, then flushes the buffer,
107
unless flush is 0."""
109
# TODO: Prepare the IVLE HTTP and HTML headers before the first write.
110
self.apache_req.write(string, flush)
113
"""Flushes the output buffer."""
114
self.apache_req.flush()