<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Python: module pyweblib.session</title> </head><body bgcolor="#f0f0f8"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> <tr bgcolor="#7799ee"> <td valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="pyweblib.html"><font color="#ffffff">pyweblib</font></a>.session</strong></big></big> (version 0.3.4)</font></td ><td align=right valign=bottom ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.3/site-packages/pyweblib/session.py">/usr/lib/python2.3/site-packages/pyweblib/session.py</a></font></td></tr></table> <p><tt>pyweblib.session - server-side web session handling<br> (C) 2001 by Michael Stroeder <michael@stroeder.com><br> <br> This module implements server side session handling stored in<br> arbitrary string-keyed dictionary objects<br> <br> This module is distributed under the terms of the<br> GPL (GNU GENERAL PUBLIC LICENSE) Version 2<br> (see <a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a>)<br> <br> $Id: pyweblib.session.html,v 1.13 2004/08/24 10:26:30 michael Exp $</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#aa55cc"> <td colspan=3 valign=bottom> <br> <font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="pickle.html">pickle</a><br> <a href="random.html">random</a><br> </td><td width="25%" valign=top><a href="re.html">re</a><br> <a href="string.html">string</a><br> </td><td width="25%" valign=top><a href="threading.html">threading</a><br> <a href="time.html">time</a><br> </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ee77aa"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> <td width="100%"><dl> <dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a> </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="pyweblib.session.html#SessionException">SessionException</a> </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="pyweblib.session.html#BadSessionId">BadSessionId</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#CorruptData">CorruptData</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#GenerateIDError">GenerateIDError</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#InvalidSessionId">InvalidSessionId</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#MaxSessionCountExceeded">MaxSessionCountExceeded</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#SessionExpired">SessionExpired</a> </font></dt><dt><font face="helvetica, arial"><a href="pyweblib.session.html#SessionHijacked">SessionHijacked</a> </font></dt></dl> </dd> </dl> </dd> <dt><font face="helvetica, arial"><a href="threading.html#Thread">threading.Thread</a>(<a href="threading.html#_Verbose">threading._Verbose</a>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="pyweblib.session.html#CleanUpThread">CleanUpThread</a> </font></dt></dl> </dd> <dt><font face="helvetica, arial"><a href="pyweblib.session.html#WebSession">WebSession</a> </font></dt></dl> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="BadSessionId">class <strong>BadSessionId</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if session ID not found in session dictionary.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#BadSessionId">BadSessionId</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="BadSessionId-__init__"><strong>__init__</strong></a>(self, session_id)</dt></dl> <dl><dt><a name="BadSessionId-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="BadSessionId-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="CleanUpThread">class <strong>CleanUpThread</strong></a>(<a href="threading.html#Thread">threading.Thread</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt><a href="threading.html#Thread">Thread</a> class for clean-up thread<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#CleanUpThread">CleanUpThread</a></dd> <dd><a href="threading.html#Thread">threading.Thread</a></dd> <dd><a href="threading.html#_Verbose">threading._Verbose</a></dd> <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="CleanUpThread-__init__"><strong>__init__</strong></a>(self, sessionInstance, interval<font color="#909090">=60</font>)</dt></dl> <dl><dt><a name="CleanUpThread-__repr__"><strong>__repr__</strong></a>(self)</dt></dl> <dl><dt><a name="CleanUpThread-join"><strong>join</strong></a>(self, timeout<font color="#909090">=0.0</font>)</dt></dl> <dl><dt><a name="CleanUpThread-run"><strong>run</strong></a>(self)</dt><dd><tt><a href="threading.html#Thread">Thread</a> function for cleaning up session database</tt></dd></dl> <hr> Methods inherited from <a href="threading.html#Thread">threading.Thread</a>:<br> <dl><dt><a name="CleanUpThread-getName"><strong>getName</strong></a>(self)</dt></dl> <dl><dt><a name="CleanUpThread-isAlive"><strong>isAlive</strong></a>(self)</dt></dl> <dl><dt><a name="CleanUpThread-isDaemon"><strong>isDaemon</strong></a>(self)</dt></dl> <dl><dt><a name="CleanUpThread-setDaemon"><strong>setDaemon</strong></a>(self, daemonic)</dt></dl> <dl><dt><a name="CleanUpThread-setName"><strong>setName</strong></a>(self, name)</dt></dl> <dl><dt><a name="CleanUpThread-start"><strong>start</strong></a>(self)</dt></dl> <hr> Data and other attributes inherited from <a href="threading.html#_Verbose">threading._Verbose</a>:<br> <dl><dt><strong>__dict__</strong> = <dictproxy object><dd><tt>dictionary for instance variables (if defined)</tt></dl> <dl><dt><strong>__weakref__</strong> = <attribute '__weakref__' of '_Verbose' objects><dd><tt>list of weak references to the object (if defined)</tt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="CorruptData">class <strong>CorruptData</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if data was corrupt, e.g. UnpicklingError occured<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#CorruptData">CorruptData</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="CorruptData-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="pyweblib.session.html#SessionException">SessionException</a>:<br> <dl><dt><a name="CorruptData-__init__"><strong>__init__</strong></a>(self, *args)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="CorruptData-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="GenerateIDError">class <strong>GenerateIDError</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if generation of unique session ID failed.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#GenerateIDError">GenerateIDError</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="GenerateIDError-__init__"><strong>__init__</strong></a>(self, maxtry)</dt></dl> <dl><dt><a name="GenerateIDError-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="GenerateIDError-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="InvalidSessionId">class <strong>InvalidSessionId</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if session ID not found in session dictionary.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#InvalidSessionId">InvalidSessionId</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="InvalidSessionId-__init__"><strong>__init__</strong></a>(self, session_id)</dt></dl> <dl><dt><a name="InvalidSessionId-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="InvalidSessionId-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="MaxSessionCountExceeded">class <strong>MaxSessionCountExceeded</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if maximum number of sessions is exceeded.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#MaxSessionCountExceeded">MaxSessionCountExceeded</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="MaxSessionCountExceeded-__init__"><strong>__init__</strong></a>(self, max_session_count)</dt></dl> <dl><dt><a name="MaxSessionCountExceeded-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="MaxSessionCountExceeded-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="SessionException">class <strong>SessionException</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="SessionException-__init__"><strong>__init__</strong></a>(self, *args)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="SessionException-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> <dl><dt><a name="SessionException-__str__"><strong>__str__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="SessionExpired">class <strong>SessionExpired</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if session is expired.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#SessionExpired">SessionExpired</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="SessionExpired-__init__"><strong>__init__</strong></a>(self, timestamp, session_data)</dt></dl> <dl><dt><a name="SessionExpired-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="SessionExpired-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="SessionHijacked">class <strong>SessionHijacked</strong></a>(<a href="pyweblib.session.html#SessionException">SessionException</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Raised if hijacking of session was detected.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="pyweblib.session.html#SessionHijacked">SessionHijacked</a></dd> <dd><a href="pyweblib.session.html#SessionException">SessionException</a></dd> <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="SessionHijacked-__init__"><strong>__init__</strong></a>(self, failed_vars)</dt></dl> <dl><dt><a name="SessionHijacked-__str__"><strong>__str__</strong></a>(self)</dt></dl> <hr> Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br> <dl><dt><a name="SessionHijacked-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="WebSession">class <strong>WebSession</strong></a></font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>The session class which handles storing and retrieving of session data<br> in a dictionary-like sessiondict object.<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="WebSession-__init__"><strong>__init__</strong></a>(self, dictobj<font color="#909090">=None</font>, expireDeactivate<font color="#909090">=0</font>, expireRemove<font color="#909090">=0</font>, crossCheckVars<font color="#909090">=None</font>, maxSessionCount<font color="#909090">=None</font>)</dt><dd><tt>dictobj<br> has to be a instance of a dictionary-like object<br> (e.g. derived from UserDict or shelve)<br> expireDeactivate <br> amount of time (secs) after which a session<br> expires and a <a href="#SessionExpired">SessionExpired</a> exception is<br> raised which contains the session data.<br> expireRemove<br> Amount of time (secs) after which a session<br> expires and the session data is silently deleted.<br> A <a href="#InvalidSessionId">InvalidSessionId</a> exception is raised in this case if<br> the application trys to access the session ID again.<br> crossCheckVars<br> List of keys of variables cross-checked for each<br> retrieval of session data in <a href="#WebSession-retrieveSession">retrieveSession</a>(). If None<br> SESSION_CROSSCHECKVARS is used.<br> maxSessionCount<br> Maximum number of valid sessions. This affects<br> behaviour of <a href="#WebSession-retrieveSession">retrieveSession</a>() which raises.<br> None means unlimited number of sessions.</tt></dd></dl> <dl><dt><a name="WebSession-cleanUp"><strong>cleanUp</strong></a>(self)</dt><dd><tt>Search for expired session entries and delete them.<br> <br> Returns integer counter of deleted sessions as result.</tt></dd></dl> <dl><dt><a name="WebSession-close"><strong>close</strong></a>(self)</dt><dd><tt>Call <a href="#WebSession-close">close</a>() if self.<strong>sessiondict</strong> has .<a href="#WebSession-close">close</a>() method</tt></dd></dl> <dl><dt><a name="WebSession-deleteSession"><strong>deleteSession</strong></a>(self, session_id)</dt><dd><tt>Delete session_data referenced by session_id.</tt></dd></dl> <dl><dt><a name="WebSession-newSession"><strong>newSession</strong></a>(self, env<font color="#909090">={}</font>)</dt><dd><tt>Store session data under session id</tt></dd></dl> <dl><dt><a name="WebSession-retrieveSession"><strong>retrieveSession</strong></a>(self, session_id, env<font color="#909090">={}</font>)</dt><dd><tt>Retrieve session data</tt></dd></dl> <dl><dt><a name="WebSession-storeSession"><strong>storeSession</strong></a>(self, session_id, session_data)</dt><dd><tt>Store session_data under session_id.</tt></dd></dl> <dl><dt><a name="WebSession-sync"><strong>sync</strong></a>(self)</dt><dd><tt>Call sync if self.<strong>sessiondict</strong> has .<a href="#WebSession-sync">sync</a>() method</tt></dd></dl> </td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#eeaa77"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> <td width="100%"><dl><dt><a name="-ThreadingLock"><strong>ThreadingLock</strong></a> = allocate_lock(...)</dt><dd><tt>allocate_lock() -> lock object<br> (allocate() is an obsolete synonym)<br> <br> Create a new lock object. See LockType.__doc__ for information about locks.</tt></dd></dl> </td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> <td width="100%"><strong>SESSION_CROSSCHECKVARS</strong> = ('<font color="#c040c0">\n</font> List of environment variables assumed to be c...gh a network of web proxy siblings.<font color="#c040c0">\n</font> REMOTE_ADDR', 'REMOTE_HOST', 'REMOTE_IDENT', 'REMOTE_USER', 'FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR', 'HTTP_USER_AGENT', 'HTTP_ACCEPT_CHARSET', 'SSL_SESSION_ID', 'SSL_CLIENT_V_START', 'SSL_CLIENT_V_END', 'SSL_CLIENT_I_DN', 'SSL_CLIENT_IDN', 'SSL_CLIENT_S_DN', 'SSL_CLIENT_SDN', 'SSL_CLIENT_M_SERIAL', 'SSL_CLIENT_CERT_SERIAL')<br> <strong>SESSION_ID_CHARS</strong> = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'<br> <strong>__version__</strong> = '0.3.4'</td></tr></table> </body></html>