Skip to content

Commit 70f8085

Browse files
committed
PY2 repairs
1 parent 97be7ec commit 70f8085

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

mig/shared/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,9 @@ def html_format(configuration, ret_val, ret_msg, out_obj):
753753
i['template_name'],
754754
i['template_group'],
755755
'html',
756-
store.context.extend(**i['template_args'])
757756
)
758-
lines.append(template.render())
757+
bound = store.context.extend(template, i['template_args'])
758+
lines.append(bound.render())
759759
elif i['object_type'] == 'error_text':
760760
msg = "%(text)s" % i
761761
if i.get('exc', False):

mig/shared/templates/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,20 @@ def template_dirs():
5252
return _all_template_dirs
5353

5454

55+
class _BonundTemplate:
56+
def __init__(self, template, template_args):
57+
self.tmpl = template
58+
self.args = template_args
59+
60+
61+
def render(self):
62+
return self.tmpl.render(**self.args)
63+
64+
5565
class _FormatContext:
5666
def __init__(self, configuration):
5767
self.output_format = None
5868
self.configuration = configuration
59-
self.conf_map = ChainMap(configuration)
6069
self.script_map = {}
6170
self.style_map = {}
6271

@@ -66,8 +75,8 @@ def __getitem__(self, key):
6675
def __iter__(self):
6776
return iter(self.__dict__)
6877

69-
def extend(self, **kwargs):
70-
return ChainMap(kwargs, self)
78+
def extend(self, template, template_args):
79+
return _BonundTemplate(template, ChainMap(template_args, self))
7180

7281

7382
class TemplateStore:

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# https://pip.pypa.io/en/stable/reference/requirement-specifiers/
33
future
44

5+
chainmap;python_version < "3.3"
6+
57
# cgi was removed from the standard library in Python 3.13
68
legacy-cgi;python_version >= "3.13"
79

@@ -26,7 +28,8 @@ email-validator;python_version >= "3.7"
2628
email-validator<2.0;python_version >= "3" and python_version < "3.7"
2729
email-validator<1.3;python_version < "3"
2830

29-
jinja2
31+
jinja2<3;python_version < "3"
32+
jinja2;python_version >= "3.7"
3033

3134
# NOTE: additional optional dependencies depending on site conf are listed
3235
# in recommended.txt and can be installed in the same manner by pointing

tests/test_mig_shared_templates.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from __future__ import print_function
1+
import shutil
22

33
from tests.support import MigTestCase, testmain
44

55
from mig.shared.templates import TemplateStore, cache_dir, template_dirs
66

77

88
class TestMigSharedTemplates(MigTestCase):
9+
@classmethod
10+
def tearDownClass(cls):
11+
shutil.rmtree(cache_dir(), ignore_errors=True)
12+
913
def _provide_configuration(self):
1014
return 'testconfig'
1115

0 commit comments

Comments
 (0)