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

« back to all changes in this revision

Viewing changes to lib/common/cgirequest.py

  • Committer: mattgiuca
  • Date: 2008-02-24 22:09:16 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:553
Added new app: Settings (UI for userservice).
    (Added app dir, media dir with empty JS file, icon).
apps/__init__.py: Added error message.
dispatch/__init__.py: Added error message.
dispatch/html.py: Added link to Settings at the top
    (a special app).
    Fixed HTML icons (correct size link).
    Catch keyerror on icon which would otherwise be thrown all
    the way up on certain errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
 
124
124
        if ('SERVER_NAME' not in os.environ or
125
125
            'REQUEST_METHOD' not in os.environ or
126
 
            'SCRIPT_NAME' not in os.environ or
127
 
            'PATH_INFO' not in os.environ):
 
126
            'REQUEST_URI' not in os.environ):
128
127
            raise Exception("No CGI environment found")
129
128
 
130
129
        # Determine if the browser used the public host name to make the
136
135
 
137
136
        # Inherit values for the input members
138
137
        self.method = os.environ['REQUEST_METHOD']
139
 
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
 
138
        self.uri = os.environ['REQUEST_URI']
140
139
        # Split the given path into the app (top-level dir) and sub-path
141
140
        # (after first stripping away the root directory)
142
141
        path = common.util.unmake_path(self.uri)
143
142
        if self.publicmode:
144
143
            self.app = None
145
 
            (_, self.path) = (common.util.split_path(path))
 
144
            self.path = path
146
145
        else:
147
146
            (self.app, self.path) = (common.util.split_path(path))
148
147
        self.user = None
243
242
        else:
244
243
            return sys.stdin.read(len)
245
244
 
246
 
    def throw_error(self, httpcode, message):
 
245
    def throw_error(self, httpcode):
247
246
        """Writes out an HTTP error of the specified code. Exits the process,
248
247
        so any code following this call will not be executed.
249
248
 
254
253
        httpcode: An HTTP response status code. Pass a constant from the
255
254
        Request class.
256
255
        """
257
 
        raise common.util.IVLEError(httpcode, message)
 
256
        self.status = httpcode
 
257
        self.content_type = "text/html"
 
258
        # Emulate an Apache error
 
259
        self.write("""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 
260
<html><head>
 
261
<title>%d Error</title>
 
262
</head><body>
 
263
<h1>Error</h1>
 
264
<p>A %d error was triggered by a CGI app.</p>
 
265
</body></html>
 
266
""" % (httpcode, httpcode))
 
267
        # Exit the process completely
 
268
        self.flush()
 
269
        sys.exit(httpcode)
258
270
 
259
271
    def throw_redirect(self, location):
260
272
        """Writes out an HTTP redirect to the specified URL. Exits the