pyweblib.session
index
/home/michael/Proj/python/PyWebLib/pyweblib/session.py

pyweblib.session - server-side web session handling
(C) 1998-2015 by Michael Ströder <michael@stroeder.com>
 
This module implements server side session handling stored in
arbitrary string-keyed dictionary objects
 
This module is distributed under the terms of the
GPL (GNU GENERAL PUBLIC LICENSE) Version 2
(see http://www.gnu.org/copyleft/gpl.html)

 
Modules
       
pickle
random
re
string
threading
time

 
Classes
       
exceptions.Exception(exceptions.BaseException)
SessionException
BadSessionId
CorruptData
GenerateIDError
InvalidSessionId
MaxSessionCountExceeded
SessionExpired
SessionHijacked
WebSession
threading.Thread(threading._Verbose)
CleanUpThread

 
class BadSessionId(SessionException)
    Raised if session ID not found in session dictionary.
 
 
Method resolution order:
BadSessionId
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, session_id)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class CleanUpThread(threading.Thread)
    Thread class for clean-up thread
 
 
Method resolution order:
CleanUpThread
threading.Thread
threading._Verbose
__builtin__.object

Methods defined here:
__init__(self, sessionInstance, interval=60)
__repr__(self)
join(self, timeout=0.0)
run(self)
Thread function for cleaning up session database

Methods inherited from threading.Thread:
getName(self)
isAlive(self)
Return whether the thread is alive.
 
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
isDaemon(self)
is_alive = isAlive(self)
Return whether the thread is alive.
 
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
setDaemon(self, daemonic)
setName(self, name)
start(self)
Start the thread's activity.
 
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
 
This method will raise a RuntimeError if called more than once on the
same thread object.

Data descriptors inherited from threading.Thread:
daemon
A boolean value indicating whether this thread is a daemon thread (True) or not (False).
 
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
 
The entire Python program exits when no alive non-daemon threads are
left.
ident
Thread identifier of this thread or None if it has not been started.
 
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
name
A string used for identification purposes only.
 
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.

Data descriptors inherited from threading._Verbose:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class CorruptData(SessionException)
    Raised if data was corrupt, e.g. UnpicklingError occured
 
 
Method resolution order:
CorruptData
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__str__(self)

Methods inherited from SessionException:
__init__(self, *args)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class GenerateIDError(SessionException)
    Raised if generation of unique session ID failed.
 
 
Method resolution order:
GenerateIDError
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, maxtry)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class InvalidSessionId(SessionException)
    Raised if session ID not found in session dictionary.
 
 
Method resolution order:
InvalidSessionId
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, session_id)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class MaxSessionCountExceeded(SessionException)
    Raised if maximum number of sessions is exceeded.
 
 
Method resolution order:
MaxSessionCountExceeded
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, max_session_count)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class SessionException(exceptions.Exception)
    Raised if
 
 
Method resolution order:
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, *args)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class SessionExpired(SessionException)
    Raised if session is expired.
 
 
Method resolution order:
SessionExpired
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, timestamp, session_data)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class SessionHijacked(SessionException)
    Raised if hijacking of session was detected.
 
 
Method resolution order:
SessionHijacked
SessionException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, failed_vars)
__str__(self)

Data descriptors inherited from SessionException:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class WebSession
    The session class which handles storing and retrieving of session data
in a dictionary-like sessiondict object.
 
  Methods defined here:
__init__(self, dictobj=None, expireDeactivate=0, expireRemove=0, crossCheckVars=None, maxSessionCount=None, sessionIDLength=12, sessionIDChars=None)
dictobj
    has to be a instance of a dictionary-like object
    (e.g. derived from UserDict or shelve)
expireDeactivate
    amount of time (secs) after which a session
    expires and a SessionExpired exception is
    raised which contains the session data.
expireRemove
    Amount of time (secs) after which a session
    expires and the session data is silently deleted.
    A InvalidSessionId exception is raised in this case if
    the application trys to access the session ID again.
crossCheckVars
    List of keys of variables cross-checked for each
    retrieval of session data in retrieveSession(). If None
    SESSION_CROSSCHECKVARS is used.
maxSessionCount
    Maximum number of valid sessions. This affects
    behaviour of retrieveSession() which raises.
    None means unlimited number of sessions.
sessionIDLength
    Exact integer length of the session ID generated
sessionIDChars
    String containing the valid chars for session IDs
    (if this is zero-value the default is SESSION_ID_CHARS)
cleanUp(self)
Search for expired session entries and delete them.
 
Returns integer counter of deleted sessions as result.
close(self)
Call close() if self.sessiondict has .close() method
deleteSession(self, session_id)
Delete session_data referenced by session_id.
newSession(self, env=None)
Store session data under session id
retrieveSession(self, session_id, env={})
Retrieve session data
storeSession(self, session_id, session_data)
Store session_data under session_id.
sync(self)
Call sync if self.sessiondict has .sync() method

 
Functions
       
ThreadingLock = allocate_lock(...)
allocate_lock() -> lock object
(allocate() is an obsolete synonym)
 
Create a new lock object.  See help(LockType) for information about locks.

 
Data
        SESSION_CROSSCHECKVARS = ('\n List of environment variables assumed to be c...gh a network of web proxy siblings.\n 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')
SESSION_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._'
__info__ = '$Id: pyweblib.session.html,v 1.14 2015/01/10 14:40:54 michael Exp $'
__revision__ = '1.31'