sessions: fixed regression in handlin sqlalchemy params for beaker DB based sessions
This commit is contained in:
parent
cbe72d2e58
commit
76f23b6bd6
1 changed files with 18 additions and 4 deletions
|
|
@ -3,11 +3,10 @@
|
|||
# License: BSD-derived (http://www.repoze.org/LICENSE.txt)
|
||||
# With Patches from RhodeCode GmBH
|
||||
|
||||
|
||||
import os
|
||||
|
||||
from beaker import cache
|
||||
from beaker.session import SessionObject
|
||||
from beaker.session import SessionObject, Session
|
||||
from beaker.util import coerce_cache_params
|
||||
from beaker.util import coerce_session_params
|
||||
|
||||
|
|
@ -18,6 +17,11 @@ from zope.interface import implementer
|
|||
from binascii import hexlify
|
||||
|
||||
|
||||
|
||||
class CustomSession(Session):
|
||||
pass
|
||||
|
||||
|
||||
def BeakerSessionFactoryConfig(**options):
|
||||
""" Return a Pyramid session factory using Beaker session settings
|
||||
supplied directly as ``**options``"""
|
||||
|
|
@ -26,8 +30,11 @@ def BeakerSessionFactoryConfig(**options):
|
|||
_options = options
|
||||
_cookie_on_exception = _options.pop('cookie_on_exception', True)
|
||||
_constant_csrf_token = _options.pop('constant_csrf_token', False)
|
||||
_sa_opts = _options.pop('sa_opts', {})
|
||||
|
||||
def __init__(self, request):
|
||||
self._options['session_class'] = CustomSession
|
||||
self._options['sa_opts'] = self._sa_opts
|
||||
SessionObject.__init__(self, request.environ, **self._options)
|
||||
|
||||
def session_callback(_request, _response):
|
||||
|
|
@ -93,12 +100,12 @@ def BeakerSessionFactoryConfig(**options):
|
|||
|
||||
# Flash API methods
|
||||
def flash(self, msg, queue='', allow_duplicate=True):
|
||||
storage = self.setdefault('_f_' + queue, [])
|
||||
storage = self.setdefault(f'_f_{queue}', [])
|
||||
if allow_duplicate or (msg not in storage):
|
||||
storage.append(msg)
|
||||
|
||||
def pop_flash(self, queue=''):
|
||||
storage = self.pop('_f_' + queue, [])
|
||||
storage = self.pop(f'_f_{queue}', [])
|
||||
return storage
|
||||
|
||||
def peek_flash(self, queue=''):
|
||||
|
|
@ -140,6 +147,10 @@ def session_factory_from_settings(settings):
|
|||
prefixes = ('session.', 'beaker.session.')
|
||||
options = {}
|
||||
|
||||
# custom gather of our specific sqlalchemy session db configuration we need to translate this into a single entry
|
||||
# dict because this is how beaker expects that.
|
||||
sa_opts = {}
|
||||
|
||||
# Pull out any config args meant for beaker session. if there are any
|
||||
for k, v in settings.items():
|
||||
for prefix in prefixes:
|
||||
|
|
@ -147,9 +158,12 @@ def session_factory_from_settings(settings):
|
|||
option_name = k[len(prefix):]
|
||||
if option_name == 'cookie_on_exception':
|
||||
v = asbool(v)
|
||||
if option_name.startswith('sa.'):
|
||||
sa_opts[option_name] = v
|
||||
options[option_name] = v
|
||||
|
||||
options = coerce_session_params(options)
|
||||
options['sa_opts'] = sa_opts
|
||||
return BeakerSessionFactoryConfig(**options)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue