From 22176e89dd7f790274665479addcb613a7985fa1 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 7 Dec 2022 14:00:32 -0600 Subject: [PATCH] Add support for Beaker >= 1.12.0 but still support previous versions too, for now --- setup.py | 4 ---- tailbone/beaker.py | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index eaa9e5b1..3328785e 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/tailbone/beaker.py b/tailbone/beaker.py index 1f7f20c5..b5d592f1 100644 --- a/tailbone/beaker.py +++ b/tailbone/beaker.py @@ -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: