本文整理汇总了Python中email.Utils.formatdate方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.formatdate方法的具体用法?Python Utils.formatdate怎么用?Python Utils.formatdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.Utils
的用法示例。
在下文中一共展示了Utils.formatdate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def send(self, data):
"""
Publish some data
@type data: string
@param data: Data to publish
"""
# Build Message Body
msg = MIMEMultipart()
msg['From'] = self.msgFrom
msg['To'] = self.msgTo
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = self.msgSubject
msg.attach(MIMEText(self.msgText))
# Attach file
part = MIMEBase('application', 'pdf')
part.set_payload(data)
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % self.fileName)
msg.attach(part)
# Send email
smtp = smtplib.SMTP(self.server)
smtp.sendmail(self.msgFrom, self.msgTo, msg.as_string())
smtp.close()
示例2: message
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def message(self):
encoding = self.encoding or settings.DEFAULT_CHARSET
msg = SafeMIMEText(smart_str(self.body, encoding),
self.content_subtype, encoding)
msg = self._create_message(msg)
msg['Subject'] = self.subject
msg['From'] = self.extra_headers.get('From', self.from_email)
msg['To'] = ', '.join(self.to)
# Email header names are case-insensitive (RFC 2045), so we have to
# accommodate that when doing comparisons.
header_names = [key.lower() for key in self.extra_headers]
if 'date' not in header_names:
msg['Date'] = formatdate()
if 'message-id' not in header_names:
msg['Message-ID'] = make_msgid()
for name, value in self.extra_headers.items():
if name.lower() == 'from': # From is already handled
continue
msg[name] = value
return msg
示例3: __next__
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def __next__(self):
formatted = formatdate(self.time, True)
self.time += 1
return formatted
示例4: _get_msg_time
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def _get_msg_time():
timestamp = time.mktime((2010, 12, 12, 1, 1, 1, 1, 1, 1))
return formatdate(timestamp)
示例5: test_formatdate
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def test_formatdate(self):
now = time.time()
self.assertEqual(Utils.parsedate(Utils.formatdate(now))[:6],
time.gmtime(now)[:6])
示例6: test_formatdate_localtime
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def test_formatdate_localtime(self):
now = time.time()
self.assertEqual(
Utils.parsedate(Utils.formatdate(now, localtime=True))[:6],
time.localtime(now)[:6])
示例7: test_formatdate_usegmt
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def test_formatdate_usegmt(self):
now = time.time()
self.assertEqual(
Utils.formatdate(now, localtime=False),
time.strftime('%a, %d %b %Y %H:%M:%S -0000', time.gmtime(now)))
self.assertEqual(
Utils.formatdate(now, localtime=False, usegmt=True),
time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(now)))
示例8: mail_headers
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def mail_headers(self, group, params):
from email import Utils
subject = self.make_subject(group, params)
try:
subject.encode('ascii')
except UnicodeError:
from email.Header import Header
subject = Header(subject, 'utf-8').encode()
hdrs = 'From: %s\n' \
'To: %s\n' \
'Subject: %s\n' \
'Date: %s\n' \
'Message-ID: %s\n' \
'MIME-Version: 1.0\n' \
'Content-Type: text/plain; charset=UTF-8\n' \
'Content-Transfer-Encoding: 8bit\n' \
'X-Svn-Commit-Project: %s\n' \
'X-Svn-Commit-Author: %s\n' \
'X-Svn-Commit-Revision: %d\n' \
'X-Svn-Commit-Repository: %s\n' \
% (self.from_addr, ', '.join(self.to_addrs), subject,
Utils.formatdate(), Utils.make_msgid(), group,
self.repos.author or 'no_author', self.repos.rev,
os.path.basename(self.repos.repos_dir))
if self.reply_to:
hdrs = '%sReply-To: %s\n' % (hdrs, self.reply_to)
return hdrs + '\n'
示例9: _mail_recipient
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def _mail_recipient(recipient_name, recipient_email,
sender_name, sender_url, subject,
body, headers={}):
mail_from = config.get('smtp.mail_from')
msg = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
for k, v in headers.items():
msg[k] = v
subject = Header(subject.encode('utf-8'), 'utf-8')
msg['Subject'] = subject
msg['From'] = _("%s <%s>") % (sender_name, mail_from)
recipient = u"%s <%s>" % (recipient_name, recipient_email)
msg['To'] = Header(recipient, 'utf-8')
msg['Date'] = Utils.formatdate(time())
msg['X-Mailer'] = "CKAN %s" % ckan.__version__
# Send the email using Python's smtplib.
smtp_connection = smtplib.SMTP()
if 'smtp.test_server' in config:
# If 'smtp.test_server' is configured we assume we're running tests,
# and don't use the smtp.server, starttls, user, password etc. options.
smtp_server = config['smtp.test_server']
smtp_starttls = False
smtp_user = None
smtp_password = None
else:
smtp_server = config.get('smtp.server', 'localhost')
smtp_starttls = paste.deploy.converters.asbool(
config.get('smtp.starttls'))
smtp_user = config.get('smtp.user')
smtp_password = config.get('smtp.password')
try:
smtp_connection.connect(smtp_server)
except socket.error, e:
log.exception(e)
raise MailerException('SMTP server could not be connected to: "%s" %s'
% (smtp_server, e))
示例10: cookie_date
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def cookie_date(epoch_seconds=None):
"""
Formats the time to ensure compatibility with Netscape's cookie standard.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current time.
Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
"""
rfcdate = formatdate(epoch_seconds)
return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25])
示例11: http_date
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def http_date(epoch_seconds=None):
"""
Formats the time to match the RFC1123 date format as specified by HTTP
RFC2616 section 3.3.1.
Accepts a floating point number expressed in seconds since the epoch, in
UTC - such as that outputted by time.time(). If set to None, defaults to
the current time.
Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
"""
rfcdate = formatdate(epoch_seconds)
return '%s GMT' % rfcdate[:25]
# Base 36 functions: useful for generating compact URLs
示例12: open_local_file
# 需要导入模块: from email import Utils [as 别名]
# 或者: from email.Utils import formatdate [as 别名]
def open_local_file(self, req):
try:
import email.utils as emailutils
except ImportError:
# python 2.4
import email.Utils as emailutils
import mimetypes
host = req.get_host()
file = req.get_selector()
localfile = url2pathname(file)
try:
stats = os.stat(localfile)
size = stats.st_size
modified = emailutils.formatdate(stats.st_mtime, usegmt=True)
mtype = mimetypes.guess_type(file)[0]
headers = mimetools.Message(StringIO(
'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified)))
if host:
host, port = splitport(host)
if not host or \
(not port and socket.gethostbyname(host) in self.get_names()):
return addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
except OSError, msg:
# urllib2 users shouldn't expect OSErrors coming from urlopen()
raise URLError(msg)