当前位置: 首页>>代码示例>>Python>>正文


Python ext.Extension方法代码示例

本文整理汇总了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) 
开发者ID:MoritzS,项目名称:jinja2-django-tags,代码行数:15,代码来源:tests.py

示例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 
开发者ID:italia,项目名称:daf-recipes,代码行数:9,代码来源:jinja_extensions.py

示例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) 
开发者ID:innolitics,项目名称:rdm,代码行数:8,代码来源:extensions_test.py

示例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 
开发者ID:Netflix-Skunkworks,项目名称:historical,代码行数:9,代码来源:extensions.py

示例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 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:11,代码来源:ext.py

示例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) 
开发者ID:kblomqvist,项目名称:yasha,代码行数:61,代码来源:cli.py


注:本文中的jinja2.ext.Extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。