From 4dba8df21d2d4203f9fe56b1e118047ef9dcd2db Mon Sep 17 00:00:00 2001 From: Karl Leuschen Date: Sun, 4 Sep 2022 11:31:03 -0300 Subject: [PATCH 1/3] Support latest Pythons and Djangos Unsupported versions of Python and Django have been dropped --- .travis.yml | 12 +++--- jstemplate/finders.py | 12 ++---- jstemplate/loading.py | 6 +-- jstemplate/preprocessors.py | 13 +++--- jstemplate/templatetags/base.py | 14 ++---- jstemplate/templatetags/handlebarsjs.py | 4 +- jstemplate/tests/project/project/settings.py | 2 + jstemplate/tests/project/project/urls.py | 18 +------- jstemplate/tests/project/project/views.py | 2 +- jstemplate/tests/test_finders.py | 16 +++---- jstemplate/tests/test_loading.py | 5 +-- jstemplate/tests/test_makemessages.py | 7 +-- jstemplate/tests/test_translation.py | 23 +++------- jstemplate/tests/test_ttag.py | 9 +--- jstemplate/tests/utils.py | 45 -------------------- requirements.txt | 6 +-- setup.py | 14 +++--- tox.ini | 11 +++-- 18 files changed, 55 insertions(+), 164 deletions(-) delete mode 100644 jstemplate/tests/utils.py diff --git a/.travis.yml b/.travis.yml index 05cf82c..a9ea734 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,14 @@ language: python python: - - "2.7" - - "3.4" + - "3.7" + - "3.8" + - "3.9" + - "3.10" env: - - DJANGO="django<1.7" # 1.6.x - - DJANGO="django<1.8" # 1.7.x - - DJANGO="django<1.9" # 1.8.x + - DJANGO="django<3" # 2.2.x + - DJANGO="django<4" # 3.2.x + - DJANGO="django<4.1" # 4.0.x - DJANGO="git+git://github.com/django/django.git@master#egg=django" # command to install dependencies diff --git a/jstemplate/finders.py b/jstemplate/finders.py index a4db0f0..66fbf51 100644 --- a/jstemplate/finders.py +++ b/jstemplate/finders.py @@ -1,15 +1,13 @@ -from __future__ import unicode_literals - +import glob +import os +import re +import sys import warnings -import glob, os, sys, re -import six - from importlib import import_module from .conf import conf - class BaseFinder(object): def find(self, name): raise NotImplementedError() @@ -115,8 +113,6 @@ def _get_app_template_dirs(): for dirname in conf.JSTEMPLATE_APP_DIRNAMES: template_dir = os.path.join(app_dir, dirname) if os.path.isdir(template_dir): - if not six.PY3: - template_dir = template_dir.decode(fs_encoding) ret.append(template_dir) return ret diff --git a/jstemplate/loading.py b/jstemplate/loading.py index 54306ac..df4f7a3 100644 --- a/jstemplate/loading.py +++ b/jstemplate/loading.py @@ -1,13 +1,9 @@ -from __future__ import unicode_literals - -import six from django.core.exceptions import ImproperlyConfigured from importlib import import_module from .conf import conf - def find(name): all_matches = {} @@ -16,7 +12,7 @@ def find(name): # .find may return a single string. The name of the template # will then be the name given to 'find' - if isinstance(matches, six.text_type): + if isinstance(matches, str): filepath = matches if name not in all_matches: all_matches[name] = filepath diff --git a/jstemplate/preprocessors.py b/jstemplate/preprocessors.py index 5463339..50d7bac 100644 --- a/jstemplate/preprocessors.py +++ b/jstemplate/preprocessors.py @@ -1,9 +1,8 @@ -from __future__ import unicode_literals - import re -from django.utils.translation import ugettext +from django.utils.translation import gettext from .conf import conf + class I18nPreprocessor(object): @property def tagnames(self): @@ -13,7 +12,7 @@ def tagnames(self): def short_trans_re(self): # Should match strings like: {{ _ "Hello, world! }} tagnames = '|'.join(['(?:{0})'.format(t) for t in self.tagnames]) - + left_side = r'''(?P\{\{\s*(?P(?:''' + tagnames + r''')\s+)(?P['"]))''' right_side = r'''(?P(?P=quote)\s*\}\})''' @@ -23,7 +22,7 @@ def short_trans_re(self): def long_trans_re(self): # Should match strings like: {{# _ }}Hello, {{ name }}.{{/ _ }} tagnames = '|'.join(['(?:{0})'.format(t) for t in self.tagnames]) - + start_tag = r'\{\{#\s*(?P' + tagnames + r')\s*\}\}' end_tag = r'\{\{\/\s*(?P=tag)\s*\}\}' @@ -33,14 +32,14 @@ def translate_short_form(self, match): """Translate a result of matching the compiled trans_re pattern.""" tag = match.group('tag') msg = match.group('msg') - msg = ugettext(msg) if len(msg) > 0 else '' + msg = gettext(msg) if len(msg) > 0 else '' string = match.group('left').replace(tag, '', 1) + msg + match.group('right') return string def translate_long_form(self, match): """Translate a result of matching the compiled trans_re pattern.""" msg = match.group('msg') - string = ugettext(msg) if len(msg) > 0 else '' + string = gettext(msg) if len(msg) > 0 else '' return string def process(self, content): diff --git a/jstemplate/templatetags/base.py b/jstemplate/templatetags/base.py index ad384e3..44a870c 100644 --- a/jstemplate/templatetags/base.py +++ b/jstemplate/templatetags/base.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals - -import six from django import template from ..conf import conf from ..loading import find, preprocess, JSTemplateNotFound @@ -45,13 +42,8 @@ def render_file(self, context, resolved_name, filepath): return output def read_template_file_contents(self, filepath): - if six.PY3: - with open(filepath, "r", encoding=conf.FILE_CHARSET) as fp: - template_text = fp.read() - else: - with open(filepath, "r") as fp: - template_text = fp.read().decode(conf.FILE_CHARSET) - + with open(filepath, "r") as fp: + template_text = fp.read() template_text = self.preprocess(template_text) return template_text @@ -71,4 +63,4 @@ def jstemplate_tag_helper(tagname, TagNodeClass, parser, token): "'%s' tag takes at least one argument: the name/id of " "the template, or a pattern matching a set of templates. " % tagname) - return TagNodeClass(*bits[1:]) \ No newline at end of file + return TagNodeClass(*bits[1:]) diff --git a/jstemplate/templatetags/handlebarsjs.py b/jstemplate/templatetags/handlebarsjs.py index 6e4a6d4..b942a69 100644 --- a/jstemplate/templatetags/handlebarsjs.py +++ b/jstemplate/templatetags/handlebarsjs.py @@ -1,6 +1,4 @@ -from __future__ import unicode_literals from django import template -from ..conf import conf from .base import BaseJSTemplateNode, jstemplate_tag_helper @@ -49,7 +47,7 @@ def handlebarsjs(parser, token): Finds the Handlebars template for the given name and renders it surrounded by the requisite Handlebars