本文整理汇总了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)
示例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))
示例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))