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

« back to all changes in this revision

Viewing changes to lib/common/cgirequest.py

  • Committer: wagrant
  • Date: 2008-07-17 04:47:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:907
browser: Display the current revision next to the current path if the
         former is set.

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
34
36
 
35
37
import conf
36
38
import common
123
125
 
124
126
        if ('SERVER_NAME' not in os.environ or
125
127
            'REQUEST_METHOD' not in os.environ or
126
 
            'REQUEST_URI' not in os.environ):
 
128
            'SCRIPT_NAME' not in os.environ or
 
129
            'PATH_INFO' not in os.environ):
127
130
            raise Exception("No CGI environment found")
128
131
 
129
132
        # Determine if the browser used the public host name to make the
135
138
 
136
139
        # Inherit values for the input members
137
140
        self.method = os.environ['REQUEST_METHOD']
138
 
        self.uri = os.environ['REQUEST_URI']
 
141
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
139
142
        # Split the given path into the app (top-level dir) and sub-path
140
143
        # (after first stripping away the root directory)
141
144
        path = common.util.unmake_path(self.uri)
142
145
        if self.publicmode:
143
146
            self.app = None
144
 
            self.path = path
 
147
            (_, self.path) = (common.util.split_path(path))
145
148
        else:
146
149
            (self.app, self.path) = (common.util.split_path(path))
147
150
        self.user = None
159
162
        self.write_html_head_foot = False
160
163
        self.got_common_vars = False
161
164
 
 
165
 
 
166
    def install_error_handler(self):
 
167
        '''Install our exception handler as the default.'''
 
168
        sys.excepthook = self.handle_unknown_exception
 
169
 
162
170
    def __writeheaders(self):
163
171
        """Writes out the HTTP and HTML headers before any real data is
164
172
        written."""
255
263
        """
256
264
        raise common.util.IVLEError(httpcode, message)
257
265
 
 
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
 
258
285
    def throw_redirect(self, location):
259
286
        """Writes out an HTTP redirect to the specified URL. Exits the
260
287
        process, so any code following this call will not be executed.