本文整理汇总了Python中config.LOGGER.warn方法的典型用法代码示例。如果您正苦于以下问题:Python LOGGER.warn方法的具体用法?Python LOGGER.warn怎么用?Python LOGGER.warn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.LOGGER
的用法示例。
在下文中一共展示了LOGGER.warn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from config import LOGGER [as 别名]
# 或者: from config.LOGGER import warn [as 别名]
def send(portal, message, subject, recipients=[]):
"""Send an email.
this is taken from Products.eXtremeManagement
"""
# Weed out any empty strings.
recipients = [r for r in recipients if r]
if not recipients:
LOGGER.warn("No recipients to send the mail to, not sending.")
return
charset = portal.getProperty('email_charset', 'ISO-8859-1')
# Header class is smart enough to try US-ASCII, then the charset we
# provide, then fall back to UTF-8.
header_charset = charset
# We must choose the body charset manually
for body_charset in 'US-ASCII', charset, 'UTF-8':
try:
message = message.encode(body_charset)
except UnicodeError:
pass
else:
break
# Get the 'From' address.
registry = getUtility(IRegistry)
sender_name = registry.get('plone.email_from_name')
sender_addr = registry.get('plone.email_from_address')
# We must always pass Unicode strings to Header, otherwise it will
# use RFC 2047 encoding even on plain ASCII strings.
sender_name = str(Header(safe_unicode(sender_name), header_charset))
# Make sure email addresses do not contain non-ASCII characters
sender_addr = sender_addr.encode('ascii')
email_from = formataddr((sender_name, sender_addr))
formatted_recipients = []
for recipient in recipients:
# Split real name (which is optional) and email address parts
recipient_name, recipient_addr = parseaddr(recipient)
recipient_name = str(Header(safe_unicode(recipient_name),
header_charset))
recipient_addr = recipient_addr.encode('ascii')
formatted = formataddr((recipient_name, recipient_addr))
formatted_recipients.append(formatted)
email_to = ', '.join(formatted_recipients)
# Make the subject a nice header
subject = Header(safe_unicode(subject), header_charset)
# Create the message ('plain' stands for Content-Type: text/plain)
# plone4 should use 'text/plain' according to the docs, but this should work for us
# http://plone.org/documentation/manual/upgrade-guide/version/upgrading-plone-3-x-to-4.0/updating-add-on-products-for-plone-4.0/mailhost.securesend-is-now-deprecated-use-send-instead/
msg = MIMEText(message, 'html', body_charset)
msg['From'] = email_from
msg['To'] = email_to
msg['Subject'] = subject
msg = msg.as_string()
# Finally send it out.
mailhost = getToolByName(portal, 'MailHost')
try:
LOGGER.info("Begin sending email to %r " % formatted_recipients)
LOGGER.info("Subject: %s " % subject)
mailhost.send(msg)
except gaierror, exc:
LOGGER.error("Failed sending email to %r" % formatted_recipients)
LOGGER.error("Reason: %s: %r" % (exc.__class__.__name__, str(exc)))