##// END OF EJS Templates
sessions: fixed regression in handlin sqlalchemy params for beaker DB based sessions
super-admin -
r5132:896a74f1 default
parent child Browse files
Show More
@@ -3,11 +3,10 b''
3 3 # License: BSD-derived (http://www.repoze.org/LICENSE.txt)
4 4 # With Patches from RhodeCode GmBH
5 5
6
7 6 import os
8 7
9 8 from beaker import cache
10 from beaker.session import SessionObject
9 from beaker.session import SessionObject, Session
11 10 from beaker.util import coerce_cache_params
12 11 from beaker.util import coerce_session_params
13 12
@@ -18,6 +17,11 b' from zope.interface import implementer'
18 17 from binascii import hexlify
19 18
20 19
20
21 class CustomSession(Session):
22 pass
23
24
21 25 def BeakerSessionFactoryConfig(**options):
22 26 """ Return a Pyramid session factory using Beaker session settings
23 27 supplied directly as ``**options``"""
@@ -26,8 +30,11 b' def BeakerSessionFactoryConfig(**options'
26 30 _options = options
27 31 _cookie_on_exception = _options.pop('cookie_on_exception', True)
28 32 _constant_csrf_token = _options.pop('constant_csrf_token', False)
33 _sa_opts = _options.pop('sa_opts', {})
29 34
30 35 def __init__(self, request):
36 self._options['session_class'] = CustomSession
37 self._options['sa_opts'] = self._sa_opts
31 38 SessionObject.__init__(self, request.environ, **self._options)
32 39
33 40 def session_callback(_request, _response):
@@ -93,12 +100,12 b' def BeakerSessionFactoryConfig(**options'
93 100
94 101 # Flash API methods
95 102 def flash(self, msg, queue='', allow_duplicate=True):
96 storage = self.setdefault('_f_' + queue, [])
103 storage = self.setdefault(f'_f_{queue}', [])
97 104 if allow_duplicate or (msg not in storage):
98 105 storage.append(msg)
99 106
100 107 def pop_flash(self, queue=''):
101 storage = self.pop('_f_' + queue, [])
108 storage = self.pop(f'_f_{queue}', [])
102 109 return storage
103 110
104 111 def peek_flash(self, queue=''):
@@ -140,6 +147,10 b' def session_factory_from_settings(settin'
140 147 prefixes = ('session.', 'beaker.session.')
141 148 options = {}
142 149
150 # custom gather of our specific sqlalchemy session db configuration we need to translate this into a single entry
151 # dict because this is how beaker expects that.
152 sa_opts = {}
153
143 154 # Pull out any config args meant for beaker session. if there are any
144 155 for k, v in settings.items():
145 156 for prefix in prefixes:
@@ -147,9 +158,12 b' def session_factory_from_settings(settin'
147 158 option_name = k[len(prefix):]
148 159 if option_name == 'cookie_on_exception':
149 160 v = asbool(v)
161 if option_name.startswith('sa.'):
162 sa_opts[option_name] = v
150 163 options[option_name] = v
151 164
152 165 options = coerce_session_params(options)
166 options['sa_opts'] = sa_opts
153 167 return BeakerSessionFactoryConfig(**options)
154 168
155 169
General Comments 0
You need to be logged in to leave comments. Login now