Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:15-SP1
salt.26880
fix-jinja2-contextfuntion-base-on-version-bsc-1...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix-jinja2-contextfuntion-base-on-version-bsc-119874.patch of Package salt.26880
From 65494338f5a9bdaa0be27afab3da3a03a92d8cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= <psuarezhernandez@suse.com> Date: Fri, 8 Jul 2022 13:35:50 +0100 Subject: [PATCH] fix: jinja2 contextfuntion base on version (bsc#1198744) (#520) --- salt/utils/jinja.py | 16 ++++++++++++++-- tests/unit/utils/test_jinja.py | 8 +++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/salt/utils/jinja.py b/salt/utils/jinja.py index 0cb70bf64a..6b5b0d4e81 100644 --- a/salt/utils/jinja.py +++ b/salt/utils/jinja.py @@ -25,7 +25,7 @@ import salt.utils.json import salt.utils.stringutils import salt.utils.url import salt.utils.yaml -from jinja2 import BaseLoader, Markup, TemplateNotFound, nodes +from jinja2 import BaseLoader, TemplateNotFound, nodes from jinja2.environment import TemplateModule from jinja2.exceptions import TemplateRuntimeError from jinja2.ext import Extension @@ -34,6 +34,12 @@ from salt.utils.decorators.jinja import jinja_filter, jinja_global, jinja_test from salt.utils.odict import OrderedDict from salt.utils.versions import LooseVersion +try: + from markupsafe import Markup +except ImportError: + # jinja < 3.1 + from jinja2 import Markup + log = logging.getLogger(__name__) __all__ = ["SaltCacheLoader", "SerializerExtension"] @@ -706,7 +712,13 @@ def method_call(obj, f_name, *f_args, **f_kwargs): return getattr(obj, f_name, lambda *args, **kwargs: None)(*f_args, **f_kwargs) -@jinja2.contextfunction +try: + contextfunction = jinja2.contextfunction +except AttributeError: + contextfunction = jinja2.pass_context + + +@contextfunction def show_full_context(ctx): return salt.utils.data.simple_types_filter( {key: value for key, value in ctx.items()} diff --git a/tests/unit/utils/test_jinja.py b/tests/unit/utils/test_jinja.py index 6502831aff..6bbcf9ef6f 100644 --- a/tests/unit/utils/test_jinja.py +++ b/tests/unit/utils/test_jinja.py @@ -22,7 +22,7 @@ import salt.utils.files import salt.utils.json import salt.utils.stringutils import salt.utils.yaml -from jinja2 import DictLoader, Environment, Markup, exceptions +from jinja2 import DictLoader, Environment, exceptions from salt.exceptions import SaltRenderError from salt.utils.decorators.jinja import JinjaFilter from salt.utils.jinja import ( @@ -46,6 +46,12 @@ try: except ImportError: HAS_TIMELIB = False +try: + from markupsafe import Markup +except ImportError: + # jinja < 3.1 + from jinja2 import Markup + BLINESEP = salt.utils.stringutils.to_bytes(os.linesep) -- 2.36.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor