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/.gitignore b/.gitignore index a597499..c225d0d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ __pycache__ *~ .cache htmlcov +.idea diff --git a/django_activeurl/__init__.py b/django_activeurl/__init__.py index 96706af..604463e 100644 --- a/django_activeurl/__init__.py +++ b/django_activeurl/__init__.py @@ -1,4 +1,2 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from .__about__ import __version__ # noqa 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/ext/__init__.py b/django_activeurl/ext/__init__.py index 2c7594d..0b72afa 100644 --- a/django_activeurl/ext/__init__.py +++ b/django_activeurl/ext/__init__.py @@ -1,3 +1,2 @@ # -*- coding: utf-8 -*- '''jinja port''' -from __future__ import absolute_import, unicode_literals diff --git a/django_activeurl/ext/django_jinja.py b/django_activeurl/ext/django_jinja.py index 445b544..79f006b 100644 --- a/django_activeurl/ext/django_jinja.py +++ b/django_activeurl/ext/django_jinja.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- '''jinja extenions for django_jinja/django 1.8+''' -from __future__ import absolute_import, unicode_literals - from jinja2 import lexer, nodes from jinja2.ext import Extension 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/__init__.py b/django_activeurl/templatetags/__init__.py index 1170ec4..3aca112 100644 --- a/django_activeurl/templatetags/__init__.py +++ b/django_activeurl/templatetags/__init__.py @@ -1,3 +1,2 @@ # -*- coding: utf-8 -*- '''django template tags''' -from __future__ import absolute_import, unicode_literals 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 901462b..04a2967 100644 --- a/django_activeurl/utils.py +++ b/django_activeurl/utils.py @@ -1,11 +1,9 @@ # -*- 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 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 @@ -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') @@ -155,9 +150,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 +162,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: @@ -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