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


Python text.NewTextTemplate类代码示例

本文整理汇总了Python中genshi.template.text.NewTextTemplate的典型用法代码示例。如果您正苦于以下问题:Python NewTextTemplate类的具体用法?Python NewTextTemplate怎么用?Python NewTextTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NewTextTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_exec_import

 def test_exec_import(self):
     tmpl = NewTextTemplate(u"""{% python from datetime import timedelta %}
     ${timedelta(days=2)}
     """)
     self.assertEqual("""
     2 days, 0:00:00
     """, str(tmpl.generate()))
开发者ID:alon,项目名称:polinax,代码行数:7,代码来源:text.py

示例2: test_exec_import

 def test_exec_import(self):
     tmpl = NewTextTemplate("""{% python from datetime import timedelta %}
     ${timedelta(days=2)}
     """)
     self.assertEqual("""
     2 days, 0:00:00
     """, tmpl.generate().render(encoding=None))
开发者ID:292388900,项目名称:OmniMarkupPreviewer,代码行数:7,代码来源:text.py

示例3: test_end_with_args

    def test_end_with_args(self):
        tmpl = NewTextTemplate(
            """
{% if foo %}
  bar
{% end 'if foo' %}"""
        )
        self.assertEqual("\n", tmpl.generate(foo=False).render(encoding=None))
开发者ID:endorno,项目名称:Sublime-Text-2,代码行数:8,代码来源:text.py

示例4: test_exec_def

 def test_exec_def(self):
     tmpl = NewTextTemplate("""{% python
     def foo():
         return 42
     %}
     ${foo()}
     """)
     self.assertEqual("""
     42
     """, tmpl.generate().render(encoding=None))
开发者ID:292388900,项目名称:OmniMarkupPreviewer,代码行数:10,代码来源:text.py

示例5: test_exec_def

 def test_exec_def(self):
     tmpl = NewTextTemplate(u"""{% python
     def foo():
         return 42
     %}
     ${foo()}
     """)
     self.assertEqual(u"""
     42
     """, str(tmpl.generate()))
开发者ID:alon,项目名称:polinax,代码行数:10,代码来源:text.py

示例6: _notify_admins

    def _notify_admins(self, permission, email_path, debug="false"):
        is_debug = debug.lower() in ("true", "yes")

        if permission != "TRAC_ADMIN":
            raise AdminCommandError("Only TRAC_ADMIN permission is supported")

        # A standard thing to do in IAdminCommandProviders (otherwise,
        # accessing project_identifier would give errors)
        if not hasattr(self.env, "project_identifier"):
            MultiProjectEnvironmentInit(self.env).environment_needs_upgrade(None)

        env_name = self.env.project_identifier
        if env_name == self.env.config.get("multiproject", "sys_home_project_name"):
            raise AdminCommandError("Command does not support home project")

        if not os.path.exists(email_path):
            raise AdminCommandError(_("Email template was not found!"))

        project = Project.get(self.env)
        email_template = ""
        try:
            with open(email_path) as fd:
                email_template = fd.read()
        except OSError as e:
            raise AdminCommandError(_("Error with opening file %(path)s: %(error_msg)s", path=email_path, error_msg=e))
        except Exception as e:
            raise AdminCommandError(
                _("Unknown error when parsing file %(path)s: %(error_msg)s", path=email_path, error_msg=e)
            )
        email_template = [i.strip() for i in email_template.split("\n", 1) if i]
        if not len(email_template) > 1 or not all(email_template):
            raise AdminCommandError(_("Email template %(path)s was invalid.", path=email_path))

        subject, body = email_template
        text_template = NewTextTemplate(body)
        admins = project.get_admin_email_addresses()

        data = {"env_name": env_name}

        if is_debug:
            printout("## DEBUG MODE - NOT SENDING EMAILS ##")

        printout("project: {0}".format(env_name))
        printout("to: {0}".format(",".join(admins)))
        printout("subject: {0}".format(subject))
        printout("----------------------------")
        printout(text_template.generate(**data))
        printout("----------------------------")

        if not is_debug:
            notifier = EmailNotifier(self.env, subject=subject, data=data)
            notifier.template = text_template
            notifier.notify(admins)
            printout("Emails sent")
开发者ID:nagyistoce,项目名称:trac-multiproject,代码行数:54,代码来源:email.py

示例7: format_subj

    def format_subj(self, summary):
        template = self.config.get("notification", "ticket_subject_template")
        template = NewTextTemplate(template.encode("utf8"))

        prefix = self.config.get("notification", "smtp_subject_prefix")
        if prefix == "__default__":
            prefix = "[%s]" % self.env.project_name

        data = {"prefix": prefix, "summary": summary, "ticket": self.ticket, "env": self.env}

        return template.generate(**data).render("text", encoding=None).strip()
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:11,代码来源:notification.py

示例8: test_empty_lines1

    def test_empty_lines1(self):
        tmpl = NewTextTemplate("""Your items:

{% for item in items %}\
  * ${item}
{% end %}""")
        self.assertEqual("""Your items:

  * 0
  * 1
  * 2
""", tmpl.generate(items=range(3)).render())
开发者ID:alon,项目名称:polinax,代码行数:12,代码来源:text.py

示例9: test_empty_lines1_with_crlf

    def test_empty_lines1_with_crlf(self):
        tmpl = NewTextTemplate('Your items:\r\n'
'\r\n'
'{% for item in items %}\\\r\n'
'  * ${item}\r\n'
'{% end %}')

        self.assertEqual('Your items:\r\n'
'\r\n'
'  * 0\r\n'
'  * 1\r\n'
'  * 2\r\n', tmpl.generate(items=range(3)).render(encoding=None))
开发者ID:NixePix,项目名称:genshi,代码行数:12,代码来源:text.py

示例10: format_subj

 def format_subj(self, tickets_descr):
     template = self.config.get('notification','batch_subject_template')
     template = NewTextTemplate(template.encode('utf8'))
                                             
     prefix = self.config.get('notification', 'smtp_subject_prefix')
     if prefix == '__default__': 
         prefix = '[%s]' % self.env.project_name
     
     data = {
         'prefix': prefix,
         'tickets_descr': tickets_descr,
         'env': self.env,
     }
     
     return template.generate(**data).render('text', encoding=None).strip()
开发者ID:dinhkhanh,项目名称:trac,代码行数:15,代码来源:notification.py

示例11: format_subject

    def format_subject(self, action):
        template = self.config.get('wiki-notification', 'subject_template')
        template = NewTextTemplate(template.encode('utf8'))

        prefix = self.config.get('notification', 'smtp_subject_prefix')
        if prefix == '__default__':
            prefix = '[%s]' % self.config.get('project', 'name')

        data = {
            'pagename': self.old_name or self.page.name,
            'prefix': prefix,
            'action': action,
            'env': self.env,
        }
        return template.generate(**data).render('text', encoding=None).strip()
开发者ID:trac-hacks,项目名称:trac-wikinotification,代码行数:15,代码来源:notification.py

示例12: build_clone_form

    def build_clone_form(self, req, ticket, data):
        fields = {}
        for derivation in self.derived_fields:
            template, new_field = derivation.split('->')
            if new_field in self.excluded_fields:
                continue
            template = NewTextTemplate(template.replace("\\n", "\n").encode('utf8'))
            fields[new_field] = template.generate(ticket=ticket).render('text', encoding=None).strip()

        for f in data.get('fields', []):
            name = f['name']
            if name in fields:
                continue
            if name not in self.excluded_fields:
                fields[name] = ticket[name]
        return fields
开发者ID:boldprogressives,项目名称:trac-NewTicketLikeThisPlugin,代码行数:16,代码来源:policies.py

示例13: format_subj

    def format_subj(self, summary, newticket=True):
        template = self.config.get('notification', 'ticket_subject_template')
        template = NewTextTemplate(template.encode('utf8'))

        prefix = self.config.get('notification', 'smtp_subject_prefix')
        if prefix == '__default__':
            prefix = '[%s]' % self.env.project_name

        data = {
            'prefix': prefix,
            'summary': summary,
            'ticket': self.ticket,
            'env': self.env,
        }

        subj = template.generate(**data).render('text', encoding=None).strip()
        if not newticket:
            subj = "Re: " + subj
        return subj
开发者ID:pkdevbox,项目名称:trac,代码行数:19,代码来源:notification.py

示例14: test_empty_lines2

    def test_empty_lines2(self):
        tmpl = NewTextTemplate(
            """Your items:

{% for item in items %}\
  * ${item}

{% end %}"""
        )
        self.assertEqual(
            """Your items:

  * 0

  * 1

  * 2

""",
            tmpl.generate(items=list(range(3))).render(encoding=None),
        )
开发者ID:endorno,项目名称:Sublime-Text-2,代码行数:21,代码来源:text.py

示例15: test_unicode_input

 def test_unicode_input(self):
     text = u'$foo\xf6$bar'
     tmpl = NewTextTemplate(text)
     self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y')))
开发者ID:alon,项目名称:polinax,代码行数:4,代码来源:text.py


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