本文整理汇总了Python中pystache.context.ContextStack.create方法的典型用法代码示例。如果您正苦于以下问题:Python ContextStack.create方法的具体用法?Python ContextStack.create怎么用?Python ContextStack.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.context.ContextStack
的用法示例。
在下文中一共展示了ContextStack.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create__none
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__none(self):
"""
Test passing None.
"""
context = ContextStack.create({"foo": "bar"}, None)
self.assertEqual(context.get("foo"), "bar")
示例2: test_create__dictionary
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__dictionary(self):
"""
Test passing a dictionary.
"""
context = ContextStack.create({"foo": "bar"})
self.assertEqual(context.get("foo"), "bar")
示例3: test_create__precedence_keyword
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__precedence_keyword(self):
"""
Test precedence of keyword arguments.
"""
context = ContextStack.create({"foo": "bar"}, foo="buzz")
self.assertEqual(context.get("foo"), "buzz")
示例4: test_create__precedence_positional
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__precedence_positional(self):
"""
Test precedence of positional arguments.
"""
context = ContextStack.create({'foo': 'bar'}, {'foo': 'buzz'})
self.assertEqual(context.get('foo'), 'buzz')
示例5: test_create__kwarg
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__kwarg(self):
"""
Test passing a keyword argument.
"""
context = ContextStack.create(foo='bar')
self.assertEqual(context.get('foo'), 'bar')
示例6: test_create__context
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__context(self):
"""
Test passing a ContextStack instance.
"""
obj = ContextStack({'foo': 'bar'})
context = ContextStack.create(obj)
self.assertEqual(context.get('foo'), 'bar')
示例7: test_create__object
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def test_create__object(self):
"""
Test passing an object.
"""
class Foo(object):
foo = 'bar'
context = ContextStack.create(Foo())
self.assertEqual(context.get('foo'), 'bar')
示例8: _render_final
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def _render_final(self, render_func, *context, **kwargs):
"""
Arguments:
render_func: a function that accepts a RenderEngine and ContextStack
instance and returns a template rendering as a unicode string.
"""
stack = ContextStack.create(*context, **kwargs)
self._context = stack
engine = self._make_render_engine()
return render_func(engine, stack)
示例9: _render_string
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def _render_string(self, template, *context, **kwargs):
"""
Render the given template string using the given context.
"""
# RenderEngine.render() requires that the template string be unicode.
template = self._to_unicode_hard(template)
context = ContextStack.create(*context, **kwargs)
self._context = context
engine = self._make_render_engine()
rendered = engine.render(template, context)
return str(rendered)
示例10: render_name
# 需要导入模块: from pystache.context import ContextStack [as 别名]
# 或者: from pystache.context.ContextStack import create [as 别名]
def render_name(self, template_name, *context, **kwargs):
try:
parsed_template = None
cache_key = "%s_template_%s" % (options.site_name, template_name)
parsed_template = self.memcache_get(cache_key)
if not parsed_template:
loader = self._make_loader()
template = loader.load_name(template_name)
template = self._to_unicode_hard(template)
parsed_template = parse(template, None)
self.memcache_set(cache_key, parsed_template)
stack = ContextStack.create(*context, **kwargs)
self._context = stack
engine = self._make_render_engine()
return parsed_template.render(engine, stack)
except Exception as e:
logging.exception(e)
return e.message