summaryrefslogtreecommitdiffstats
path: root/module/lib/beaker/middleware.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/lib/beaker/middleware.py')
-rw-r--r--module/lib/beaker/middleware.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/module/lib/beaker/middleware.py b/module/lib/beaker/middleware.py
index 785d25377..7ba88b37d 100644
--- a/module/lib/beaker/middleware.py
+++ b/module/lib/beaker/middleware.py
@@ -16,15 +16,15 @@ from beaker.util import coerce_cache_params, coerce_session_params, \
class CacheMiddleware(object):
cache = beaker_cache
-
+
def __init__(self, app, config=None, environ_key='beaker.cache', **kwargs):
"""Initialize the Cache Middleware
-
+
The Cache middleware will make a Cache instance available
every request under the ``environ['beaker.cache']`` key by
default. The location in environ can be changed by setting
``environ_key``.
-
+
``config``
dict All settings should be prefixed by 'cache.'. This
method of passing variables is intended for Paste and other
@@ -32,11 +32,11 @@ class CacheMiddleware(object):
single dictionary. If config contains *no cache. prefixed
args*, then *all* of the config options will be used to
intialize the Cache objects.
-
+
``environ_key``
Location where the Cache instance will keyed in the WSGI
environ
-
+
``**kwargs``
All keyword arguments are assumed to be cache settings and
will override any settings found in ``config``
@@ -44,26 +44,26 @@ class CacheMiddleware(object):
"""
self.app = app
config = config or {}
-
+
self.options = {}
-
+
# Update the options with the parsed config
self.options.update(parse_cache_config_options(config))
-
+
# Add any options from kwargs, but leave out the defaults this
# time
self.options.update(
parse_cache_config_options(kwargs, include_defaults=False))
-
+
# Assume all keys are intended for cache if none are prefixed with
# 'cache.'
if not self.options and config:
self.options = config
-
+
self.options.update(kwargs)
self.cache_manager = CacheManager(**self.options)
self.environ_key = environ_key
-
+
def __call__(self, environ, start_response):
if environ.get('paste.registry'):
if environ['paste.registry'].reglist:
@@ -75,16 +75,16 @@ class CacheMiddleware(object):
class SessionMiddleware(object):
session = beaker_session
-
+
def __init__(self, wrap_app, config=None, environ_key='beaker.session',
**kwargs):
"""Initialize the Session Middleware
-
+
The Session middleware will make a lazy session instance
available every request under the ``environ['beaker.session']``
key by default. The location in environ can be changed by
setting ``environ_key``.
-
+
``config``
dict All settings should be prefixed by 'session.'. This
method of passing variables is intended for Paste and other
@@ -92,18 +92,18 @@ class SessionMiddleware(object):
single dictionary. If config contains *no cache. prefixed
args*, then *all* of the config options will be used to
intialize the Cache objects.
-
+
``environ_key``
Location where the Session instance will keyed in the WSGI
environ
-
+
``**kwargs``
All keyword arguments are assumed to be session settings and
will override any settings found in ``config``
"""
config = config or {}
-
+
# Load up the default params
self.options = dict(invalidate_corrupt=True, type=None,
data_dir=None, key='beaker.session.id',
@@ -120,19 +120,19 @@ class SessionMiddleware(object):
warnings.warn('Session options should start with session. '
'instead of session_.', DeprecationWarning, 2)
self.options[key[8:]] = val
-
+
# Coerce and validate session params
coerce_session_params(self.options)
-
+
# Assume all keys are intended for cache if none are prefixed with
# 'cache.'
if not self.options and config:
self.options = config
-
+
self.options.update(kwargs)
self.wrap_app = wrap_app
self.environ_key = environ_key
-
+
def __call__(self, environ, start_response):
session = SessionObject(environ, **self.options)
if environ.get('paste.registry'):
@@ -140,7 +140,7 @@ class SessionMiddleware(object):
environ['paste.registry'].register(self.session, session)
environ[self.environ_key] = session
environ['beaker.get_session'] = self._get_session
-
+
def session_start_response(status, headers, exc_info = None):
if session.accessed():
session.persist()
@@ -150,7 +150,7 @@ class SessionMiddleware(object):
headers.append(('Set-cookie', cookie))
return start_response(status, headers, exc_info)
return self.wrap_app(environ, session_start_response)
-
+
def _get_session(self):
return Session({}, use_cookies=False, **self.options)