From 603bab1ff45f2bdee3815672556ea7cf39a0fc67 Mon Sep 17 00:00:00 2001 From: Christian Wiegand Date: Fri, 10 Dec 2021 07:50:50 +0100 Subject: [PATCH 1/4] Replace django.utils.http.urlquote with urllib.parse.quote for django 4.0 compatibility (see https://docs.djangoproject.com/en/4.0/releases/3.0/#deprecated-features-3-0) --- django_activeurl/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/django_activeurl/utils.py b/django_activeurl/utils.py index 901462b..8821dd5 100644 --- a/django_activeurl/utils.py +++ b/django_activeurl/utils.py @@ -3,9 +3,9 @@ from __future__ import absolute_import, unicode_literals from hashlib import md5 +from urllib.parse import quote from django.core.cache import cache -from django.utils.http import urlquote from django.utils.translation import get_language from lxml.etree import ParserError from lxml.html import fragment_fromstring, tostring @@ -155,9 +155,9 @@ def check_active(url, element, **kwargs): kwargs['full_path'].startswith(href) or # maybe an urlquoted href was supplied - urlquote(kwargs['full_path']).startswith(href) + quote(kwargs['full_path']).startswith(href) or - kwargs['full_path'].startswith(urlquote(href)) + kwargs['full_path'].startswith(quote(href)) ) else: logic = False @@ -167,9 +167,9 @@ def check_active(url, element, **kwargs): kwargs['full_path'] == href or # maybe an urlquoted href was supplied - urlquote(kwargs['full_path']) == href + quote(kwargs['full_path']) == href or - kwargs['full_path'] == urlquote(href) + kwargs['full_path'] == quote(href) ) # "active" url found if logic: From ee6888f2a4784e04c744efe8f80dd92ac4ec7ecf Mon Sep 17 00:00:00 2001 From: Christian Wiegand Date: Thu, 22 Sep 2022 23:05:39 +0200 Subject: [PATCH 2/4] Drop django < 3.2 support --- .coveragerc | 2 -- django_activeurl/conf.py | 4 +-- django_activeurl/models.py | 3 +-- django_activeurl/templatetags/activeurl.py | 17 ++++-------- django_activeurl/utils.py | 31 +++++++++------------- pytest.ini | 2 +- tests/urls.py | 20 +++++++------- tox.ini | 26 +++--------------- 8 files changed, 34 insertions(+), 71 deletions(-) diff --git a/.coveragerc b/.coveragerc index 8b6ea44..cd60182 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,3 @@ [run] -include = - django_activeurl/* omit = diff --git a/django_activeurl/conf.py b/django_activeurl/conf.py index f176e14..638ec35 100644 --- a/django_activeurl/conf.py +++ b/django_activeurl/conf.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from appconf import AppConf from django.conf import settings # noqa class ActiveUrlConf(AppConf): - '''default settings for django-activeurl''' + """default settings for django-activeurl""" # flipper for caching feature CACHE = True diff --git a/django_activeurl/models.py b/django_activeurl/models.py index 9558f0e..3ecf4dc 100644 --- a/django_activeurl/models.py +++ b/django_activeurl/models.py @@ -1,3 +1,2 @@ # -*- coding: utf-8 -*- -'''hello django test runner''' # pragma: no cover -from __future__ import absolute_import, unicode_literals # pragma: no cover +"""hello django test runner""" # pragma: no cover diff --git a/django_activeurl/templatetags/activeurl.py b/django_activeurl/templatetags/activeurl.py index 851aa99..a96765f 100644 --- a/django_activeurl/templatetags/activeurl.py +++ b/django_activeurl/templatetags/activeurl.py @@ -1,21 +1,18 @@ # -*- coding: utf-8 -*- -'''activeurl django template library''' -from __future__ import absolute_import, unicode_literals - +"""activeurl django template library""" from classytags.arguments import MultiKeywordArgument from classytags.core import Options, Tag from django import template -from ..utils import Configuration, render_content +from django_activeurl.utils import Configuration, render_content # django template library register = template.Library() +@register.tag(name='activeurl') class ActiveUrl(Tag, Configuration): - '''django template tag via django-classy-tags''' - # tag name - name = 'activeurl' + """django template tag via django-classy-tags""" # template tag arguments options = Options( @@ -25,7 +22,7 @@ class ActiveUrl(Tag, Configuration): ) def render_tag(self, context, kwargs, nodelist): - '''render content with "active" urls logic''' + """render content with "active" urls logic""" # load configuration from passed options self.load_configuration(**kwargs) @@ -51,7 +48,3 @@ def render_tag(self, context, kwargs, nodelist): ) return content - - -# register new template tag -register.tag(ActiveUrl) diff --git a/django_activeurl/utils.py b/django_activeurl/utils.py index 8821dd5..04a2967 100644 --- a/django_activeurl/utils.py +++ b/django_activeurl/utils.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -'''template engine independent utils''' -from __future__ import absolute_import, unicode_literals - +"""template engine independent utils""" from hashlib import md5 from urllib.parse import quote @@ -13,22 +11,19 @@ from .__about__ import __version__ from .conf import settings -try: - from django.utils.six.moves.urllib import parse as urlparse -except ImportError: - from urllib import parse as urlparse +from urllib import parse as urlparse class ImproperlyConfigured(Exception): - '''django-like ImproperlyConfigured exception''' + """django-like ImproperlyConfigured exception""" pass class Configuration(object): - '''abstract configuration''' + """abstract configuration""" def load_configuration(self, **kwargs): - '''load configuration, merge with default settings''' + """load configuration, merge with default settings""" # update passed arguments with default values for key in settings.ACTIVE_URL_KWARGS: kwargs.setdefault(key, settings.ACTIVE_URL_KWARGS[key]) @@ -44,7 +39,7 @@ def load_configuration(self, **kwargs): def get_cache_key(content, **kwargs): - '''generate cache key''' + """generate cache key""" cache_key = '' for key in sorted(kwargs.keys()): cache_key = '{cache_key}.{key}:{value}'.format( @@ -104,7 +99,7 @@ def yesno_to_bool(value, varname): def check_active(url, element, **kwargs): - '''check "active" url, apply css_class''' + """check "active" url, apply css_class""" menu = yesno_to_bool(kwargs['menu'], 'menu') ignore_params = yesno_to_bool(kwargs['ignore_params'], 'ignore_params') @@ -190,7 +185,7 @@ def check_active(url, element, **kwargs): def check_content(content, **kwargs): - '''check content for "active" urls''' + """check content for "active" urls""" # valid html root tag try: # render elements tree from content @@ -202,9 +197,9 @@ def check_content(content, **kwargs): if not kwargs['parent_tag']: kwargs['parent_tag'] = 'self' else: - raise ImproperlyConfigured(''' + raise ImproperlyConfigured(""" parent_tag=True is not allowed - ''') + """) elif kwargs['parent_tag'] is None: kwargs['parent_tag'] = 'self' # if parent_tag is False\None\''\a\self @@ -241,7 +236,7 @@ def check_content(content, **kwargs): # not valid html root tag except ParserError: # raise an exception with configuration example - raise ImproperlyConfigured(''' + raise ImproperlyConfigured(""" content of {% activeurl %} must have valid html root tag for example {% activeurl %} @@ -255,12 +250,12 @@ def check_content(content, **kwargs): {% endactiveurl %} in this case