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

« back to all changes in this revision

Viewing changes to lib/common/cgirequest.py

  • Committer: mattgiuca
  • Date: 2008-04-17 07:24:01 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:736
Added new script "marks.py" which computes the marks for all students and outputs it as a CSV file.
This borrows a lot of code from tutorial/__init__.py which should be factored out.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import sys
32
32
import os
33
33
import cgi
34
 
import urllib
35
 
import traceback
36
34
 
37
35
import conf
38
36
import common
125
123
 
126
124
        if ('SERVER_NAME' not in os.environ or
127
125
            'REQUEST_METHOD' not in os.environ or
128
 
            'SCRIPT_NAME' not in os.environ or
129
 
            'PATH_INFO' not in os.environ):
 
126
            'REQUEST_URI' not in os.environ):
130
127
            raise Exception("No CGI environment found")
131
128
 
132
129
        # Determine if the browser used the public host name to make the
138
135
 
139
136
        # Inherit values for the input members
140
137
        self.method = os.environ['REQUEST_METHOD']
141
 
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
 
138
        self.uri = os.environ['REQUEST_URI']
142
139
        # Split the given path into the app (top-level dir) and sub-path
143
140
        # (after first stripping away the root directory)
144
141
        path = common.util.unmake_path(self.uri)
162
159
        self.write_html_head_foot = False
163
160
        self.got_common_vars = False
164
161
 
165
 
 
166
 
    def install_error_handler(self):
167
 
        '''Install our exception handler as the default.'''
168
 
        sys.excepthook = self.handle_unknown_exception
169
 
 
170
162
    def __writeheaders(self):
171
163
        """Writes out the HTTP and HTML headers before any real data is
172
164
        written."""
263
255
        """
264
256
        raise common.util.IVLEError(httpcode, message)
265
257
 
266
 
    def handle_unknown_exception(self, exc_type, exc_value, exc_tb):
267
 
        if exc_type is common.util.IVLEError:
268
 
            self.headers_out['X-IVLE-Error-Code'] = exc_value.httpcode
269
 
 
270
 
        self.headers_out['X-IVLE-Error-Type'] = exc_type.__name__
271
 
 
272
 
        try:
273
 
            self.headers_out['X-IVLE-Error-Message'] = exc_value.message
274
 
        except AttributeError:
275
 
            pass
276
 
 
277
 
        self.headers_out['X-IVLE-Error-Info'] = urllib.quote(''.join(
278
 
              traceback.format_exception(exc_type, exc_value, exc_tb)))
279
 
        self.status = 500
280
 
        self.ensure_headers_written()
281
 
        self.write('An internal IVLE error has occurred.')
282
 
        self.flush()
283
 
        sys.exit(self.status)
284
 
 
285
258
    def throw_redirect(self, location):
286
259
        """Writes out an HTTP redirect to the specified URL. Exits the
287
260
        process, so any code following this call will not be executed.