~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to src/dispatch/request.py

  • Committer: mattgiuca
  • Date: 2007-12-12 01:38:59 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:37
Added src/dispatch/request.py: The IVLE Request class.
dispatch module now transforms the Apache request object into an IVLE one, and
goes through it. (Note this temporarily means the content type is no longer
set, because the request object is missing functionality).

Added brief description of this object in notes/apps/dispatch.txt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2008 The University of Melbourne
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
 
 
18
# Module: dispatch.request
 
19
# Author: Matt Giuca
 
20
# Date:   12/12/2007
 
21
 
 
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
 
24
# object.
 
25
 
 
26
class 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."""
 
29
 
 
30
    # Special code for "everything's OK" (somehow different to 200).
 
31
    OK  = 0
 
32
 
 
33
    # HTTP status codes
 
34
 
 
35
    HTTP_CONTINUE                     = 100
 
36
    HTTP_SWITCHING_PROTOCOLS          = 101
 
37
    HTTP_PROCESSING                   = 102
 
38
    HTTP_OK                           = 200
 
39
    HTTP_CREATED                      = 201
 
40
    HTTP_ACCEPTED                     = 202
 
41
    HTTP_NON_AUTHORITATIVE            = 203
 
42
    HTTP_NO_CONTENT                   = 204
 
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
 
49
    HTTP_SEE_OTHER                    = 303
 
50
    HTTP_NOT_MODIFIED                 = 304
 
51
    HTTP_USE_PROXY                    = 305
 
52
    HTTP_TEMPORARY_REDIRECT           = 307
 
53
    HTTP_BAD_REQUEST                  = 400
 
54
    HTTP_UNAUTHORIZED                 = 401
 
55
    HTTP_PAYMENT_REQUIRED             = 402
 
56
    HTTP_FORBIDDEN                    = 403
 
57
    HTTP_NOT_FOUND                    = 404
 
58
    HTTP_METHOD_NOT_ALLOWED           = 405
 
59
    HTTP_NOT_ACCEPTABLE               = 406
 
60
    HTTP_PROXY_AUTHENTICATION_REQUIRED= 407
 
61
    HTTP_REQUEST_TIME_OUT             = 408
 
62
    HTTP_CONFLICT                     = 409
 
63
    HTTP_GONE                         = 410
 
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
 
72
    HTTP_LOCKED                       = 423
 
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
 
83
 
 
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
 
87
        additional fields.
 
88
 
 
89
        req: A mod_python request object.
 
90
        """
 
91
 
 
92
        # Methods are mostly wrappers around the Apache request object
 
93
        self.apache_req = req
 
94
 
 
95
        # Inherit values for the input members
 
96
        self.uri = req.uri
 
97
 
 
98
        # Default values for the output members
 
99
        self.status = Request.OK
 
100
        self.content_type = None        # Use Apache's default
 
101
        self.location = None
 
102
        self.title = None     # Will be set by dispatch before passing to app
 
103
        self.write_html_head_foot = False
 
104
 
 
105
    def write(self, string, flush=1):
 
106
        """Writes string directly to the client, then flushes the buffer,
 
107
        unless flush is 0."""
 
108
 
 
109
        # TODO: Prepare the IVLE HTTP and HTML headers before the first write.
 
110
        self.apache_req.write(string, flush)
 
111
 
 
112
    def flush(self):
 
113
        """Flushes the output buffer."""
 
114
        self.apache_req.flush()