Skip to content

Commit 3ae6daa

Browse files
committed
Merge branch 'karlrl-support-new-python-and-django'
2 parents 4f44a0a + dfdb96a commit 3ae6daa

File tree

19 files changed

+59
-163
lines changed

19 files changed

+59
-163
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: python
22
python:
3-
- "2.7"
4-
- "3.4"
3+
- "3.7"
4+
- "3.8"
5+
- "3.9"
6+
- "3.10"
57

68
env:
7-
- DJANGO="django<1.9" # 1.8.x
89
- DJANGO="django<3" # 2.2.x
910
- DJANGO="django<4" # 3.2.x
1011
- DJANGO="git+git://github.com/django/django.git@master#egg=django"

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGES
22
=======
33

4+
2.0.0
5+
-----
6+
7+
Thank you to @karlrl for the following changes:
8+
- Support Python 3.7-3.10
9+
- Support Django 2.2-4.1
10+
- Drop support for Python<3.7 and Django<3.2
11+
412
1.3.9
513
-----
614

jstemplate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.3.9"
1+
__version__ = "2.0.0"

jstemplate/finders.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from __future__ import unicode_literals
2-
1+
import glob
2+
import os
3+
import re
4+
import sys
35
import warnings
4-
import glob, os, sys, re
5-
import six
6-
76
from importlib import import_module
87

98
from .conf import conf
109

1110

12-
1311
class BaseFinder(object):
1412
def find(self, name):
1513
raise NotImplementedError()
@@ -115,8 +113,6 @@ def _get_app_template_dirs():
115113
for dirname in conf.JSTEMPLATE_APP_DIRNAMES:
116114
template_dir = os.path.join(app_dir, dirname)
117115
if os.path.isdir(template_dir):
118-
if not six.PY3:
119-
template_dir = template_dir.decode(fs_encoding)
120116
ret.append(template_dir)
121117
return ret
122118

jstemplate/loading.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
from __future__ import unicode_literals
2-
3-
import six
41
from django.core.exceptions import ImproperlyConfigured
52
from importlib import import_module
63

74
from .conf import conf
85

96

10-
117
def find(name):
128
all_matches = {}
139

@@ -16,7 +12,7 @@ def find(name):
1612

1713
# <finder>.find may return a single string. The name of the template
1814
# will then be the name given to 'find'
19-
if isinstance(matches, six.text_type):
15+
if isinstance(matches, str):
2016
filepath = matches
2117
if name not in all_matches:
2218
all_matches[name] = filepath

jstemplate/preprocessors.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from __future__ import unicode_literals
2-
31
import re
4-
from django.utils.translation import ugettext
2+
from django.utils.translation import gettext
53
from .conf import conf
64

5+
76
class I18nPreprocessor(object):
87
@property
98
def tagnames(self):
@@ -13,7 +12,7 @@ def tagnames(self):
1312
def short_trans_re(self):
1413
# Should match strings like: {{ _ "Hello, world! }}
1514
tagnames = '|'.join(['(?:{0})'.format(t) for t in self.tagnames])
16-
15+
1716
left_side = r'''(?P<left>\{\{\s*(?P<tag>(?:''' + tagnames + r''')\s+)(?P<quote>['"]))'''
1817
right_side = r'''(?P<right>(?P=quote)\s*\}\})'''
1918

@@ -23,7 +22,7 @@ def short_trans_re(self):
2322
def long_trans_re(self):
2423
# Should match strings like: {{# _ }}Hello, {{ name }}.{{/ _ }}
2524
tagnames = '|'.join(['(?:{0})'.format(t) for t in self.tagnames])
26-
25+
2726
start_tag = r'\{\{#\s*(?P<tag>' + tagnames + r')\s*\}\}'
2827
end_tag = r'\{\{\/\s*(?P=tag)\s*\}\}'
2928

@@ -33,14 +32,14 @@ def translate_short_form(self, match):
3332
"""Translate a result of matching the compiled trans_re pattern."""
3433
tag = match.group('tag')
3534
msg = match.group('msg')
36-
msg = ugettext(msg) if len(msg) > 0 else ''
35+
msg = gettext(msg) if len(msg) > 0 else ''
3736
string = match.group('left').replace(tag, '', 1) + msg + match.group('right')
3837
return string
3938

4039
def translate_long_form(self, match):
4140
"""Translate a result of matching the compiled trans_re pattern."""
4241
msg = match.group('msg')
43-
string = ugettext(msg) if len(msg) > 0 else ''
42+
string = gettext(msg) if len(msg) > 0 else ''
4443
return string
4544

4645
def process(self, content):

jstemplate/templatetags/base.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import unicode_literals
2-
3-
import six
41
from django import template
52
from ..conf import conf
63
from ..loading import find, preprocess, JSTemplateNotFound
@@ -49,13 +46,8 @@ def read_template_file_contents(self, filepath):
4946
# Django 3.1, UTF-8 is always expected.
5047
encoding = getattr(conf, 'FILE_CHARSET', 'utf-8')
5148

52-
if six.PY3:
53-
with open(filepath, "r", encoding=encoding) as fp:
54-
template_text = fp.read()
55-
else:
56-
with open(filepath, "r") as fp:
57-
template_text = fp.read().decode(encoding)
58-
49+
with open(filepath, "r", encoding=encoding) as fp:
50+
template_text = fp.read()
5951
template_text = self.preprocess(template_text)
6052
return template_text
6153

@@ -75,4 +67,4 @@ def jstemplate_tag_helper(tagname, TagNodeClass, parser, token):
7567
"'%s' tag takes at least one argument: the name/id of "
7668
"the template, or a pattern matching a set of templates. "
7769
% tagname)
78-
return TagNodeClass(*bits[1:])
70+
return TagNodeClass(*bits[1:])

jstemplate/templatetags/handlebarsjs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import unicode_literals
21
from django import template
3-
from ..conf import conf
42
from .base import BaseJSTemplateNode, jstemplate_tag_helper
53

64

@@ -49,7 +47,7 @@ def handlebarsjs(parser, token):
4947
Finds the Handlebars template for the given name and renders it surrounded
5048
by the requisite Handlebars <script> tags.
5149
52-
We don't use the jstemplate_tag_helper here, since we can take an
50+
We don't use the jstemplate_tag_helper here, since we can take an
5351
additional parameter denoting whether to register partials inline.
5452
5553
"""
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
from django.conf.urls import *
2-
3-
# Uncomment the next two lines to enable the admin:
4-
# from django.contrib import admin
5-
# admin.autodiscover()
6-
7-
urlpatterns = [
8-
# Examples:
9-
# url(r'^$', 'project.views.home', name='home'),
10-
# url(r'^project/', include('project.foo.urls')),
11-
12-
# Uncomment the admin/doc line below to enable admin documentation:
13-
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
14-
15-
# Uncomment the next line to enable the admin:
16-
# url(r'^admin/', include(admin.site.urls)),
17-
]
1+
urlpatterns = []
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.utils.translation import ugettext as _
1+
from django.utils.translation import gettext as _
22

33
def f():
44
return _('View message')

0 commit comments

Comments
 (0)