本文整理汇总了Python中bz2.BZ2File.read方法的典型用法代码示例。如果您正苦于以下问题:Python BZ2File.read方法的具体用法?Python BZ2File.read怎么用?Python BZ2File.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bz2.BZ2File
的用法示例。
在下文中一共展示了BZ2File.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReadable
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testReadable(self):
bz2f = BZ2File(BytesIO(self.DATA))
try:
self.assertTrue(bz2f.readable())
bz2f.read()
self.assertTrue(bz2f.readable())
finally:
bz2f.close()
self.assertRaises(ValueError, bz2f.readable)
bz2f = BZ2File(BytesIO(), "w")
try:
self.assertFalse(bz2f.readable())
finally:
bz2f.close()
self.assertRaises(ValueError, bz2f.readable)
示例2: testWritable
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testWritable(self):
bz2f = BZ2File(BytesIO(self.DATA))
try:
self.assertFalse(bz2f.writable())
bz2f.read()
self.assertFalse(bz2f.writable())
finally:
bz2f.close()
self.assertRaises(ValueError, bz2f.writable)
bz2f = BZ2File(BytesIO(), "w")
try:
self.assertTrue(bz2f.writable())
finally:
bz2f.close()
self.assertRaises(ValueError, bz2f.writable)
示例3: testMixedIterationAndReads
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testMixedIterationAndReads(self):
self.createTempFile()
linelen = len(self.TEXT_LINES[0])
halflen = linelen // 2
with BZ2File(self.filename) as bz2f:
bz2f.read(halflen)
self.assertEqual(next(bz2f), self.TEXT_LINES[0][halflen:])
self.assertEqual(bz2f.read(), self.TEXT[linelen:])
with BZ2File(self.filename) as bz2f:
bz2f.readline()
self.assertEqual(next(bz2f), self.TEXT_LINES[1])
self.assertEqual(bz2f.readline(), self.TEXT_LINES[2])
with BZ2File(self.filename) as bz2f:
bz2f.readlines()
self.assertRaises(StopIteration, next, bz2f)
self.assertEqual(bz2f.readlines(), [])
示例4: decompress
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def decompress(self, data):
pop = subprocess.Popen("bunzip2", shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
pop.stdin.write(data)
pop.stdin.close()
ret = pop.stdout.read()
pop.stdout.close()
if pop.wait() != 0:
ret = bz2.decompress(data)
return ret
示例5: testRead
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testRead(self):
# "Test BZ2File.read()"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
self.assertRaises(TypeError, bz2f.read, None)
self.assertEqual(bz2f.read(), self.TEXT)
示例6: testRead0
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testRead0(self):
# Test BBZ2File.read(0)"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
self.assertRaises(TypeError, bz2f.read, None)
self.assertEqual(bz2f.read(0), "")
示例7: testReadChunk10
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testReadChunk10(self):
# "Test BZ2File.read() in chunks of 10 bytes"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
text = ''
while 1:
str = bz2f.read(10)
if not str:
break
text += str
self.assertEqual(text, self.TEXT)
示例8: testRead100
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testRead100(self):
# "Test BZ2File.read(100)"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
self.assertEqual(bz2f.read(100), self.TEXT[:100])
示例9: testUniversalNewlinesCRLF
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testUniversalNewlinesCRLF(self):
# "Test BZ2File.read() with universal newlines (\\r\\n)"
self.createTempFile(crlf=1)
bz2f = BZ2File(self.filename, "rU")
self.assertEqual(bz2f.read(), self.TEXT)
self.assertEqual(bz2f.newlines, "\r\n")
bz2f.close()
示例10: testWrite
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testWrite(self):
# "Test BZ2File.write()"
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.write)
bz2f.write(self.TEXT)
with open(self.filename, 'rb') as f:
self.assertEqual(self.decompress(f.read()), self.TEXT)
示例11: testWriteChunks10
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testWriteChunks10(self):
# "Test BZ2File.write() with chunks of 10 bytes"
with BZ2File(self.filename, "w") as bz2f:
n = 0
while 1:
str = self.TEXT[n*10:(n+1)*10]
if not str:
break
bz2f.write(str)
n += 1
with open(self.filename, 'rb') as f:
self.assertEqual(self.decompress(f.read()), self.TEXT)
示例12: testWriteLines
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testWriteLines(self):
# "Test BZ2File.writelines()"
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.writelines)
sio = StringIO(self.TEXT)
bz2f.writelines(sio.readlines())
# patch #1535500
self.assertRaises(ValueError, bz2f.writelines, ["a"])
with open(self.filename, 'rb') as f:
self.assertEqual(self.decompress(f.read()), self.TEXT)
示例13: testSeekForward
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testSeekForward(self):
# "Test BZ2File.seek(150, 0)"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
self.assertRaises(TypeError, bz2f.seek)
bz2f.seek(150)
self.assertEqual(bz2f.read(), self.TEXT[150:])
示例14: testSeekBackwardsFromEnd
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testSeekBackwardsFromEnd(self):
# "Test BZ2File.seek(-150, 2)"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
bz2f.seek(-150, 2)
self.assertEqual(bz2f.read(), self.TEXT[len(self.TEXT)-150:])
示例15: testSeekPostEnd
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import read [as 别名]
def testSeekPostEnd(self):
# "Test BZ2File.seek(150000)"
self.createTempFile()
with BZ2File(self.filename) as bz2f:
bz2f.seek(150000)
self.assertEqual(bz2f.tell(), len(self.TEXT))
self.assertEqual(bz2f.read(), "")