durusmail: quixote-users: session2: a persistent session library
session2: a persistent session library
2005-06-13
2005-06-18
2005-06-18
2005-06-19
2005-06-19
session2: a persistent session library
mso@oz.net
2005-06-13
Titus and I have put together a persistent session library for Quxiote.
Give it a try at http://quixote.idyll.org/session2/ and let us know of any
bugs or feedback.  It comes with five stores: file-based (with fcntl
locking), Durus, MySQL, PostgreSQL (psycopg), and Shelve.

Titus refactored the session manager to call just four methods in the
stores:  .load_session, .save_session, .delete_session, .has_session .
This will make it easier to develop new stores in the future.  I made
MySQLSessionStore and added three methods and two attributes to the
stores:

    .setup() : initialize the store (i.e., create the database table).
This is for your application setup routine.  The store automatically
calls this at instantiation if needed, but you can call it separately
if you need special permissions to initialize.  Not implemented for
Postgres.

    .delete_old_sessions(minutes) : delete sessions older than N minutes.
This is for your application maintenance routine.  Currently works for
MySQL; no-op for the others.

    .iter_sessions():  return iterable of (id, session).  This is for
admin applications that want to browse the sessions.  Currently works
for MySQL; others raise NotImplementedError.

    .is_multiprocess_safe: true if the store is approved for forking
servers.  All except Shelve are.

    .is_thread_safe: true if the store is approved for mulithreaded
servers.  All are false, for reasons commented in the source.

setup-store.py is a command-line interface to .setup().

The Session class is the same as Quixote's but there's no .is_dirty()
method.  I added a DictSession class which adds key access.  (eys are
distinct from attributes.)

It comes with an interactive demo for testing, and twill-based automated
tests, both by Titus.

The source is in the Quixote Extras repository under titus/session2/ .
The Quixote Extras README is at
http://cafepy.ca/quixote_extras/README .

--
-- Mike Orr 

reply