diff options
author | ianb <devnull@localhost> | 2006-10-20 18:56:34 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2006-10-20 18:56:34 +0000 |
commit | 07b918fcc6744b473e66d63e1e3e99c8013ecaf2 (patch) | |
tree | c0d45e033a269155d2256bf5e0d823d46324f62b /paste/session.py | |
parent | 418344755d66d2d7347cf5d7792d23991d68f7c5 (diff) | |
download | paste-07b918fcc6744b473e66d63e1e3e99c8013ecaf2.tar.gz |
Moved session entry point
Diffstat (limited to 'paste/session.py')
-rw-r--r-- | paste/session.py | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/paste/session.py b/paste/session.py index 3219fab..ca98441 100644 --- a/paste/session.py +++ b/paste/session.py @@ -77,7 +77,7 @@ class SessionFactory(object): def __init__(self, environ, cookie_name='_SID_', session_class=None, - expiration=60*12, # in minutes + session_expiration=60*12, # in minutes **session_class_kw): self.created = False @@ -88,8 +88,7 @@ class SessionFactory(object): self.session_class = session_class or FileSession self.session_class_kw = session_class_kw - self.expiration = expiration - self.session_class_kw['expiration'] = self.expiration + self.expiration = session_expiration def __call__(self): self.used = True @@ -267,3 +266,62 @@ class FileSession(object): # it... cleaning_up = False raise + +class _NoDefault: + def __repr__(self): + return '<dynamic default>' +NoDefault = _NoDefault() + +def make_session_middleware( + app, global_conf, + session_expiration=NoDefault, + expiration=NoDefault, + cookie_name=NoDefault, + session_file_path=NoDefault, + chmod=NoDefault): + """ + Adds a middleware that handles sessions for your applications. + The session is a peristent dictionary. To get this dictionary + in your application, use ``environ['paste.session.factory']()`` + which returns this persistent dictionary. + + Configuration: + + session_expiration: + The time each session lives, in minutes. This controls + the cookie expiration. Default 12 hours. + + expiration: + The time each session lives on disk. Old sessions are + culled from disk based on this. Default 48 hours. + + cookie_name: + The cookie name used to track the session. Use different + names to avoid session clashes. + + session_file_path: + Sessions are put in this location, default /tmp. + + chmod: + The octal chmod you want to apply to new sessions (e.g., 660 + to make the sessions group readable/writable) + + Each of these also takes from the global configuration. cookie_name + and chmod take from session_cookie_name and session_chmod + """ + if session_expiration is NoDefault: + session_expiration = global_conf.get('session_expiration', 60*12) + session_expiration = int(session_expiration) + if expiration is NoDefault: + expiration = global_conf.get('expiration', 60*48) + expiration = int(expiration) + if cookie_name is NoDefault: + cookie_name = global_conf.get('session_cookie_name', '_SID_') + if session_file_path is NoDefault: + session_file_path = global_conf.get('session_file_path', '/tmp') + if chmod is NoDefault: + chmod = global_conf.get('session_chmod', None) + return SessionMiddleware( + app, session_expiration=session_expiration, + expiration=expiration, cookie_name=cookie_name, + session_file_path=session_file_path, chmod=chmod) |