From 0eda8c5c04c6ce6cfac5fe64d1de8f6e92dce538 Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Fri, 22 Oct 2021 09:03:30 +0200 Subject: [PATCH] fixup! Rename (force|smart)_text to (force|smart)_str Also Import lru_cache from seddable place --- python/nav/compatibility.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/python/nav/compatibility.py b/python/nav/compatibility.py index c6b86d3470..905bb14e47 100644 --- a/python/nav/compatibility.py +++ b/python/nav/compatibility.py @@ -1,5 +1,9 @@ -# Django 4.0: -# s/nav.compatibility \(import force_str\)/django.utils.encoding \1/' +# Django 2.2 has only *_text, Django 3.2 has both *_text and *_str, +# Django 4.0 has only *_str. These are imported so many places that +# it is better to do it once, hence this file + +# When no longer supporting 2.2: +# s/nav.compatibility \(import \w+_str\)/django.utils.encoding \1/ try: from django.utils.encoding import force_str except ImoprtError: @@ -9,3 +13,13 @@ from django.utils.encoding import smart_str except ImoprtError: from django.utils.encoding import smart_text as smart_str + +# lru_cache isn't used that much but one application of sed is faster +# than changing a block into a line three times. + +# When no longer supporting 2.2: +# s/nav.compatibility import lru_cache/functools import lru_cache/ +try: + from functools import lru_cache +except ImportError: + from django.utils.lru_cache import lru_cache