~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-19 00:54:28 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:500
db: get_user and get_users now return User objects instead of dictionaries.
    This is the major part of replacing dicts with User objects, as it
    propagates upwards.

Propagated User objects up through the following modules:
    listusers.py, dispatch.login, authenticate, userservice, forumutil
All of these now treat users as an object rather than a dict.

To save on the size of the changes so far, login still individually copies
fields over to the session (so the session does not yet store a user object;
that is the second part of this refactor).

WOO!! Revision 500 :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import common.util
27
27
import mod_python
28
 
from mod_python import (util, Session)
 
28
from mod_python import (util, Session, Cookie)
29
29
import conf
30
30
 
31
31
class Request:
224
224
 
225
225
        if not self.headers_written:
226
226
            self.__writeheaders()
227
 
        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)
228
235
 
229
236
    def flush(self):
230
237
        """Flushes the output buffer."""
264
271
        """
265
272
        mod_python.util.redirect(self.apache_req, location)
266
273
 
 
274
    def add_cookie(self, cookie, value=None, **attributes):
 
275
        """Inserts a cookie into this request object's headers."""
 
276
        if value is None:
 
277
            Cookie.add_cookie(self.apache_req, cookie)
 
278
        else:
 
279
            Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
 
280
 
267
281
    def get_session(self):
268
282
        """Returns a mod_python Session object for this request.
269
283
        Note that this is dependent on mod_python and may need to change
270
284
        interface if porting away from mod_python."""
271
 
        # Cache the session object
 
285
        # Cache the session object and set the timeout to 24 hours.
272
286
        if not hasattr(self, 'session'):
273
 
            self.session = Session.Session(self.apache_req)
 
287
            self.session = Session.FileSession(self.apache_req,
 
288
                                               timeout = 60 * 60 * 24)
274
289
        return self.session
275
290
 
276
291
    def get_fieldstorage(self):