Add support for Beaker >= 1.12.0

but still support previous versions too, for now
This commit is contained in:
Lance Edgar 2022-12-07 14:00:32 -06:00
parent 2b220459c7
commit 22176e89dd
2 changed files with 15 additions and 11 deletions

View file

@ -75,10 +75,6 @@ requires = [
# (still, probably a better idea is to refactor so we can use 0.9)
'webhelpers2_grid==0.1', # 0.1
# TODO: latest version breaks us totally! need to fix ASAP, but
# for the moment, must restrict version
'Beaker<1.12', # 1.11.0
# TODO: remove version cap once we can drop support for python 2.x
'cornice<5.0', # 3.4.2 4.0.1

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2022 Lance Edgar
#
# This file is part of Rattail.
#
@ -30,7 +30,9 @@ pyramid_beaker projects.
from __future__ import unicode_literals, absolute_import
import time
from pkg_resources import parse_version
import beaker
from beaker.session import Session
from beaker.util import coerce_session_params
from pyramid.settings import asbool
@ -45,6 +47,10 @@ class TailboneSession(Session):
def load(self):
"Loads the data from this session from persistent storage"
# are we using older version of beaker?
old_beaker = parse_version(beaker.__version__) < parse_version('1.12')
self.namespace = self.namespace_class(self.id,
data_dir=self.data_dir,
digest_filenames=False,
@ -60,8 +66,12 @@ class TailboneSession(Session):
try:
session_data = self.namespace['session']
if (session_data is not None and self.encrypt_key):
session_data = self._decrypt_data(session_data)
if old_beaker:
if (session_data is not None and self.encrypt_key):
session_data = self._decrypt_data(session_data)
else: # beaker >= 1.12
if session_data is not None:
session_data = self._decrypt_data(session_data)
# Memcached always returns a key, its None when its not
# present
@ -90,6 +100,7 @@ class TailboneSession(Session):
# for this module entirely...
timeout = session_data.get('_timeout', self.timeout)
if timeout is not None and \
'_accessed_time' in session_data and \
now - session_data['_accessed_time'] > timeout:
timed_out = True
else:
@ -103,9 +114,6 @@ class TailboneSession(Session):
# Update the current _accessed_time
session_data['_accessed_time'] = now
# Set the path if applicable
if '_path' in session_data:
self._path = session_data['_path']
self.update(session_data)
self.accessed_dict = session_data.copy()
finally: