mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-11-23 15:19:46 +00:00
namespace object works in async templates
This commit is contained in:
parent
5f95471a68
commit
0fd45a4dc7
@ -23,6 +23,8 @@ Unreleased
|
||||
:pr:`1182`
|
||||
- Fix line numbers in error messages when newlines are stripped.
|
||||
:pr:`1178`
|
||||
- The special ``namespace()`` assignment object in templates works in
|
||||
async environments. :issue:`1180`
|
||||
|
||||
|
||||
Version 2.11.1
|
||||
|
@ -697,7 +697,8 @@ class Namespace(object):
|
||||
self.__attrs = dict(*args, **kwargs)
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == "_Namespace__attrs":
|
||||
# __class__ is needed for the awaitable check in async mode
|
||||
if name in {"_Namespace__attrs", "__class__"}:
|
||||
return object.__getattribute__(self, name)
|
||||
try:
|
||||
return self.__attrs[name]
|
||||
|
@ -578,3 +578,14 @@ class TestAsyncForLoop(object):
|
||||
def test_awaitable_property_slicing(self, test_env_async):
|
||||
t = test_env_async.from_string("{% for x in a.b[:1] %}{{ x }}{% endfor %}")
|
||||
assert t.render(a=dict(b=[1, 2, 3])) == "1"
|
||||
|
||||
|
||||
def test_namespace_awaitable(test_env_async):
|
||||
async def _test():
|
||||
t = test_env_async.from_string(
|
||||
'{% set ns = namespace(foo="Bar") %}{{ ns.foo }}'
|
||||
)
|
||||
actual = await t.render_async()
|
||||
assert actual == "Bar"
|
||||
|
||||
run(_test())
|
||||
|
Loading…
Reference in New Issue
Block a user