本文整理汇总了Python中jinja2.ext.Extension方法的典型用法代码示例。如果您正苦于以下问题:Python ext.Extension方法的具体用法?Python ext.Extension怎么用?Python ext.Extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.ext
的用法示例。
在下文中一共展示了ext.Extension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_existing_finalize
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def test_existing_finalize(self):
finalize_mock = mock.Mock(side_effect=lambda s: s)
class TestExtension(Extension):
def __init__(self, environment):
environment.finalize = finalize_mock
env = Environment(extensions=[TestExtension, DjangoL10n])
template = env.from_string("{{ foo }}")
translation.activate('de')
self.assertEqual('1,23', template.render({'foo': 1.23}))
finalize_mock.assert_called_with(1.23)
示例2: __init__
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def __init__(self, environment):
ext.Extension.__init__(self, environment)
try:
self.searchpath = environment.loader.searchpath[:]
except AttributeError:
# this isn't available on message extraction
pass
示例3: test_dynamic_class_loader
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def test_dynamic_class_loader():
extensions = dynamic_class_loader(['rdm.md_extensions.audit_notes.AuditNoteExclusionExtension'])
assert extensions is not None
assert len(extensions) == 1
extension = extensions[0]
assert issubclass(extension, Extension)
示例4: __init__
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def __init__(self, environment):
"""Instantiates the Historical Extension
:param environment:
"""
super(HistoricalExtension, self).__init__(environment)
environment.filters['titlecase'] = titlecase
示例5: test_extension_ordering
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def test_extension_ordering(self):
class T1(Extension):
priority = 1
class T2(Extension):
priority = 2
env = Environment(extensions=[T1, T2])
ext = list(env.iter_extensions())
assert ext[0].__class__ is T1
assert ext[1].__class__ is T2
示例6: load_extensions
# 需要导入模块: from jinja2 import ext [as 别名]
# 或者: from jinja2.ext import Extension [as 别名]
def load_extensions(file):
from jinja2.ext import Extension
import inspect
tests = dict()
filters = dict()
parsers = dict()
classes = []
try:
module = load_python_module(file)
except NameError as e:
msg = 'Unable to load extensions, {}'
raise ClickException(msg.format(e))
except SyntaxError as e:
msg = "Unable to load extensions\n{} ({}, line {})"
error = e.msg[0].upper() + e.msg[1:]
filename = os.path.relpath(e.filename)
raise ClickException(msg.format(error, filename, e.lineno))
for attr in [getattr(module, x) for x in dir(module)]:
if inspect.isfunction(attr):
if attr.__name__.startswith('test_'):
name = attr.__name__[5:]
tests[name] = attr
if attr.__name__.startswith('filter_'):
name = attr.__name__[7:]
filters[name] = attr
if attr.__name__.startswith('parse_'):
name = attr.__name__[6:]
parsers['.' + name] = attr
if inspect.isclass(attr):
if issubclass(attr, Extension):
classes.append(attr)
import jinja2.defaults
for name, obj in inspect.getmembers(module):
if name in jinja2.defaults.__all__:
setattr(jinja2.defaults, name, obj)
try:
TESTS.update(module.TESTS)
except AttributeError:
TESTS.update(tests)
try:
FILTERS.update(module.FILTERS)
except AttributeError:
FILTERS.update(filters)
try:
PARSERS.update(module.PARSERS)
except AttributeError:
PARSERS.update(parsers)
try:
CLASSES.extend(module.CLASSES)
except AttributeError:
CLASSES.extend(classes)