本文整理汇总了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()))
示例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))
示例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))
示例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))
示例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()))
示例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")
示例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()
示例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())
示例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))
示例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()
示例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()
示例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
示例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
示例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),
)
示例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')))