Skip to content

Commit

Permalink
Remove Python 2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Vallet authored and timgraham committed Jan 21, 2020
1 parent 6590a87 commit d642e63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 4 additions & 10 deletions django_hosts/resolvers.py
Expand Up @@ -4,17 +4,15 @@
``reverse_host`` helper functions (or its lazy cousins).
"""
import re

from functools import lru_cache
from importlib import import_module

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.signals import setting_changed
from django.urls import NoReverseMatch, reverse as reverse_path
from django.utils import six
from django.utils.encoding import iri_to_uri, force_text
from django.utils.encoding import iri_to_uri
from django.utils.functional import lazy
from django.utils.lru_cache import lru_cache
from django.utils.regex_helper import normalize

from .defaults import host as host_cls
Expand Down Expand Up @@ -102,19 +100,15 @@ def reverse_host(host, args=None, kwargs=None):
if not isinstance(host, host_cls):
host = get_host(host)

unicode_args = [force_text(x) for x in args]
unicode_kwargs = dict(((k, force_text(v))
for (k, v) in six.iteritems(kwargs)))

for result, params in normalize(host.regex):
if args:
if len(args) != len(params):
continue
candidate = result % dict(zip(params, unicode_args))
candidate = result % dict(zip(params, args))
else:
if set(kwargs.keys()) != set(params):
continue
candidate = result % unicode_kwargs
candidate = result % kwargs

if re.match(host.regex, candidate, re.UNICODE): # pragma: no cover
parent_host = getattr(settings, 'PARENT_HOST', '').lstrip('.')
Expand Down
3 changes: 1 addition & 2 deletions django_hosts/templatetags/hosts.py
Expand Up @@ -3,7 +3,6 @@
from django import template
from django.conf import settings
from django.template import TemplateSyntaxError
from django.utils import six
from django.template.base import FilterExpression
from django.template.defaulttags import URLNode
from django.utils.encoding import iri_to_uri, smart_str
Expand Down Expand Up @@ -52,7 +51,7 @@ def render(self, context):

host_kwargs = dict((smart_str(k, 'ascii'),
self.maybe_resolve(v, context))
for k, v in six.iteritems(self.host_kwargs))
for k, v in self.host_kwargs.items())

if self.scheme:
scheme = normalize_scheme(self.maybe_resolve(self.scheme, context))
Expand Down

0 comments on commit d642e63

Please sign in to comment.