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

« back to all changes in this revision

Viewing changes to www/dispatch/request.py

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import common.util
27
27
import mod_python
28
28
from mod_python import (util, Session)
 
29
import conf
29
30
 
30
31
class Request:
31
32
    """An IVLE request object. This is presented to the IVLE apps as a way of
51
52
            Table object representing headers sent by the client.
52
53
        headers_out (read, can be written to)
53
54
            Table object representing headers to be sent to the client.
 
55
        publicmode (read)
 
56
            Bool. True if the request came for the "public host" as
 
57
            configured in conf.py. Note that public mode requests do not
 
58
            have an app (app is set to None).
54
59
 
55
60
        status (write)
56
61
            Int. Response status number. Use one of the status codes defined
160
165
        self.func_write_html_head = write_html_head
161
166
        self.headers_written = False
162
167
 
 
168
        # Determine if the browser used the public host name to make the
 
169
        # request (in which case we are in "public mode")
 
170
        if req.hostname == conf.public_host:
 
171
            self.publicmode = True
 
172
        else:
 
173
            self.publicmode = False
 
174
 
163
175
        # Inherit values for the input members
164
176
        self.method = req.method
165
177
        self.uri = req.uri
166
178
        # Split the given path into the app (top-level dir) and sub-path
167
179
        # (after first stripping away the root directory)
168
 
        (self.app, self.path) = (
169
 
            common.util.split_path(common.util.unmake_path(req.uri)))
 
180
        path = common.util.unmake_path(req.uri)
 
181
        if self.publicmode:
 
182
            self.app = None
 
183
            self.path = path
 
184
        else:
 
185
            (self.app, self.path) = (common.util.split_path(path))
170
186
        self.username = None
171
187
        self.hostname = req.hostname
172
188
        self.headers_in = req.headers_in
208
224
 
209
225
        if not self.headers_written:
210
226
            self.__writeheaders()
211
 
        self.apache_req.write(string, flush)
 
227
        if isinstance(string, unicode):
 
228
            # Encode unicode strings as UTF-8
 
229
            # (Otherwise cannot handle being written to a bytestream)
 
230
            self.apache_req.write(string.encode('utf8'), flush)
 
231
        else:
 
232
            # 8-bit clean strings just get written directly.
 
233
            # This includes binary strings.
 
234
            self.apache_req.write(string, flush)
212
235
 
213
236
    def flush(self):
214
237
        """Flushes the output buffer."""
254
277
        interface if porting away from mod_python."""
255
278
        # Cache the session object
256
279
        if not hasattr(self, 'session'):
257
 
            self.session = Session.Session(self.apache_req)
 
280
            self.session = Session.FileSession(self.apache_req)
258
281
        return self.session
259
282
 
260
283
    def get_fieldstorage(self):