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

« back to all changes in this revision

Viewing changes to ivle/cgirequest.py

  • Committer: Matt Giuca
  • Date: 2009-01-19 17:28:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: matt.giuca@gmail.com-20090119172859-htjq3rfpp0fhtpc9
ivle.worksheet: Added calculate_score. This is a nice clean Storm port of
    ivle.db.calculate_worksheet_score.
tutorial: Replaced use of ivle.db.calculate_worksheet_score with
    ivle.worksheet.calculate_score.
    Guess What!! Removed this module's dependency on ivle.db! Hooray!
    (Note: tutorialservice still depends on it).
bin/ivle-marks: Updated this script to use ivle.worksheet_calculate_score.
    Note that this DOES NOT execute properly -- it seems it didn't even
    before my changes (tries to call db.get_users). Not my fault; I'm
    committing and going to bed!
ivle.db: Removed calculate_worksheet_score.
    As this removes the dependency on get_problem_status, removed that too!
    Almost all the worksheet stuff is gone now!

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# This allows CGI scripts to create request objects and then pass them to
26
26
# normal IVLE handlers.
27
27
 
 
28
# NOTE: This object does not support write_html_head_foot (simply because we
 
29
# do not need it in its intended application: fileservice).
 
30
 
28
31
import sys
29
32
import os
30
 
import os.path
31
33
import cgi
32
34
import urllib
33
35
import traceback
138
140
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
139
141
        # Split the given path into the app (top-level dir) and sub-path
140
142
        # (after first stripping away the root directory)
 
143
        path = ivle.util.unmake_path(self.uri)
141
144
        if self.publicmode:
142
145
            self.app = None
143
 
            (_, self.path) = (ivle.util.split_path(self.uri))
 
146
            (_, self.path) = (ivle.util.split_path(path))
144
147
        else:
145
 
            (self.app, self.path) = (ivle.util.split_path(self.uri))
 
148
            (self.app, self.path) = (ivle.util.split_path(path))
146
149
        self.user = None
147
150
        self.hostname = os.environ['SERVER_NAME']
148
151
        self.headers_in = _http_headers_in_from_cgi()
152
155
        self.status = CGIRequest.HTTP_OK
153
156
        self.content_type = None        # Use Apache's default
154
157
        self.location = None
 
158
        self.title = None     # Will be set by dispatch before passing to app
155
159
        self.styles = []
156
160
        self.scripts = []
 
161
        self.write_html_head_foot = False
157
162
        self.got_common_vars = False
158
163
 
159
164
 
192
197
            if k != 'Content-Type' and k != 'Location':
193
198
                print "%s: %s" % (k, v)
194
199
 
 
200
        # XXX write_html_head_foot not supported
 
201
        #if self.write_html_head_foot:
 
202
        #    # Write the HTML header, pass "self" (request object)
 
203
        #    self.func_write_html_head(self)
195
204
        # Print a blank line to signal the start of output
196
205
        print
197
206
 
240
249
        else:
241
250
            return sys.stdin.read(len)
242
251
 
 
252
    def throw_error(self, httpcode, message):
 
253
        """Writes out an HTTP error of the specified code. Exits the process,
 
254
        so any code following this call will not be executed.
 
255
 
 
256
        (This is justified because of the nature of CGI, it is a single-script
 
257
        environment, there is no containing process which needs to catch an
 
258
        exception).
 
259
 
 
260
        httpcode: An HTTP response status code. Pass a constant from the
 
261
        Request class.
 
262
        """
 
263
        raise ivle.util.IVLEError(httpcode, message)
 
264
 
243
265
    def handle_unknown_exception(self, exc_type, exc_value, exc_tb):
 
266
        if exc_type is ivle.util.IVLEError:
 
267
            self.headers_out['X-IVLE-Error-Code'] = exc_value.httpcode
 
268
 
244
269
        self.headers_out['X-IVLE-Error-Type'] = exc_type.__name__
245
270
 
246
271
        try: