]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Use print() function in both Python2 and Python 3 1093/head
authorcclauss <cclauss@me.com>
Sun, 27 Oct 2019 12:05:59 +0000 (13:05 +0100)
committercclauss <cclauss@me.com>
Sun, 27 Oct 2019 12:05:59 +0000 (13:05 +0100)
12 files changed:
examples/basic/cycle.py
examples/basic/debugger.py
examples/basic/inheritance.py
examples/basic/test.py
examples/basic/test_filter_and_linestatements.py
examples/basic/test_loop_filter.py
examples/basic/translate.py
examples/profile.py
examples/rwbench/rwbench.py
ext/django2jinja/django2jinja.py
ext/djangojinja2.py
scripts/jinja2-debug.py

index 73dd6325eb8064a5887935b32b80cafc385846c3..ecfd7b900945b42c6b538b22c0e5f37483ffe0b7 100644 (file)
@@ -1,13 +1,14 @@
+from __future__ import print_function
 from jinja2 import Environment
 
 
 env = Environment(line_statement_prefix="#", variable_start_string="${", variable_end_string="}")
 
 
-print env.from_string("""\
+print(env.from_string("""\
 <ul>
 # for item in range(10)
     <li class="${loop.cycle('odd', 'even')}">${item}</li>
 # endfor
 </ul>\
-""").render()
+""").render())
index 4291ff7ac4a9ff480520ca174dae7dd87adc3508..4c101ffda5222f0c5ed3b485717aa6200d4a73a4 100644 (file)
@@ -1,7 +1,8 @@
+from __future__ import print_function
 from jinja2 import Environment
 from jinja2.loaders import FileSystemLoader
 
 env = Environment(loader=FileSystemLoader('templates'))
 
 tmpl = env.get_template('broken.html')
-print tmpl.render(seq=[3, 2, 4, 5, 3, 2, 0, 2, 1])
+print(tmpl.render(seq=[3, 2, 4, 5, 3, 2, 0, 2, 1]))
index aa687c898a1378e341bd38c93ed60e9e41915f79..d5f0ae4fe3a85362e5a4212d181d5e88f13b172d 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from jinja2 import Environment
 from jinja2.loaders import DictLoader
 
@@ -9,4 +10,4 @@ env = Environment(loader=DictLoader({
 }))
 
 
-print env.get_template('c').render()
+print(env.get_template('c').render())
index 8f7dde79221057ddec963c7742597ada6b5cb6cb..44597269a02475f4f1b2826d2764bc1010475a95 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from jinja2 import Environment
 from jinja2.loaders import DictLoader
 
index 79e0a4b371a5d06bffff38c74b36ffa19594ccdd..81da750819756048d340afaeee3689766ce82233 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from jinja2 import Environment
 
 
index 0469d04e432af8acdab390d9848817716baedd5d..38a221d3d7cfde4837a13f89ba6591344f7231a0 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from jinja2 import Environment
 
 tmpl = Environment().from_string("""\
index 1fb8ee63bf284ba3adbba3788b359dd033bfc44f..8d1970f49d881a5fc430ce4e6f42043b6138129b 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 from jinja2 import Environment
 
 env = Environment(extensions=['jinja2.ext.i18n'])
@@ -8,7 +9,7 @@ env.globals['ngettext'] = lambda s, p, n: {
     '%(count)s user': '%(count)d Benutzer',
     '%(count)s users': '%(count)d Benutzer'
 }[n == 1 and s or p]
-print env.from_string("""\
+print(env.from_string("""\
 {% trans %}Hello {{ user }}!{% endtrans %}
 {% trans count=users|count %}{{ count }} user{% pluralize %}{{ count }} users{% endtrans %}
-""").render(user="someone", users=[1, 2, 3])
+""").render(user="someone", users=[1, 2, 3]))
index 0c907ae3f12a64e21087a9a591b1407b780b1bb1..e6deb47f63460617ce23f9c4c9f887ab3981db67 100644 (file)
@@ -1,3 +1,4 @@
+from __future__ import print_function
 try:
     from cProfile import Profile
 except ImportError:
@@ -42,7 +43,7 @@ jinja_template = JinjaEnvironment(
     variable_start_string="${",
     variable_end_string="}"
 ).from_string(source)
-print jinja_template.environment.compile(source, raw=True)
+print(jinja_template.environment.compile(source, raw=True))
 
 
 p = Profile()
index bf1d997aab777bd3cfb57bf6c4d99605ce1ced36..c8dc5f8838e693097ff9d5682a2bf1ac7ff98dda 100644 (file)
@@ -10,6 +10,7 @@
     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD.
 """
+from __future__ import print_function
 import sys
 from os.path import join, dirname, abspath
 try:
@@ -104,7 +105,7 @@ if __name__ == '__main__':
         sys.stdout.write('\r    %-20s%.4f seconds\n' % (test, t.timeit(number=200) / 200))
 
     if '-p' in sys.argv:
-        print 'Jinja profile'
+        print('Jinja profile')
         p = Profile()
         p.runcall(test_jinja)
         stats = Stats(p)
index d2f3717f2e846d0c19fcde7d05d40ac254ceb56b..c4629222815c5507a10c5534857da2845c768e5c 100644 (file)
@@ -68,6 +68,7 @@
     :copyright: (c) 2009 by the Jinja Team.
     :license: BSD.
 """
+from __future__ import print_function
 import re
 import os
 import sys
@@ -128,7 +129,7 @@ def convert_templates(output_dir, extensions=('.html', '.txt'), writer=None,
 
     if callback is None:
         def callback(template):
-            print template
+            print(template)
 
     for directory in settings.TEMPLATE_DIRS:
         for dirname, _, files in os.walk(directory):
@@ -308,7 +309,7 @@ class Writer(object):
         if node is not None and hasattr(node, 'source'):
             filename, lineno = self.get_location(*node.source)
             message = '[%s:%d] %s' % (filename, lineno, message)
-        print >> self.error_stream, message
+        print(message, file=self.error_stream)
 
     def translate_variable_name(self, var):
         """Performs variable name translation."""
index 70d60cbde9ae47b00163858c36d97f5c3f25759f..d32eadff7a7392d9e1a74357342aab26728337e0 100644 (file)
@@ -53,7 +53,7 @@ def get_template(template_name, globals=None):
     """Load a template."""
     try:
         return get_env().get_template(template_name, globals=globals)
-    except TemplateNotFound, e:
+    except TemplateNotFound as e:
         raise TemplateDoesNotExist(str(e))
 
 
index 71daeb98341e57ae99b8c13e47256f1e49baabb2..13350db6a05a19388e18c55328975afe1d1554ad 100755 (executable)
@@ -9,6 +9,7 @@
     :copyright: Copyright 2010 by Armin Ronacher.
     :license: BSD.
 """
+from __future__ import print_function
 import sys
 import jinja2
 from werkzeug import script