當前位置: 首頁>>代碼示例>>Python>>正文


Python BufferedSubFile.push方法代碼示例

本文整理匯總了Python中email.feedparser.BufferedSubFile.push方法的典型用法代碼示例。如果您正苦於以下問題:Python BufferedSubFile.push方法的具體用法?Python BufferedSubFile.push怎麽用?Python BufferedSubFile.push使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.feedparser.BufferedSubFile的用法示例。


在下文中一共展示了BufferedSubFile.push方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_push_random

# 需要導入模塊: from email.feedparser import BufferedSubFile [as 別名]
# 或者: from email.feedparser.BufferedSubFile import push [as 別名]
def test_push_random(self):
        from email.feedparser import BufferedSubFile, NeedMoreData

        n = 10000
        chunksize = 5
        chars = 'abcd \t\r\n'

        s = ''.join(choice(chars) for i in range(n)) + '\n'
        target = s.splitlines(True)

        bsf = BufferedSubFile()
        lines = []
        for i in range(0, len(s), chunksize):
            chunk = s[i:i+chunksize]
            bsf.push(chunk)
            lines.extend(iter(bsf.readline, NeedMoreData))
        self.assertEqual(lines, target) 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:19,代碼來源:test_email.py

示例2: test_pushCR_LF

# 需要導入模塊: from email.feedparser import BufferedSubFile [as 別名]
# 或者: from email.feedparser.BufferedSubFile import push [as 別名]
def test_pushCR_LF(self):
        '''FeedParser BufferedSubFile.push() assumed it received complete
           line endings.  A CR ending one push() followed by a LF starting
           the next push() added an empty line.
        '''
        imt = [
            ("a\r \n",  2),
            ("b",       0),
            ("c\n",     1),
            ("",        0),
            ("d\r\n",   1),
            ("e\r",     0),
            ("\nf",     1),
            ("\r\n",    1),
          ]
        from email.feedparser import BufferedSubFile, NeedMoreData
        bsf = BufferedSubFile()
        om = []
        nt = 0
        for il, n in imt:
            bsf.push(il)
            nt += n
            n1 = 0
            for ol in iter(bsf.readline, NeedMoreData):
                om.append(ol)
                n1 += 1
            self.assertEqual(n, n1)
        self.assertEqual(len(om), nt)
        self.assertEqual(''.join([il for il, n in imt]), ''.join(om)) 
開發者ID:adde88,項目名稱:hostapd-mana,代碼行數:31,代碼來源:test_email.py

示例3: test_pushCR_LF

# 需要導入模塊: from email.feedparser import BufferedSubFile [as 別名]
# 或者: from email.feedparser.BufferedSubFile import push [as 別名]
def test_pushCR_LF(self):
        '''FeedParser BufferedSubFile.push() assumed it received complete
           line endings.  A CR ending one push() followed by a LF starting
           the next push() added an empty line.
        '''
        imt = [
            ("a\r \n",  2),
            ("b",       0),
            ("c\n",     1),
            ("",        0),
            ("d\r\n",   1),
            ("e\r",     0),
            ("\nf",     1),
            ("\r\n",    1),
          ]
        from email.feedparser import BufferedSubFile, NeedMoreData
        bsf = BufferedSubFile()
        om = []
        nt = 0
        for il, n in imt:
            bsf.push(il)
            nt += n
            n1 = 0
            while True:
                ol = bsf.readline()
                if ol == NeedMoreData:
                    break
                om.append(ol)
                n1 += 1
            self.assertTrue(n == n1)
        self.assertTrue(len(om) == nt)
        self.assertTrue(''.join([il for il, n in imt]) == ''.join(om)) 
開發者ID:securesystemslab,項目名稱:zippy,代碼行數:34,代碼來源:test_email.py


注:本文中的email.feedparser.BufferedSubFile.push方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。