comparison sat/tools/common/template.py @ 3038:5f3068915686

common (template): suppress jinja2 depreaction warning (to be removed once 2.10.1 is released)
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:41:36 +0200
parents ab2696e34d29
children 948833e3b542
comparison
equal deleted inserted replaced
3037:d314d4181f30 3038:5f3068915686
35 from babel.core import UnknownLocaleError 35 from babel.core import UnknownLocaleError
36 import pygments 36 import pygments
37 from pygments import lexers 37 from pygments import lexers
38 from pygments import formatters 38 from pygments import formatters
39 39
40 log = getLogger(__name__)
41
40 try: 42 try:
41 import sat_templates 43 import sat_templates
42 except ImportError: 44 except ImportError:
43 raise exceptions.MissingModule( 45 raise exceptions.MissingModule(
44 "sat_templates module is not available, please install it or check your path to " 46 "sat_templates module is not available, please install it or check your path to "
46 ) 48 )
47 else: 49 else:
48 sat_templates # to avoid pyflakes warning 50 sat_templates # to avoid pyflakes warning
49 51
50 try: 52 try:
51 import jinja2 53 import warnings
54
55 with warnings.catch_warnings():
56 warnings.filterwarnings("ignore", category=DeprecationWarning)
57 import jinja2
58 jinja2_version = tuple([int(n) for n in jinja2.__version__.split('.')])
59 if jinja2_version > (2, 10, 1):
60 log.warning("New jinja2 version available, warnings catches can be removed")
52 except: 61 except:
53 raise exceptions.MissingModule( 62 raise exceptions.MissingModule(
54 "Missing module jinja2, please install it from http://jinja.pocoo.org or with " 63 "Missing module jinja2, please install it from http://jinja.pocoo.org or with "
55 "pip install jinja2" 64 "pip install jinja2"
56 ) 65 )
60 from jinja2 import utils 69 from jinja2 import utils
61 from jinja2 import TemplateNotFound 70 from jinja2 import TemplateNotFound
62 from jinja2 import contextfilter 71 from jinja2 import contextfilter
63 from jinja2.loaders import split_template_path 72 from jinja2.loaders import split_template_path
64 from lxml import etree 73 from lxml import etree
65
66 log = getLogger(__name__)
67 74
68 HTML_EXT = ("html", "xhtml") 75 HTML_EXT = ("html", "xhtml")
69 RE_ATTR_ESCAPE = re.compile(r"[^a-z_-]") 76 RE_ATTR_ESCAPE = re.compile(r"[^a-z_-]")
70 SITE_RESERVED_NAMES = ("sat",) 77 SITE_RESERVED_NAMES = ("sat",)
71 TPL_RESERVED_CHARS = r"()/." 78 TPL_RESERVED_CHARS = r"()/."