TestOpenID
changeset 10:fd1a4e5a3ac5
It shows the history now!
| author | Eric Hopper <hopper@omnifarious.org> |
|---|---|
| date | Wed, 07 May 2008 19:24:25 -0700 |
| parents | 672986b9855a |
| children | a57833678677 |
| files | testoidconsumer/runconsumer.py |
| diffstat | 1 files changed, 43 insertions(+), 6 deletions(-) [+] |
line diff
1.1 --- a/testoidconsumer/runconsumer.py Wed May 07 16:00:59 2008 -0700 1.2 +++ b/testoidconsumer/runconsumer.py Wed May 07 19:24:25 2008 -0700 1.3 @@ -38,6 +38,10 @@ 1.4 url += '?' + environ['QUERY_STRING'] 1.5 return (site_url, path, script_url, path_url, url) 1.6 1.7 +def popiter(lst): 1.8 + while len(lst) > 0: 1.9 + yield lst.pop() 1.10 + 1.11 class Session(object): 1.12 def __init__(self, duration=20*60): 1.13 self._key = hex(id(self))[2:] 1.14 @@ -70,14 +74,46 @@ 1.15 return self.logout(environ, start_response) 1.16 else: 1.17 return self.environ_page(environ, start_response) 1.18 + def environ_html(self, histtuple): 1.19 + url, environ, oidsession, loginpaths = histtuple 1.20 + environ = sorted(environ.items(), key=lambda x: x[0]) 1.21 + envhead = u""" 1.22 + <div><h3>%s</h3> 1.23 + <table border="1"> 1.24 + <caption>Environment variables</caption> 1.25 + <tbody> 1.26 + """ % (_cgi.escape(url),) 1.27 + envbody = u'\n'.join((u'<tr><td>%s</td><td>%s</td>' % \ 1.28 + (_cgi.escape(k), _cgi.escape(str(v))) 1.29 + for k, v in environ)) 1.30 + envtail = u""" 1.31 + </tbody></table> 1.32 + """ 1.33 + if len(oidsession) > 0: 1.34 + sessbegin = u"""<table border="1"> 1.35 + <caption>OpenID consumer session variables</caption> 1.36 + <tbody> 1.37 + """ 1.38 + sessbody = u'\n'.join((u'<tr><td>%s</td><td>%s</td>' % \ 1.39 + (_cgi.escape(k), _cgi.escape(str(v))) 1.40 + for k, v in oidsession.iteritems())) 1.41 + sesstail = u"""</tbody></table> 1.42 + """ 1.43 + else: 1.44 + sessbegin = sessbody = sesstail = u'' 1.45 + return u''.join([envhead, envbody, envtail, 1.46 + sessbegin, sessbody, sesstail, u"</div>"]) 1.47 + 1.48 def environ_page(self, environ, start_response): 1.49 + self._history.append((wsgi_request_components(environ)[4], 1.50 + environ.copy(), self._oidsession.copy(), 1.51 + self._loginpaths.copy())) 1.52 start_response("200 OK", 1.53 [('Content-Type', 'text/html; charset=utf-8'), 1.54 ('Set-Cookie', 1.55 'testoid_session=%s; Version=1; Max-Age=%u' % \ 1.56 (self._key, self._duration))]) 1.57 self._lastused = _time.time() 1.58 - env = sorted(environ.items(), key=lambda x: x[0]) 1.59 str1 = u'''<?xml version="1.0" encoding="utf-8"?> 1.60 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 1.61 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1.62 @@ -107,11 +143,12 @@ 1.63 id="testopenid_identifier" size="22" /> 1.64 <input type="submit" value="Login"/> 1.65 </form>''' % (_cgi.escape(currentpath.decode('ascii'), quote=True),) 1.66 - str3 = u'<table border="1">' 1.67 - str4 = u''.join((u'<tr><td>%s</td><td>%s</td>' % \ 1.68 - (_cgi.escape(k), _cgi.escape(str(v))) for k, v in env)) 1.69 - str5 = u'</table></body></html>' 1.70 - return u''.join((str1, str2, str3, str4, str5)).encode('utf-8') 1.71 + str3 = u'\n<hr width="40%"/>\n' 1.72 + str3 = str3.join((self.environ_html(i) \ 1.73 + for i in popiter(self._history)) 1.74 + ) 1.75 + str4 = u'</body></html>' 1.76 + return u''.join((str1, str2, str3, str4)).encode('utf-8') 1.77 def process_login(self, oidconsumer, environ, start_response): 1.78 self._history.append((wsgi_request_components(environ)[4], 1.79 environ.copy(), self._oidsession.copy(),
