From da52d322af583c60e903d5257de033946dd1e679 Mon Sep 17 00:00:00 2001 From: Evilham Date: Mon, 1 Aug 2022 12:56:50 +0200 Subject: [PATCH] [sso-admin] Add cache decorator for python 3.7 --- dd-sso/admin/src/admin/lib/keys.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dd-sso/admin/src/admin/lib/keys.py b/dd-sso/admin/src/admin/lib/keys.py index 076387b..3a56719 100644 --- a/dd-sso/admin/src/admin/lib/keys.py +++ b/dd-sso/admin/src/admin/lib/keys.py @@ -37,7 +37,7 @@ import stat from copy import deepcopy from datetime import datetime, timedelta from pathlib import Path -from typing import Any, Dict, List, Optional, Union +from typing import Any, Callable, Dict, List, Optional, Union import requests from attr import field, frozen @@ -52,10 +52,15 @@ from jose.backends.rsa_backend import RSAKey from jose.constants import ALGORITHMS try: - # Python 3.8 - from functools import cached_property as cache -except ImportError: from functools import cache # type: ignore # Python 3.9+ +except ImportError: + try: + from functools import cached_property as cache # type: ignore # Python 3.8 + except ImportError: + from functools import lru_cache + + def cache(call: Callable) -> property: # type: ignore # Python 3.7 + return property(lru_cache()(call)) Data = Union[str, bytes]