本文整理汇总了Python中trac.util.translation.tag_函数的典型用法代码示例。如果您正苦于以下问题:Python tag_函数的具体用法?Python tag_怎么用?Python tag_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tag_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _provider_failure
def _provider_failure(self, exc, req, ep, current_filters, all_filters):
"""Raise a TracError exception explaining the failure of a provider.
At the same time, the message will contain a link to the timeline
without the filters corresponding to the guilty event provider `ep`.
"""
self.log.error('Timeline event provider failed: %s',
exception_to_unicode(exc, traceback=True))
ep_kinds = dict((f[0], f[1])
for f in ep.get_timeline_filters(req) or [])
ep_filters = set(ep_kinds.keys())
current_filters = set(current_filters)
other_filters = set(current_filters) - ep_filters
if not other_filters:
other_filters = set(all_filters) - ep_filters
args = [(a, req.args.get(a)) for a in ('from', 'format', 'max',
'daysback')]
href = req.href.timeline(args + [(f, 'on') for f in other_filters])
# TRANSLATOR: ...want to see the 'other kinds of events' from... (link)
other_events = tag.a(_('other kinds of events'), href=href)
raise TracError(tag(
tag.p(tag_("Event provider %(name)s failed for filters "
"%(kinds)s: ",
name=tag.tt(ep.__class__.__name__),
kinds=', '.join('"%s"' % ep_kinds[f] for f in
current_filters & ep_filters)),
tag.b(exception_to_unicode(exc)), class_='message'),
tag.p(tag_("You may want to see the %(other_events)s from the "
"Timeline or notify your Trac administrator about the "
"error (detailed information was written to the log).",
other_events=other_events))))
示例2: _render_property
def _render_property(self, name, mode, context, props):
repos, revs = props[name]
def link(rev):
chgset = repos.get_changeset(rev)
return tag.a(rev, class_="changeset",
title=shorten_line(chgset.message),
href=context.href.changeset(rev, repos.reponame))
if name == 'Parents' and len(revs) == 2: # merge
new = context.resource.id
parent_links = [
(link(rev), ' (',
tag.a('diff', title=_("Diff against this parent "
"(show the changes merged from the other parents)"),
href=context.href.changeset(new, repos.reponame,
old=rev)), ')')
for rev in revs]
return tag([(parent, ', ') for parent in parent_links[:-1]],
parent_links[-1], tag.br(),
tag.span(tag_("Note: this is a %(merge)s changeset, "
"the changes displayed below correspond "
"to the merge itself.",
merge=tag.strong('merge')),
class_='hint'), tag.br(),
# TODO: only keep chunks present in both parents
# (conflicts) or in none (extra changes)
# tag.span('No changes means the merge was clean.',
# class_='hint'), tag.br(),
tag.span(tag_("Use the %(diff)s links above to see all "
"the changes relative to each parent.",
diff=tag.tt('(diff)')),
class_='hint'))
return tag([tag(link(rev), ', ') for rev in revs[:-1]],
link(revs[-1]))
示例3: _do_repositories
def _do_repositories(self, req, category, page):
# Check that the setttings have been set.
parentpath = self.config.get('svnadmin', 'parent_path')
client = self.config.get('svnadmin', 'svn_client_location')
admin = self.config.get('svnadmin', 'svnadmin_location')
if not parentpath or not client or not admin:
add_warning(req, _('You must provide settings before continuing.'))
req.redirect(req.href.admin(category, 'config'))
data = {}
svn_provider = self.env[SvnRepositoryProvider]
db_provider = self.env[DbRepositoryProvider]
if req.method == 'POST':
# Add a repository
if svn_provider and req.args.get('add_repos'):
name = req.args.get('name')
dir = os.path.join(parentpath, name)
if name is None or name == "" or not dir:
add_warning(req, _('Missing arguments to add a repository.'))
elif self._check_dir(req, dir):
try:
svn_provider.add_repository(name)
db_provider.add_repository(name, dir, 'svn')
add_notice(req, _('The repository "%(name)s" has been '
'added.', name=name))
resync = tag.tt('trac-admin $ENV repository resync '
'"%s"' % name)
msg = tag_('You should now run %(resync)s to '
'synchronize Trac with the repository.',
resync=resync)
add_notice(req, msg)
cset_added = tag.tt('trac-admin $ENV changeset '
'added "%s" $REV' % name)
msg = tag_('You should also set up a post-commit hook '
'on the repository to call %(cset_added)s '
'for each committed changeset.',
cset_added=cset_added)
add_notice(req, msg)
req.redirect(req.href.admin(category, page))
except TracError, why:
add_warning(req, str(why))
# Remove repositories
elif svn_provider and req.args.get('remove'):
sel = req.args.getlist('sel')
if sel:
for name in sel:
svn_provider.remove_repository(name)
db_provider.remove_repository(name)
add_notice(req, _('The selected repositories have '
'been removed.'))
req.redirect(req.href.admin(category, page))
add_warning(req, _('No repositories were selected.'))
示例4: send
def send(self, from_addr, recipients, message):
# Ensure the message complies with RFC2822: use CRLF line endings
message = fix_eol(message, CRLF)
self.log.info("Sending notification through SMTP at %s:%d to %s",
self.smtp_server, self.smtp_port, recipients)
try:
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
except smtplib.socket.error as e:
raise ConfigurationError(
tag_("SMTP server connection error (%(error)s). Please "
"modify %(option1)s or %(option2)s in your "
"configuration.",
error=to_unicode(e),
option1=tag.code("[notification] smtp_server"),
option2=tag.code("[notification] smtp_port")))
# server.set_debuglevel(True)
if self.use_tls:
server.ehlo()
if 'starttls' not in server.esmtp_features:
raise TracError(_("TLS enabled but server does not support"
" TLS"))
server.starttls()
server.ehlo()
if self.smtp_user:
server.login(self.smtp_user.encode('utf-8'),
self.smtp_password.encode('utf-8'))
start = time.time()
resp = sendmail(server, from_addr, recipients, message)
t = time.time() - start
if t > 5:
self.log.warning("Slow mail submission (%.2f s), "
"check your mail setup", t)
if self.use_tls:
# avoid false failure detection when the server closes
# the SMTP connection with TLS enabled
import socket
try:
server.quit()
except socket.sslerror:
pass
else:
server.quit()
msg = email.message_from_string(message)
ticket_id = int(msg['x-trac-ticket-id'])
msgid = msg['message-id']
aws_re = r'^email-smtp\.([a-z0-9-]+)\.amazonaws\.com$'
m = re.match(aws_re, self.smtp_server)
if m:
parts = resp.split()
if len(parts) == 2 and parts[0] == 'Ok':
region = m.group(1)
msgid = '<%[email protected]%s.amazonses.com>' % (parts[1], region)
with self.env.db_transaction as db:
cursor = db.cursor()
cursor.execute("""
INSERT OR IGNORE INTO messageid (ticket,messageid)
VALUES (%s, %s)
""", (ticket_id, msgid))
示例5: _do_save
def _do_save(self, req, page):
if not page.exists:
req.perm(page.resource).require('WIKI_CREATE')
else:
req.perm(page.resource).require('WIKI_MODIFY')
if 'WIKI_ADMIN' in req.perm(page.resource):
# Modify the read-only flag if it has been changed and the user is
# WIKI_ADMIN
page.readonly = int('readonly' in req.args)
try:
page.save(get_reporter_id(req, 'author'), req.args.get('comment'),
req.remote_addr)
href = req.href.wiki(page.name, action='diff',
version=page.version)
add_notice(req, tag_("Your changes have been saved in version "
"%(version)s (%(diff)s).",
version=page.version,
diff=tag.a(_("diff"), href=href)))
req.redirect(get_resource_url(self.env, page.resource, req.href,
version=None))
except TracError:
add_warning(req, _("Page not modified, showing latest version."))
return self._render_view(req, page)
示例6: __get__
def __get__(self, instance, owner):
if instance is None:
return self
order = ListOption.__get__(self, instance, owner)
components = []
implementing_classes = []
for impl in self.xtnpt.extensions(instance):
implementing_classes.append(impl.__class__.__name__)
if self.include_missing or impl.__class__.__name__ in order:
components.append(impl)
not_found = sorted(set(order) - set(implementing_classes))
if not_found:
raise ConfigurationError(
tag_("Cannot find implementation(s) of the %(interface)s "
"interface named %(implementation)s. Please check "
"that the Component is enabled or update the option "
"%(option)s in trac.ini.",
interface=tag.tt(self.xtnpt.interface.__name__),
implementation=tag(
(', ' if idx != 0 else None, tag.tt(impl))
for idx, impl in enumerate(not_found)),
option=tag.tt("[%s] %s" % (self.section, self.name))))
def compare(x, y):
x, y = x.__class__.__name__, y.__class__.__name__
if x not in order:
return int(y in order)
if y not in order:
return -int(x in order)
return cmp(order.index(x), order.index(y))
components.sort(compare)
return components
示例7: _do_delete
def _do_delete(self, req, milestone):
req.perm(milestone.resource).require('MILESTONE_DELETE')
retarget_to = req.args.get('target') or None
# Don't translate ticket comment (comment:40:ticket:5658)
retargeted_tickets = \
milestone.move_tickets(retarget_to, req.authname,
"Ticket retargeted after milestone deleted")
milestone.delete(author=req.authname)
add_notice(req, _('The milestone "%(name)s" has been deleted.',
name=milestone.name))
if retargeted_tickets:
add_notice(req, _('The tickets associated with milestone '
'"%(name)s" have been retargeted to milestone '
'"%(retarget)s".', name=milestone.name,
retarget=retarget_to))
new_values = {'milestone': retarget_to}
comment = _("Tickets retargeted after milestone deleted")
tn = BatchTicketNotifyEmail(self.env)
try:
tn.notify(retargeted_tickets, new_values, comment, None,
req.authname)
except Exception, e:
self.log.error("Failure sending notification on ticket batch "
"change: %s", exception_to_unicode(e))
add_warning(req, tag_("The changes have been saved, but an "
"error occurred while sending "
"notifications: %(message)s",
message=to_unicode(e)))
示例8: notify
def notify(self, resid, subject, author=None):
self.subject = subject
config = self.config['notification']
if not config.getbool('smtp_enabled'):
return
from_email, from_name = '', ''
if author and config.getbool('smtp_from_author'):
from_email = self.get_smtp_address(author)
if from_email:
from_name = self.name_map.get(author, '')
if not from_name:
mo = self.longaddr_re.search(author)
if mo:
from_name = mo.group(1)
if not from_email:
from_email = config.get('smtp_from')
from_name = config.get('smtp_from_name') or self.env.project_name
self.replyto_email = config.get('smtp_replyto')
self.from_email = from_email or self.replyto_email
self.from_name = from_name
if not self.from_email and not self.replyto_email:
message = tag(
tag.p(_('Unable to send email due to identity crisis.')),
# convert explicitly to `Fragment` to avoid breaking message
# when passing `LazyProxy` object to `Fragment`
tag.p(to_fragment(tag_(
"Neither %(from_)s nor %(reply_to)s are specified in the "
"configuration.",
from_=tag.strong("[notification] smtp_from"),
reply_to=tag.strong("[notification] smtp_replyto")))))
raise TracError(message, _("SMTP Notification Error"))
Notify.notify(self, resid)
示例9: _render_source
def _render_source(self, context, stream, annotations, marks=None):
from trac.web.chrome import add_warning
annotators, labels, titles = {}, {}, {}
for annotator in self.annotators:
atype, alabel, atitle = annotator.get_annotation_type()
if atype in annotations:
labels[atype] = alabel
titles[atype] = atitle
annotators[atype] = annotator
annotations = [a for a in annotations if a in annotators]
if isinstance(stream, list):
stream = HTMLParser(StringIO(u'\n'.join(stream)))
elif isinstance(stream, unicode):
text = stream
def linesplitter():
for line in text.splitlines(True):
yield TEXT, line, (None, -1, -1)
stream = linesplitter()
annotator_datas = []
for a in annotations:
annotator = annotators[a]
try:
data = (annotator, annotator.get_annotation_data(context))
except TracError, e:
self.log.warning("Can't use annotator '%s': %s", a, e.message)
add_warning(context.req, tag.strong(
tag_("Can't use %(annotator)s annotator: %(error)s",
annotator=tag.em(a), error=tag.pre(e.message))))
data = (None, None)
annotator_datas.append(data)
示例10: _do_login
def _do_login(self, req):
"""Log the remote user in.
This function expects to be called when the remote user name
is available. The user name is inserted into the `auth_cookie`
table and a cookie identifying the user on subsequent requests
is sent back to the client.
If the Authenticator was created with `ignore_case` set to
true, then the authentication name passed from the web server
in req.remote_user will be converted to lower case before
being used. This is to avoid problems on installations
authenticating against Windows which is not case sensitive
regarding user names and domain names
"""
if not req.remote_user:
# TRANSLATOR: ... refer to the 'installation documentation'. (link)
inst_doc = tag.a(_('installation documentation'),
title=_("Configuring Authentication"),
href=req.href.wiki('TracInstall')
+ "#ConfiguringAuthentication")
raise TracError(tag_("Authentication information not available. "
"Please refer to the %(inst_doc)s.",
inst_doc=inst_doc))
remote_user = req.remote_user
if self.ignore_case:
remote_user = remote_user.lower()
if req.authname not in ('anonymous', remote_user):
raise TracError(_('Already logged in as %(user)s.',
user=req.authname))
with self.env.db_transaction as db:
# Delete cookies older than 10 days
db("DELETE FROM auth_cookie WHERE time < %s",
(int(time.time()) - 86400 * 10,))
# Insert a new cookie if we haven't already got one
cookie = None
trac_auth = req.incookie.get('trac_auth')
if trac_auth is not None:
name = self._cookie_to_name(req, trac_auth)
cookie = trac_auth.value if name == remote_user else None
if cookie is None:
cookie = hex_entropy()
db("""
INSERT INTO auth_cookie (cookie, name, ipnr, time)
VALUES (%s, %s, %s, %s)
""", (cookie, remote_user, req.remote_addr,
int(time.time())))
req.authname = remote_user
req.outcookie['trac_auth'] = cookie
req.outcookie['trac_auth']['path'] = self.auth_cookie_path \
or req.base_path or '/'
if self.env.secure_cookies:
req.outcookie['trac_auth']['secure'] = True
if sys.version_info >= (2, 6):
req.outcookie['trac_auth']['httponly'] = True
if self.auth_cookie_lifetime > 0:
req.outcookie['trac_auth']['expires'] = self.auth_cookie_lifetime
示例11: render_timeline_event
def render_timeline_event(self, context, field, event):
url, title, desc = event[3]
if field == 'url':
return url
elif field == 'title':
return tag_('%(page)s created', page=tag.em(title))
elif field == 'description':
return tag(desc)
示例12: _render_source
def _render_source(self, context, stream, annotations):
from trac.web.chrome import add_warning
annotators, labels, titles = {}, {}, {}
for annotator in self.annotators:
atype, alabel, atitle = annotator.get_annotation_type()
if atype in annotations:
labels[atype] = alabel
titles[atype] = atitle
annotators[atype] = annotator
annotations = [a for a in annotations if a in annotators]
if isinstance(stream, list):
stream = HTMLParser(StringIO(u"\n".join(stream)))
elif isinstance(stream, unicode):
text = stream
def linesplitter():
for line in text.splitlines(True):
yield TEXT, line, (None, -1, -1)
stream = linesplitter()
annotator_datas = []
for a in annotations:
annotator = annotators[a]
try:
data = (annotator, annotator.get_annotation_data(context))
except TracError as e:
self.log.warning("Can't use annotator '%s': %s", a, e)
add_warning(
context.req,
tag.strong(
tag_("Can't use %(annotator)s annotator: %(error)s", annotator=tag.em(a), error=tag.pre(e))
),
)
data = None, None
annotator_datas.append(data)
def _head_row():
return tag.tr(
[tag.th(labels[a], class_=a, title=titles[a]) for a in annotations]
+ [tag.th(u"\xa0", class_="content")]
)
def _body_rows():
for idx, line in enumerate(_group_lines(stream)):
row = tag.tr()
for annotator, data in annotator_datas:
if annotator:
annotator.annotate_row(context, row, idx + 1, line, data)
else:
row.append(tag.td())
row.append(tag.td(line))
yield row
return tag.table(class_="code")(tag.thead(_head_row()), tag.tbody(_body_rows()))
示例13: render_timeline_event
def render_timeline_event(self, context, field, event):
wiki_page, comment = event[3]
if field == 'url':
return context.href.wiki(wiki_page.id, version=wiki_page.version)
elif field == 'title':
name = tag.em(get_resource_name(self.env, wiki_page))
if wiki_page.version > 1:
return tag_('%(page)s edited', page=name)
else:
return tag_('%(page)s created', page=name)
elif field == 'description':
markup = format_to(self.env, None,
context.child(resource=wiki_page), comment)
if wiki_page.version > 1:
diff_href = context.href.wiki(
wiki_page.id, version=wiki_page.version, action='diff')
markup = tag(markup,
' (', tag.a(_('diff'), href=diff_href), ')')
return markup
示例14: render_timeline_event
def render_timeline_event(self, context, field, event):
milestone, description = event[3]
if field == 'url':
return context.href.milestone(milestone.id)
elif field == 'title':
return tag_('Milestone %(name)s completed',
name=tag.em(milestone.id))
elif field == 'description':
return format_to(self.env, None, context.child(resource=milestone),
description)
示例15: validate
def validate(self, relation):
rls = RelationsSystem(self.env)
existing_relations = rls._select_relations(resource_type=relation.type,
destination=relation.destination)
if existing_relations:
raise ValidationError(
tag_("Another resource is already related to %(destination)s "
"with %(relation)s relation.",
destination=tag.em(relation.destination),
relation=tag.b(self.render_relation_type(relation.type)))
)