本文整理匯總了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)