当前位置: 首页>>代码示例>>Python>>正文


Python Time.fromRFC2822方法代码示例

本文整理汇总了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
开发者ID:pombredanne,项目名称:quotient,代码行数:37,代码来源:mimestorage.py

示例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)
开发者ID:pombredanne,项目名称:quotient,代码行数:52,代码来源:test_message4to5.py


注:本文中的epsilon.extime.Time.fromRFC2822方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。