summaryrefslogtreecommitdiff
path: root/www/trac-devel/files/patch-trac_util_text.py
blob: 64e40a62758cb37672d8f19c6dabf291dfc4f3b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--- trac/util/text.py.orig	2021-05-09 23:08:49 UTC
+++ trac/util/text.py
@@ -22,6 +22,7 @@ import base64
 import configparser
 import locale
 import os
+import pkg_resources
 import re
 import sys
 import textwrap
@@ -43,6 +44,11 @@ del Empty # shouldn't be used outside of Trac core
 
 # -- Jinja2
 
+_jinja2_ver = pkg_resources.parse_version(jinja2.__version__)
+_jinja2_exts = ['jinja2.ext.do', 'jinja2.ext.i18n']
+if _jinja2_ver < pkg_resources.parse_version('3'):
+    _jinja2_exts.append('jinja2.ext.with_')
+
 def jinja2env(**kwargs):
     """Creates a Jinja2 ``Environment`` configured with Trac conventions.
 
@@ -65,7 +71,7 @@ def jinja2env(**kwargs):
         line_comment_prefix='##',
         trim_blocks=True,
         lstrip_blocks=True,
-        extensions=['jinja2.ext.do', 'jinja2.ext.i18n', 'jinja2.ext.with_'],
+        extensions=list(_jinja2_exts),
         finalize=filterout_none,
         autoescape=autoescape_extensions,
     )