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

« back to all changes in this revision

Viewing changes to www/dispatch/request.py

  • Committer: stevenbird
  • Date: 2008-02-19 21:17:21 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:512
Renaming of problems to exercises (initial commit).
Fix up module naming (exercises sometimes called tutorials).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import mod_python
28
28
from mod_python import (util, Session, Cookie)
29
29
import conf
30
 
import plugins.console
31
30
 
32
31
class Request:
33
32
    """An IVLE request object. This is presented to the IVLE apps as a way of
81
80
            in the head, if write_html_head_foot is True.
82
81
            URLs should be relative to the IVLE root; they will be fixed up
83
82
            to be site-relative.
84
 
        scripts_init (write)
85
 
            List of strings. Write a list of JS function names, and they
86
 
            will be added as window.addListener('load', ..., false); calls
87
 
            in the head, if write_html_head_foot is True.
88
 
            This is the propper way to specify functions that need to run at 
89
 
            page load time.
90
83
        write_html_head_foot (write)
91
84
            Boolean. If True, dispatch assumes that this is an XHTML page, and
92
85
            will immediately write a full HTML head, open the body element,
187
180
        path = common.util.unmake_path(req.uri)
188
181
        if self.publicmode:
189
182
            self.app = None
190
 
            (_, self.path) = (common.util.split_path(path))
 
183
            self.path = path
191
184
        else:
192
185
            (self.app, self.path) = (common.util.split_path(path))
193
186
        self.user = None
202
195
        self.title = None     # Will be set by dispatch before passing to app
203
196
        self.styles = []
204
197
        self.scripts = []
205
 
        self.scripts_init = []
206
198
        self.write_html_head_foot = False
207
199
        self.got_common_vars = False
208
200
 
210
202
        """Writes out the HTTP and HTML headers before any real data is
211
203
        written."""
212
204
        self.headers_written = True
213
 
        
214
 
        # app is the App object for the chosen app
215
 
        try:
216
 
            app = conf.apps.app_url[self.app]
217
 
        except KeyError:
218
 
            app = None
219
 
 
220
 
        # Write any final modifications to header content
221
 
        if app and app.useconsole and self.user:
222
 
            plugins.console.insert_scripts_styles(self.scripts, self.styles, \
223
 
                self.scripts_init)
224
 
 
225
205
        # Prepare the HTTP and HTML headers before the first write is made
226
206
        if self.content_type != None:
227
207
            self.apache_req.content_type = self.content_type
271
251
        else:
272
252
            return self.apache_req.read(len)
273
253
 
274
 
    def throw_error(self, httpcode, message=None):
 
254
    def throw_error(self, httpcode):
275
255
        """Writes out an HTTP error of the specified code. Raises an exception
276
256
        which is caught by the dispatch or web server, so any code following
277
257
        this call will not be executed.
279
259
        httpcode: An HTTP response status code. Pass a constant from the
280
260
        Request class.
281
261
        """
282
 
        raise common.util.IVLEError(httpcode, message)
 
262
        raise mod_python.apache.SERVER_RETURN, httpcode
283
263
 
284
264
    def throw_redirect(self, location):
285
265
        """Writes out an HTTP redirect to the specified URL. Raises an
325
305
            self.apache_req.add_common_vars()
326
306
            self.got_common_vars = True
327
307
        return self.apache_req.subprocess_env
328
 
 
329
 
    @staticmethod
330
 
    def get_http_codename(code):
331
 
        """Given a HTTP error code int, returns a (name, description)
332
 
        pair, suitable for displaying to the user.
333
 
        May return (None,None) if code is unknown.
334
 
        Only lists common 4xx and 5xx codes (since this is just used
335
 
        to display throw_error error messages).
336
 
        """
337
 
        try:
338
 
            return http_codenames[code]
339
 
        except KeyError:
340
 
            return None, None
341
 
 
342
 
# Human strings for HTTP response codes
343
 
http_codenames = {
344
 
    Request.HTTP_BAD_REQUEST:
345
 
        ("Bad Request",
346
 
        "Your browser sent a request IVLE did not understand."),
347
 
    Request.HTTP_UNAUTHORIZED:
348
 
        ("Unauthorized",
349
 
        "You are not allowed to view this part of IVLE."),
350
 
    Request.HTTP_FORBIDDEN:
351
 
        ("Forbidden",
352
 
        "You are not allowed to view this part of IVLE."),
353
 
    Request.HTTP_NOT_FOUND:
354
 
        ("Not Found",
355
 
        "The application or file you requested does not exist."),
356
 
    Request.HTTP_METHOD_NOT_ALLOWED:
357
 
        ("Method Not Allowed",
358
 
        "Your browser is interacting with IVLE in the wrong way."
359
 
        "This is probably a bug in IVLE. "
360
 
        "Please report it to the administrators."),
361
 
    Request.HTTP_INTERNAL_SERVER_ERROR:
362
 
        ("Internal Server Error",
363
 
        "An unknown error occured in IVLE."),
364
 
    Request.HTTP_NOT_IMPLEMENTED:
365
 
        ("Not Implemented",
366
 
        "The application or file you requested has not been implemented "
367
 
        "in IVLE."),
368
 
    Request.HTTP_SERVICE_UNAVAILABLE:
369
 
        ("Service Unavailable",
370
 
        "IVLE is currently experiencing technical difficulties. "
371
 
        "Please try again later."),
372
 
}