本文整理汇总了Python中Mailman.i18n.set_language函数的典型用法代码示例。如果您正苦于以下问题:Python set_language函数的具体用法?Python set_language怎么用?Python set_language使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_language函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendProbe
def sendProbe(self, member, msg):
listname = self.real_name
# Put together the substitution dictionary.
d = {
"listname": listname,
"address": member,
"optionsurl": self.GetOptionsURL(member, absolute=True),
"owneraddr": self.GetOwnerEmail(),
}
text = Utils.maketext("probe.txt", d, lang=self.getMemberLanguage(member), mlist=self)
# Calculate the VERP'd sender address for bounce processing of the
# probe message.
token = self.pend_new(Pending.PROBE_BOUNCE, member, msg)
probedict = {"bounces": self.internal_name() + "-bounces", "token": token}
probeaddr = "%[email protected]%s" % ((mm_cfg.VERP_PROBE_FORMAT % probedict), self.host_name)
# Calculate the Subject header, in the member's preferred language
ulang = self.getMemberLanguage(member)
otrans = i18n.get_translation()
i18n.set_language(ulang)
try:
subject = _("%(listname)s mailing list probe message")
finally:
i18n.set_translation(otrans)
outer = Message.UserNotification(member, probeaddr, subject, lang=ulang)
outer.set_type("multipart/mixed")
text = MIMEText(text, _charset=Utils.GetCharSet(ulang))
outer.attach(text)
outer.attach(MIMEMessage(msg))
# Turn off further VERP'ing in the final delivery step. We set
# probe_token for the OutgoingRunner to more easily handling local
# rejects of probe messages.
outer.send(self, envsender=probeaddr, verp=False, probe_token=token)
示例2: __refuse
def __refuse(self, request, recip, comment, origmsg=None, lang=None):
# As this message is going to the requestor, try to set the language
# to his/her language choice, if they are a member. Otherwise use the
# list's preferred language.
realname = self.real_name
if lang is None:
lang = self.getMemberLanguage(recip)
text = Utils.maketext(
'refuse.txt',
{'listname' : realname,
'request' : request,
'reason' : comment,
'adminaddr': self.GetOwnerEmail(),
}, lang=lang, mlist=self)
otrans = i18n.get_translation()
i18n.set_language(lang)
try:
# add in original message, but not wrap/filled
if origmsg:
text = NL.join(
[text,
'---------- ' + _('Original Message') + ' ----------',
str(origmsg)
])
subject = _('Request to mailing list %(realname)s rejected')
finally:
i18n.set_translation(otrans)
msg = Message.UserNotification(recip, self.GetOwnerEmail(),
subject, text, lang)
msg.send(self)
示例3: html_foot
def html_foot(self):
# avoid i18n side-effects
mlist = self.maillist
otrans = i18n.get_translation()
i18n.set_language(mlist.preferred_language)
# Convenience
def quotetime(s):
return html_quote(i18n.ctime(s), self.lang)
try:
d = {"lastdate": quotetime(self.lastdate),
"archivedate": quotetime(self.archivedate),
"listinfo": mlist.GetScriptURL('listinfo', absolute=1),
"version": self.version,
"listname": html_quote(mlist.real_name, self.lang),
}
i = {"thread": _("thread"),
"subject": _("subject"),
"author": _("author"),
"date": _("date")
}
finally:
i18n.set_translation(otrans)
for t in i.keys():
cap = t[0].upper() + t[1:]
if self.type == cap:
d["%s_ref" % (t)] = ""
else:
d["%s_ref" % (t)] = ('<a href="%s.html#start">[ %s ]</a>'
% (t, i[t]))
return quick_maketext(
'archidxfoot.html', d,
mlist=mlist)
示例4: unsubscription_confirm
def unsubscription_confirm(mlist, doc, cookie):
# See the comment in admin.py about the need for the signal
# handler.
def sigterm_handler(signum, frame, mlist=mlist):
mlist.Unlock()
sys.exit(0)
mlist.Lock()
try:
try:
# Do this in two steps so we can get the preferred language for
# the user who is unsubscribing.
op, addr = mlist.pend_confirm(cookie, expunge=False)
lang = mlist.getMemberLanguage(addr)
i18n.set_language(lang)
doc.set_language(lang)
op, addr = mlist.ProcessConfirmation(cookie)
except Errors.NotAMemberError:
bad_confirmation(doc, _('''Invalid confirmation string. It is
possible that you are attempting to confirm a request for an
address that has already been unsubscribed.'''))
else:
# The response
listname = mlist.real_name
title = _('Unsubscription request confirmed')
listinfourl = mlist.GetScriptURL('listinfo', absolute=1)
doc.SetTitle(title)
doc.AddItem(Header(3, Bold(FontAttr(title, size='+2'))))
doc.AddItem(_("""\
You have successfully unsubscribed from the %(listname)s mailing
list. You can now <a href="%(listinfourl)s">visit the list's main
information page</a>."""))
mlist.Save()
finally:
mlist.Unlock()
示例5: decode_headers
def decode_headers(self):
"""MIME-decode headers.
If the email, subject, or author attributes contain non-ASCII
characters using the encoded-word syntax of RFC 2047, decoded versions
of those attributes are placed in the self.decoded (a dictionary).
If the list's charset differs from the header charset, an attempt is
made to decode the headers as Unicode. If that fails, they are left
undecoded.
"""
author = self.decode_charset(self.author)
subject = self.decode_charset(self.subject)
if author:
self.decoded['author'] = author
email = self.decode_charset(self.email)
if email:
self.decoded['email'] = email
if subject:
if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
otrans = i18n.get_translation()
try:
i18n.set_language(self._lang)
atmark = unicode(_(' at '), Utils.GetCharSet(self._lang))
subject = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
'\g<1>' + atmark + '\g<2>', subject)
finally:
i18n.set_translation(otrans)
self.decoded['subject'] = subject
self.decoded['stripped'] = self.strip_subject(subject or self.subject)
示例6: _setValue
def _setValue(self, mlist, property, val, doc):
# If we're changing the list's preferred language, change the I18N
# context as well
if property == 'preferred_language':
i18n.set_language(val)
doc.set_language(val)
GUIBase._setValue(self, mlist, property, val, doc)
示例7: SendUnsubscribeAck
def SendUnsubscribeAck(self, addr, lang):
realname = self.real_name
i18n.set_language(lang)
msg = Message.UserNotification(
self.GetMemberAdminEmail(addr), self.GetBouncesEmail(),
_('You have been unsubscribed from the %(realname)s mailing list'),
Utils.wrap(self.goodbye_msg), lang)
msg.send(self, verp=mm_cfg.VERP_PERSONALIZED_DELIVERIES)
示例8: subscription_cancel
def subscription_cancel(mlist, doc, cookie):
mlist.Lock()
try:
# Discard this cookie
userdesc = mlist.pend_confirm(cookie)[1]
finally:
mlist.Unlock()
lang = userdesc.language
i18n.set_language(lang)
doc.set_language(lang)
doc.AddItem(_('You have canceled your subscription request.'))
示例9: main
def main():
cgidata = cgi.FieldStorage()
language = cgidata.getvalue('language')
parts = Utils.GetPathPieces()
i18n.set_language(language)
openidreg_overview(language)
if (cgidata.has_key("action") and cgidata.has_key("listname") and cgidata.has_key("reg-pw") and cgidata.has_key("reg-email")):
if (cgidata["action"].value == "display"):
result = test(cgidata["listname"].value, cgidata["reg-pw"].value, cgidata["reg-email"].value)
display_page(result)
else:
print "<B> Fields are blank, please enter correct Username , Password and choose your list </B>"
FormatOpenIDLogin()
示例10: SendSubscribeAck
def SendSubscribeAck(self, name, password, digest, text=""):
pluser = self.getMemberLanguage(name)
# Need to set this here to get the proper l10n of the Subject:
i18n.set_language(pluser)
if self.welcome_msg:
welcome = Utils.wrap(self.welcome_msg) + "\n"
else:
welcome = ""
if self.umbrella_list:
addr = self.GetMemberAdminEmail(name)
umbrella = Utils.wrap(
_(
"""\
Note: Since this is a list of mailing lists, administrative
notices like the password reminder will be sent to
your membership administrative address, %(addr)s."""
)
)
else:
umbrella = ""
# get the text from the template
text += Utils.maketext(
"subscribeack.txt",
{
"real_name": self.real_name,
"host_name": self.host_name,
"welcome": welcome,
"umbrella": umbrella,
"emailaddr": self.GetListEmail(),
"listinfo_url": self.GetScriptURL("listinfo", absolute=True),
"optionsurl": self.GetOptionsURL(name, absolute=True),
"password": password,
"user": self.getMemberCPAddress(name),
},
lang=pluser,
mlist=self,
)
if digest:
digmode = _(" (Digest mode)")
else:
digmode = ""
realname = self.real_name
msg = Message.UserNotification(
self.GetMemberAdminEmail(name),
self.GetRequestEmail(),
_('Welcome to the "%(realname)s" mailing list%(digmode)s'),
text,
pluser,
)
msg["X-No-Archive"] = "yes"
msg.send(self, verp=mm_cfg.VERP_PERSONALIZED_DELIVERIES)
示例11: as_html
def as_html(self):
"""Different attributes that can be used when generating a html file from a template for the archives."""
d = self.__dict__.copy()
# avoid i18n side-effects
otrans = i18n.get_translation()
i18n.set_language(self._lang)
try:
d["prev"], d["prev_wsubj"] = self._get_prev()
d["next"], d["next_wsubj"] = self._get_next()
d["email_html"] = self.quote(self.email)
d["title"] = self.quote(self.subject)
d["subject_html"] = self.quote(self.subject)
# TK: These two _url variables are used to compose a response
# from the archive web page. So, ...
# Possibly remove since not used??
d["subject_url"] = url_quote('Re: ' + self.subject)
d["in_reply_to_url"] = url_quote(self._message_id)
if mm_cfg.ARCHIVER_OBSCURES_EMAILADDRS:
# Point the mailto url back to the list
author = re.sub('@', _(' at '), self.author)
emailurl = self._mlist.GetListEmail()
else:
author = self.author
emailurl = self.email
d["author_html"] = self.quote(author)
d["email_url"] = url_quote(emailurl)
d["datestr_html"] = self.quote(i18n.ctime(int(self.date)))
d["body"] = self._get_body()
d['listurl'] = self._mlist.GetScriptURL('listinfo', absolute=1)
d['listname'] = self._mlist.real_name
d['encoding'] = ''
try:
# This should work after a couple of emails has been send and the thread
# address has been set, but to not get an error in the beginning the error
# is caught and an already existing address is provided. Is for dlists.
d['thread_addr'] = self.thread_addr
d['thread_addr_at'] = re.sub('@', _(' at '), self.thread_addr)
except:
d['thread_addr'] = d["email_url"]
d['thread_addr_at'] = d["email_url"]
finally:
i18n.set_translation(otrans)
charset = Utils.GetCharSet(self._lang)
d["encoding"] = html_charset % charset
self._add_decoded(d)
return quick_maketext(
'article.html', d,
lang=self._lang, mlist=self._mlist)
示例12: addrchange_confirm
def addrchange_confirm(mlist, doc, cookie):
# See the comment in admin.py about the need for the signal
# handler.
def sigterm_handler(signum, frame, mlist=mlist):
mlist.Unlock()
sys.exit(0)
mlist.Lock()
try:
try:
# Do this in two steps so we can get the preferred language for
# the user who is unsubscribing.
op, oldaddr, newaddr, globally = mlist.pend_confirm(
cookie, expunge=False)
lang = mlist.getMemberLanguage(oldaddr)
i18n.set_language(lang)
doc.set_language(lang)
op, oldaddr, newaddr = mlist.ProcessConfirmation(cookie)
except Errors.NotAMemberError:
bad_confirmation(doc, _('''Invalid confirmation string. It is
possible that you are attempting to confirm a request for an
address that has already been unsubscribed.'''))
except Errors.MembershipIsBanned:
owneraddr = mlist.GetOwnerEmail()
realname = mlist.real_name
doc.addError(_("""%(newaddr)s is banned from subscribing to the
%(realname)s list. If you think this restriction is erroneous,
please contact the list owners at %(owneraddr)s."""))
except Errors.MMAlreadyAMember:
realname = mlist.real_name
bad_confirmation(doc, _("""%(newaddr)s is already a member of
the %(realname)s list. It is possible that you are attempting
to confirm a request for an address that has already been
subscribed."""))
else:
# The response
listname = mlist.real_name
title = _('Change of address request confirmed')
optionsurl = mlist.GetOptionsURL(newaddr, absolute=1)
doc.SetTitle(title)
doc.AddItem(Header(3, Bold(FontAttr(title, size='+2'))))
doc.AddItem(_("""\
You have successfully changed your address on the %(listname)s
mailing list from <b>%(oldaddr)s</b> to <b>%(newaddr)s</b>. You
can now <a href="%(optionsurl)s">proceed to your membership
login page</a>."""))
mlist.Save()
finally:
mlist.Unlock()
示例13: addrchange_prompt
def addrchange_prompt(mlist, doc, cookie, oldaddr, newaddr, globally):
title = _('Confirm change of address request')
doc.SetTitle(title)
lang = mlist.getMemberLanguage(oldaddr)
i18n.set_language(lang)
doc.set_language(lang)
form = Form(mlist.GetScriptURL('confirm', 1))
table = Table(border=0, width='100%')
table.AddRow([Center(Bold(FontAttr(title, size='+1')))])
table.AddCellInfo(table.GetCurrentRowIndex(), 0,
colspan=2, bgcolor=mm_cfg.WEB_HEADER_COLOR)
listname = mlist.real_name
fullname = mlist.getMemberName(oldaddr)
if fullname is None:
fullname = _('<em>Not available</em>')
else:
fullname = Utils.websafe(Utils.uncanonstr(fullname, lang))
if globally:
globallys = _('globally')
else:
globallys = ''
table.AddRow([_("""Your confirmation is required in order to complete the
change of address request for the mailing list <em>%(listname)s</em>. You
are currently subscribed with
<ul><li><b>Real name:</b> %(fullname)s
<li><b>Old email address:</b> %(oldaddr)s
</ul>
and you have requested to %(globallys)s change your email address to
<ul><li><b>New email address:</b> %(newaddr)s
</ul>
Hit the <em>Change address</em> button below to complete the confirmation
process.
<p>Or hit <em>Cancel and discard</em> to cancel this change of address
request.""") + '<p><hr>'])
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2)
table.AddRow([Hidden('cookie', cookie)])
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2)
table.AddRow([SubmitButton('submit', _('Change address')),
SubmitButton('cancel', _('Cancel and discard'))])
form.AddItem(table)
doc.AddItem(form)
示例14: SendHostileSubscriptionNotice
def SendHostileSubscriptionNotice(self, listname, address):
# Some one was invited to one list but tried to confirm to a different
# list. We inform both list owners of the bogosity, but be careful
# not to reveal too much information.
selfname = self.internal_name()
syslog("mischief", "%s was invited to %s but confirmed to %s", address, listname, selfname)
# First send a notice to the attacked list
msg = Message.OwnerNotification(
self,
_("Hostile subscription attempt detected"),
Utils.wrap(
_(
"""%(address)s was invited to a different mailing
list, but in a deliberate malicious attempt they tried to confirm the
invitation to your list. We just thought you'd like to know. No further
action by you is required."""
)
),
)
msg.send(self)
# Now send a notice to the invitee list
try:
# Avoid import loops
from Mailman.MailList import MailList
mlist = MailList(listname, lock=False)
except Errors.MMListError:
# Oh well
return
otrans = i18n.get_translation()
i18n.set_language(mlist.preferred_language)
try:
msg = Message.OwnerNotification(
mlist,
_("Hostile subscription attempt detected"),
Utils.wrap(
_(
"""You invited %(address)s to your list, but in a
deliberate malicious attempt, they tried to confirm the invitation to a
different list. We just thought you'd like to know. No further action by you
is required."""
)
),
)
msg.send(mlist)
finally:
i18n.set_translation(otrans)
示例15: _onefile
def _onefile(self, msg, msgdata):
# Do some common sanity checking on the message metadata. It's got to
# be destined for a particular mailing list. This switchboard is used
# to shunt off badly formatted messages. We don't want to just trash
# them because they may be fixable with human intervention. Just get
# them out of our site though.
#
# Find out which mailing list this message is destined for.
listname = msgdata.get('listname')
if not listname:
listname = mm_cfg.MAILMAN_SITE_LIST
mlist = self._open_list(listname)
if not mlist:
syslog('error',
'Dequeuing message destined for missing list: %s',
listname)
self._shunt.enqueue(msg, msgdata)
return
# Now process this message, keeping track of any subprocesses that may
# have been spawned. We'll reap those later.
#
# We also want to set up the language context for this message. The
# context will be the preferred language for the user if a member of
# the list, or the list's preferred language. However, we must take
# special care to reset the defaults, otherwise subsequent messages
# may be translated incorrectly. BAW: I'm not sure I like this
# approach, but I can't think of anything better right now.
otranslation = i18n.get_translation()
sender = msg.get_sender()
if mlist:
lang = mlist.getMemberLanguage(sender)
else:
lang = mm_cfg.DEFAULT_SERVER_LANGUAGE
i18n.set_language(lang)
msgdata['lang'] = lang
try:
keepqueued = self._dispose(mlist, msg, msgdata)
finally:
i18n.set_translation(otranslation)
# Keep tabs on any child processes that got spawned.
kids = msgdata.get('_kids')
if kids:
self._kids.update(kids)
if keepqueued:
self._switchboard.enqueue(msg, msgdata)