/[glsr]/trunk/glsr_framework/request.py
Gentoo

Contents of /trunk/glsr_framework/request.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 176 - (show annotations) (download) (as text)
Mon Oct 31 07:47:29 2005 UTC (8 years, 10 months ago) by hadfield
File MIME type: text/x-python
File size: 3505 byte(s)
fixed a exception being raised when users attempted to login. also a syntax error in login.py
1 # Copyright 2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4
5 """Simple request/response handling objects"""
6
7 __revision__ = "$Id$"
8 __authors__ = ["Scott Hadfield <hadfield@gentoo.org>",
9 "Ian Leitch <port001@gentoo.org>"]
10 __modulename__ = "request"
11
12 import cgi
13 import Cookie
14 import os
15
16 import sessionutils
17 from glsr.setup import config
18
19 class CgiHandler:
20 def __init__(self):
21 self._session_store = None
22
23 self.response = BaseResponse()
24 self.request = BaseRequest()
25
26 if config.SessionEnable:
27 self._session_store = sessionutils.SessionStorage(
28 config.StorageType)
29 self._session_store.load_store()
30
31 self.session = sessionutils.Session(self._session_store)
32
33 for key in self.session.attrs.keys():
34 arg_dict = {key: self.session.attrs[key]}
35 self._session_store.update_session(
36 sessionutils.get_id(), **arg_dict)
37
38 if self.session.is_persistent() == True:
39 self._session_store.set_persistent(self.session.get_id(), True)
40 else:
41 self._session_store.set_persistent(self.session.get_id(), False)
42
43 session_cookie = Cookie.SimpleCookie()
44 session_cookie[config.CookieName] = self.session.get_id()
45 session_cookie[config.CookieName]['path'] = '/'
46 # Uncomment for release
47 #session_cookie[config.CookieName]['domain'] = self._harm.request.host
48
49 if self.session.is_persistent() == False:
50 session_cookie[config.CookieName]['max-age'] = config.Timeout * 60
51
52 cookie_str = session_cookie[config.CookieName].OutputString()
53 self.response.add_header('Set-Cookie', cookie_str)
54
55 if not self.response.headers.has_key('Content-Type'):
56 self.response.add_header('Content-Type', 'text/html')
57
58 def __del__(self):
59 if config.SessionEnable:
60 self._session_store.save_store()
61
62 class BaseRequest:
63 def __init__(self):
64 self._form = cgi.FieldStorage()
65 # TODO: Use a __getitem__ method to build these on demand.
66 self.forms = self._build_forms()
67 self.queries = self._build_queries()
68
69 self.client_address = os.environ["REMOTE_ADDR"]
70
71 def _build_forms(self):
72 return self._form
73
74 def _build_queries(self):
75 query_str = {}
76 for key in self._form.keys():
77 query_str[key] = self._form.getvalue(key)
78
79 return query_str
80
81 class BaseResponse:
82
83 def __init__(self):
84 self.headers = {}
85 self.body = ""
86 self.status = 0
87 self.encoding = 'utf-8'
88
89 def add_header(self, htype, value):
90 if self.headers.has_key(htype):
91 return
92 self.headers[htype] = value
93
94 def remove_header(self, htype):
95 if self.headers.has_key(htype):
96 self.headers.pop(htype)
97
98 def update_header(self, htype, value):
99 if self.headers.has_key(htype):
100 self.headers[htype] = value
101
102 def append_body(self, text):
103 self.body = "%s%s" % (self.body, text)
104
105 def send(self):
106 for htype, hval in self.headers.iteritems():
107 if htype == "Content-Type":
108 continue
109 print "%s: %s" % (htype, hval)
110
111 if "Content-Type" in self.headers:
112 print "Content-Type: %s\n" % self.headers["Content-Type"]
113
114 print self.body

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20