コード例 #1
0
ファイル: genshi.py プロジェクト: Cito/tg2
    def create(cls, config, app_globals):
        """Setup a renderer and loader for Genshi templates.

        Override this to customize the way that the internationalization
        filter, template loader

        """
        if genshi is None:  # pragma: no cover
            # Genshi not available
            return None

        if config.get('use_dotted_templatenames', True):
            TemplateLoader = DottedTemplateLoader
            template_loader_args = {'dotted_finder': app_globals.dotted_filename_finder}
        else:
            TemplateLoader = GenshiTemplateLoader
            template_loader_args = {}

        loader = TemplateLoader(search_path=config.paths.templates,
                                max_cache_size=asint(config.get('genshi.max_cache_size', 30)),
                                auto_reload=config.auto_reload_templates,
                                callback=cls.on_template_loaded,
                                **template_loader_args)

        return {'genshi': cls(loader, config)}
コード例 #2
0
ファイル: genshi.py プロジェクト: garrettmc/TGWikiTutorial
    def create(cls, config, app_globals):
        """Setup a renderer and loader for Genshi templates.

        Override this to customize the way that the internationalization
        filter, template loader

        """
        if genshi is None:  # pragma: no cover
            # Genshi not available
            return None

        if config.get('use_dotted_templatenames', True):
            TemplateLoader = DottedTemplateLoader
            template_loader_args = {
                'dotted_finder': app_globals.dotted_filename_finder
            }
        else:
            TemplateLoader = GenshiTemplateLoader
            template_loader_args = {}

        loader = TemplateLoader(search_path=config.paths.templates,
                                max_cache_size=asint(
                                    config.get('genshi.max_cache_size', 30)),
                                auto_reload=config.auto_reload_templates,
                                callback=cls.on_template_loaded,
                                **template_loader_args)

        return {'genshi': cls(loader, config)}
コード例 #3
0
    def create(cls, config, app_globals):
        """Setup a renderer and loader for Genshi templates.

        Override this to customize the way that the internationalization
        filter, template loader

        """
        if genshi is None:  # pragma: no cover
            # Genshi not available
            return None

        options = coerce_config(config, 'templating.genshi.',
                                cls.CONFIG_OPTIONS)

        # Patch for Genshi on Python3.4
        if options.get('name_constant_patch', False):  # pragma: no cover
            from genshi.template.astutil import ASTCodeGenerator
            if not hasattr(ASTCodeGenerator, 'visit_NameConstant'):

                def _visit_NameConstant(self, node):
                    if node.value is None:
                        self._write('None')
                    elif node.value is True:
                        self._write('True')
                    elif node.value is False:
                        self._write('False')
                    else:
                        raise Exception("Unknown NameConstant %r" %
                                        (node.value, ))

                ASTCodeGenerator.visit_NameConstant = _visit_NameConstant

        if config.get('use_dotted_templatenames', True):
            TemplateLoader = DottedTemplateLoader
            template_loader_args = {
                'dotted_finder': app_globals.dotted_filename_finder
            }
        else:
            TemplateLoader = GenshiTemplateLoader
            template_loader_args = {}

        loader = TemplateLoader(search_path=config['paths'].templates,
                                max_cache_size=options.get(
                                    'max_cache_size',
                                    asint(
                                        config.get('genshi.max_cache_size',
                                                   30))),
                                auto_reload=config['auto_reload_templates'],
                                callback=cls.on_template_loaded,
                                **template_loader_args)

        return {'genshi': cls(loader, config)}
コード例 #4
0
    def create(cls, config, app_globals):
        """Setup a renderer and loader for Genshi templates.

        Override this to customize the way that the internationalization
        filter, template loader

        """
        if genshi is None:  # pragma: no cover
            # Genshi not available
            return None

        options = coerce_config(config, 'templating.genshi.', cls.CONFIG_OPTIONS)

        # Patch for Genshi on Python3.4
        if options.get('name_constant_patch', False):
            from genshi.template.astutil import ASTCodeGenerator
            if not hasattr(ASTCodeGenerator, 'visit_NameConstant'):
                def _visit_NameConstant(self, node):
                    if node.value is None:
                        self._write('None')
                    elif node.value is True:
                        self._write('True')
                    elif node.value is False:
                        self._write('False')
                    else:
                        raise Exception("Unknown NameConstant %r" % (node.value,))
                ASTCodeGenerator.visit_NameConstant = _visit_NameConstant

        if config.get('use_dotted_templatenames', True):
            TemplateLoader = DottedTemplateLoader
            template_loader_args = {'dotted_finder': app_globals.dotted_filename_finder}
        else:
            TemplateLoader = GenshiTemplateLoader
            template_loader_args = {}

        loader = TemplateLoader(search_path=config['paths'].templates,
                                max_cache_size=options.get(
                                    'max_cache_size',
                                    asint(config.get('genshi.max_cache_size', 30))
                                ),
                                auto_reload=config['auto_reload_templates'],
                                callback=cls.on_template_loaded,
                                **template_loader_args)

        return {'genshi': cls(loader, config)}
コード例 #5
0
    def create(cls, config, app_globals):
        # this has evolved over the age of allura, and upgrades of TG
        # the parent JinjaRenderer logic is different, some may be better and hasn't been incorporated into ours yet

        bcc = cls._setup_bytecode_cache()
        jinja2_env = jinja2.Environment(
            loader=PackagePathLoader(),
            auto_reload=config['auto_reload_templates'],
            autoescape=True,
            bytecode_cache=bcc,
            cache_size=asint(config.get('jinja_cache_size', -1)),
            extensions=['jinja2.ext.do', 'jinja2.ext.i18n'])
        jinja2_env.install_gettext_translations(tg.i18n)
        jinja2_env.filters['datetimeformat'] = helpers.datetimeformat
        jinja2_env.filters['filter'] = lambda s, t=None: list(filter(t and jinja2_env.tests[t], s))
        jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter
        jinja2_env.globals.update({'hasattr': hasattr})
        config['tg.app_globals'].jinja2_env = jinja2_env  # TG doesn't need this, but we use g.jinja2_env a lot
        return {'jinja': cls(jinja2_env)}
コード例 #6
0
 def test_nonstring(self):
     asint(['55'])
コード例 #7
0
 def test_nan(self):
     asint('hello')
コード例 #8
0
 def test_fine(self):
     assert asint('55') == 55
コード例 #9
0
 def test_nonstring(self):
     asint([True])
コード例 #10
0
ファイル: test_converters.py プロジェクト: TurboGears/tg2
 def test_nonstring(self):
     asint(['55'])
コード例 #11
0
ファイル: test_converters.py プロジェクト: TurboGears/tg2
 def test_nan(self):
     asint('hello')
コード例 #12
0
ファイル: test_converters.py プロジェクト: TurboGears/tg2
 def test_fine(self):
     assert asint('55') == 55
コード例 #13
0
ファイル: test_converters.py プロジェクト: TurboGears/tg2
 def test_nonstring(self):
     asint([True])