本文整理汇总了Python中epsilon.extime.Time.fromRFC2822方法的典型用法代码示例。如果您正苦于以下问题:Python Time.fromRFC2822方法的具体用法?Python Time.fromRFC2822怎么用?Python Time.fromRFC2822使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类epsilon.extime.Time
的用法示例。
在下文中一共展示了Time.fromRFC2822方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: guessSentTime
# 需要导入模块: from epsilon.extime import Time [as 别名]
# 或者: from epsilon.extime.Time import fromRFC2822 [as 别名]
def guessSentTime(self, default=None):
"""
Try to determine the time this message claims to have been sent by
analyzing various headers.
@return: a L{Time} instance, or C{None}, if we don't have a guess.
"""
try:
sentHeader = self.getHeader(u'date')
except equotient.NoSuchHeader:
sentHeader = None
else:
try:
return Time.fromRFC2822(sentHeader)
except ValueError:
pass
for received in list(self.getHeaders(u'received'))[::-1]:
lines = received.value.splitlines()
if lines:
lastLine = lines[-1]
parts = lastLine.split('; ')
if parts:
date = parts[-1]
try:
when = rfc822.parsedate(date)
if when is None:
continue
except ValueError:
pass
else:
return Time.fromStructTime(when)
return default
示例2: test_attributes
# 需要导入模块: from epsilon.extime import Time [as 别名]
# 或者: from epsilon.extime.Time import fromRFC2822 [as 别名]
def test_attributes(self):
"""
Verify all the attributes directly on the Message class are preserved
by the upgrade function.
"""
for i, msg in enumerate(self.messageList):
# The code at the revision which this stub requires randomly
# mangles the sentWhen of the 3rd and 4th message (because they're
# drafts), so we can't reasonably test them, except to make sure
# they're not none.
if i == 3 or i == 4:
self.assertNotEqual(msg.sentWhen, None)
else:
self.assertEqual(
msg.sentWhen,
Time.fromRFC2822("Thu, 26 Apr 2001 22:01:%d GMT" % (i,)))
# Received when is set to the time the stub is generated! So we
# can only test for non-Noneness.
self.assertNotEqual(msg.receivedWhen, None)
self.assertEqual(msg.sender, u"[email protected]")
self.assertEqual(msg.senderDisplay, u"[email protected]")
self.assertEqual(msg.recipient, u"[email protected]")
self.assertEqual(msg.subject, u"message number %d" % (i,))
self.assertEqual(msg.attachments, i * 2)
self.assertEqual(msg.read, i == 2)
self.assertEqual(msg.everDeferred, i == 1 or i == 2)
if i == 0 or i == 1 or i == 2 or i == 5:
_spam = False
elif i == 3 or i == 4:
_spam = None
elif i == 6 or i == 7:
_spam = True
self.assertEqual(msg._spam, _spam)
self.assertEqual(msg.shouldBeClassified, not (i == 3 or i == 4 or i == 7))
self.assertEqual(msg.impl.getHeader(u"subject"), msg.subject)
if i == 7:
frozenWith = SPAM_STATUS
elif i == 5 or i == 6:
frozenWith = TRASH_STATUS
else:
frozenWith = None
self.assertEqual(msg._frozenWith, frozenWith)