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

« back to all changes in this revision

Viewing changes to src/dispatch/request.py

  • Committer: mattgiuca
  • Date: 2007-12-12 05:31:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:43
src/common/util.py: Added functions unmake_path and split_path.
src/dispatch/request: Now properly writes "app" and "path" attributes.
src/dispatch: Test code now displays app separately from path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
# object.
25
25
 
26
26
import common.util
27
 
import mod_python
28
27
 
29
28
class Request:
30
29
    """An IVLE request object. This is presented to the IVLE apps as a way of
150
149
        self.title = None     # Will be set by dispatch before passing to app
151
150
        self.write_html_head_foot = False
152
151
 
153
 
    def __writeheaders(self):
154
 
        """Writes out the HTTP and HTML headers before any real data is
155
 
        written."""
156
 
        self.headers_written = True
157
 
        # Prepare the HTTP and HTML headers before the first write is made
158
 
        if self.content_type != None:
159
 
            self.apache_req.content_type = self.content_type
160
 
        self.apache_req.status = self.status
161
 
        if self.location != None:
162
 
            self.apache_req.headers_out['Location'] = self.location
163
 
        if self.write_html_head_foot:
164
 
            # Write the HTML header, pass "self" (request object)
165
 
            self.func_write_html_head(self)
166
 
 
167
 
    def ensure_headers_written(self):
168
 
        """Writes out the HTTP and HTML headers if they haven't already been
169
 
        written."""
170
 
        if not self.headers_written:
171
 
            self.__writeheaders()
172
 
 
173
152
    def write(self, string, flush=1):
174
153
        """Writes string directly to the client, then flushes the buffer,
175
154
        unless flush is 0."""
176
155
 
177
156
        if not self.headers_written:
178
 
            self.__writeheaders()
 
157
            self.headers_written = True
 
158
            # Prepare the HTTP and HTML headers before the first write is made
 
159
            if self.content_type != None:
 
160
                self.apache_req.content_type = self.content_type
 
161
            self.apache_req.status = self.status
 
162
            if self.location != None:
 
163
                self.apache_req.headers_out['Location'] = self.location
 
164
            if self.write_html_head_foot:
 
165
                # Write the HTML header, pass "self" (request object)
 
166
                self.func_write_html_head(self)
 
167
 
179
168
        self.apache_req.write(string, flush)
180
169
 
181
170
    def flush(self):
182
171
        """Flushes the output buffer."""
183
172
        self.apache_req.flush()
184
 
 
185
 
    def sendfile(self, filename):
186
 
        """Sends the named file directly to the client."""
187
 
        if not self.headers_written:
188
 
            self.__writeheaders()
189
 
        self.apache_req.sendfile(filename)
190
 
 
191
 
    def read(self, len=None):
192
 
        """Reads at most len bytes directly from the client. (See mod_python
193
 
        Request.read)."""
194
 
        if len is None:
195
 
            self.apache_req.read()
196
 
        else:
197
 
            self.apache_req.read(len)
198
 
 
199
 
    def throw_error(self, httpcode):
200
 
        """Writes out an HTTP error of the specified code. Raises an exception
201
 
        which is caught by the dispatch or web server, so any code following
202
 
        this call will not be executed.
203
 
 
204
 
        httpcode: An HTTP response status code. Pass a constant from the
205
 
        Request class.
206
 
        """
207
 
        raise mod_python.apache.SERVER_RETURN, httpcode
208
 
 
209
 
    def throw_redirect(self, location):
210
 
        """Writes out an HTTP redirect to the specified URL. Raises an
211
 
        exception which is caught by the dispatch or web server, so any
212
 
        code following this call will not be executed.
213
 
 
214
 
        httpcode: An HTTP response status code. Pass a constant from the
215
 
        Request class.
216
 
        """
217
 
        mod_python.util.redirect(self.apache_req, location)