本文整理汇总了Python中pystache.context.Context.create方法的典型用法代码示例。如果您正苦于以下问题:Python Context.create方法的具体用法?Python Context.create怎么用?Python Context.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.context.Context
的用法示例。
在下文中一共展示了Context.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create__precedence_keyword
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__precedence_keyword(self):
"""
Test precedence of keyword arguments.
"""
context = Context.create({'foo': 'bar'}, foo='buzz')
self.assertEqual(context.get('foo'), 'buzz')
示例2: test_create__kwarg
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__kwarg(self):
"""
Test passing a keyword argument.
"""
context = Context.create(foo='bar')
self.assertEqual(context.get('foo'), 'bar')
示例3: test_create__precedence_positional
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__precedence_positional(self):
"""
Test precedence of positional arguments.
"""
context = Context.create({'foo': 'bar'}, {'foo': 'buzz'})
self.assertEqual(context.get('foo'), 'buzz')
示例4: test_create__none
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__none(self):
"""
Test passing None.
"""
context = Context.create({'foo': 'bar'}, None)
self.assertEqual(context.get('foo'), 'bar')
示例5: test_create__dictionary
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__dictionary(self):
"""
Test passing a dictionary.
"""
context = Context.create({'foo': 'bar'})
self.assertEqual(context.get('foo'), 'bar')
示例6: test_create__context
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__context(self):
"""
Test passing a Context instance.
"""
obj = Context({'foo': 'bar'})
context = Context.create(obj)
self.assertEqual(context.get('foo'), 'bar')
示例7: test_create__object
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context import create [as 别名]
def test_create__object(self):
"""
Test passing an object.
"""
class Foo(object):
foo = 'bar'
context = Context.create(Foo())
self.assertEqual(context.get('foo'), 'bar')
示例8: _render_string
# 需要导入模块: from pystache.context import Context [as 别名]
# 或者: from pystache.context.Context 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 = Context.create(*context, **kwargs)
self._context = context
engine = self._make_render_engine()
rendered = engine.render(template, context)
return unicode(rendered)