當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。