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


Python _compat.cBytesIO函数代码示例

本文整理汇总了Python中mutagen._compat.cBytesIO函数的典型用法代码示例。如果您正苦于以下问题:Python cBytesIO函数的具体用法?Python cBytesIO怎么用?Python cBytesIO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cBytesIO函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_almost_my_file

 def test_almost_my_file(self):
     self.failUnlessRaises(
         MusepackHeaderError, MusepackInfo, cBytesIO(b"MP+" + b"\x00" * 32))
     self.failUnlessRaises(
         MusepackHeaderError, MusepackInfo, cBytesIO(b"MP+" + b"\x00" * 100))
     self.failUnlessRaises(
         MusepackHeaderError, MusepackInfo, cBytesIO(b"MPCK" + b"\x00" * 100))
开发者ID:LordSputnik,项目名称:mutagen,代码行数:7,代码来源:test_musepack.py

示例2: test_read

    def test_read(self):
        payload = 8 * b"\xff"
        fileobj = cBytesIO(b"\x00\x00\x00\x10atom" + payload)
        atom = Atom(fileobj)
        ok, data = atom.read(fileobj)
        self.assertTrue(ok)
        self.assertEqual(data, payload)

        payload = 7 * b"\xff"
        fileobj = cBytesIO(b"\x00\x00\x00\x10atom" + payload)
        atom = Atom(fileobj)
        ok, data = atom.read(fileobj)
        self.assertFalse(ok)
        self.assertEqual(data, payload)
开发者ID:maphew,项目名称:mutagen,代码行数:14,代码来源:test_mp4.py

示例3: _parse_dac3

    def _parse_dac3(self, atom, fileobj):
        # ETSI TS 102 366

        assert atom.name == b"dac3"

        ok, data = atom.read(fileobj)
        if not ok:
            raise ASEntryError("truncated %s atom" % atom.name)
        fileobj = cBytesIO(data)
        r = BitReader(fileobj)

        # sample_rate in AudioSampleEntry covers values in
        # fscod2 and not just fscod, so ignore fscod here.
        try:
            r.skip(2 + 5 + 3)  # fscod, bsid, bsmod
            acmod = r.bits(3)
            lfeon = r.bits(1)
            bit_rate_code = r.bits(5)
            r.skip(5)  # reserved
        except BitReaderError as e:
            raise ASEntryError(e)

        self.channels = [2, 1, 2, 3, 3, 4, 4, 5][acmod] + lfeon

        try:
            self.bitrate = [
                32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192,
                224, 256, 320, 384, 448, 512, 576, 640][bit_rate_code] * 1000
        except IndexError:
            pass
开发者ID:Allifreyr,项目名称:plexpy,代码行数:30,代码来源:_as_entry.py

示例4: test_fileobj

 def test_fileobj(self):
     for filename in self.filenames:
         with open(filename, "rb") as h:
             self.assertTrue(File(h) is not None)
         with open(filename, "rb") as h:
             fileobj = cBytesIO(h.read())
             self.assertTrue(File(fileobj, filename=filename) is not None)
开发者ID:gdelfresno,项目名称:mutagen,代码行数:7,代码来源:test___init__.py

示例5: test_theora_bad_version

 def test_theora_bad_version(self):
     page = OggPage(open(self.filename, "rb"))
     packet = page.packets[0]
     packet = packet[:7] + b"\x03\x00" + packet[9:]
     page.packets = [packet]
     fileobj = cBytesIO(page.write())
     self.failUnlessRaises(IOError, OggTheoraInfo, fileobj)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:7,代码来源:test_oggtheora.py

示例6: test_length_0_container

 def test_length_0_container(self):
     data = cBytesIO(struct.pack(">I4s", 0, b"moov") +
                     Atom.render(b"data", b"whee"))
     atom = Atom(data)
     self.failUnlessEqual(len(atom.children), 1)
     self.failUnlessEqual(atom.length, 20)
     self.failUnlessEqual(atom.children[-1].length, 12)
开发者ID:maphew,项目名称:mutagen,代码行数:7,代码来源:test_mp4.py

示例7: test_invalid_header

 def test_invalid_header(self):
     asf = ASF()
     fileobj = cBytesIO(
         b"0&\xb2u\x8ef\xcf\x11\xa6\xd9\x00\xaa\x00b\xcel\x19\xbf\x01\x00"
         b"\x00\x00\x00\x00\x07\x00\x00\x00\x01\x02")
     self.assertRaises(
         ASFHeaderError, HeaderObject.parse_full, asf, fileobj)
开发者ID:akerbis,项目名称:mutagen,代码行数:7,代码来源:test_asf.py

示例8: test_underestimated_bitrate

 def test_underestimated_bitrate(self):
     page = OggPage(open(self.filename, "rb"))
     packet = page.packets[0]
     packet = (packet[:16] + b"\x00\x00\x01\x00" + b"\x01\x00\x00\x00" +
               b"\x00\x00\x01\x00" + packet[28:])
     page.packets[0] = packet
     info = OggVorbisInfo(cBytesIO(page.write()))
     self.failUnlessEqual(info.bitrate, 65536)
开发者ID:akerbis,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py

示例9: test_negative_bitrate

 def test_negative_bitrate(self):
     page = OggPage(open(self.filename, "rb"))
     packet = page.packets[0]
     packet = (packet[:16] + b"\xff\xff\xff\xff" + b"\xff\xff\xff\xff" +
               b"\xff\xff\xff\xff" + packet[28:])
     page.packets[0] = packet
     info = OggVorbisInfo(cBytesIO(page.write()))
     self.failUnlessEqual(info.bitrate, 0)
开发者ID:akerbis,项目名称:mutagen,代码行数:8,代码来源:test_oggvorbis.py

示例10: test_zero_padded_sh_packet

    def test_zero_padded_sh_packet(self):
        # https://bitbucket.org/lazka/mutagen/issue/198
        data = (b"MPCKSH\x10\x95 Q\xa2\x08\x81\xb8\xc9T\x00\x1e\x1b"
                b"\x00RG\x0c\x01A\xcdY\x06?\x80Z\x06EI")

        fileobj = cBytesIO(data)
        info = MusepackInfo(fileobj)
        self.assertEqual(info.channels, 2)
        self.assertEqual(info.samples, 3024084)
开发者ID:Shutshutnunte,项目名称:mutagen,代码行数:9,代码来源:test_musepack.py

示例11: test_bits

    def test_bits(self):
        data = b"\x12\x34\x56\x78\x89\xAB\xCD\xEF"
        ref = cdata.uint64_be(data)

        for i in xrange(64):
            fo = cBytesIO(data)
            r = BitReader(fo)
            v = r.bits(i) << (64 - i) | r.bits(64 - i)
            self.assertEqual(v, ref)
开发者ID:akerbis,项目名称:mutagen,代码行数:9,代码来源:test__util.py

示例12: test_get_position

 def test_get_position(self):
     r = BitReader(cBytesIO(b"\xAB\xCD"))
     self.assertEqual(r.get_position(), 0)
     r.bits(3)
     self.assertEqual(r.get_position(), 3)
     r.skip(9)
     self.assertEqual(r.get_position(), 3 + 9)
     r.align()
     self.assertEqual(r.get_position(), 16)
开发者ID:akerbis,项目名称:mutagen,代码行数:9,代码来源:test__util.py

示例13: test_invalid_header

 def test_invalid_header(self):
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         asf = ASF()
     fileobj = cBytesIO(
         b"0&\xb2u\x8ef\xcf\x11\xa6\xd9\x00\xaa\x00b\xcel\x19\xbf\x01\x00"
         b"\x00\x00\x00\x00\x07\x00\x00\x00\x01\x02")
     self.assertRaises(
         ASFHeaderError, HeaderObject.parse_full, asf, fileobj)
开发者ID:quodlibet,项目名称:mutagen,代码行数:9,代码来源:test_asf.py

示例14: test_valid_info_header

    def test_valid_info_header(self):
        data = (b'Info\x00\x00\x00\x0f\x00\x00:>\x00\xed\xbd8\x00\x03\x05\x07'
                b'\n\r\x0f\x12\x14\x17\x1a\x1c\x1e"$&)+.1359;[email protected]\\^ac'
                b'fikmqsux{}\x80\x82\x84\x87\x8a\x8c\x8e\x92\x94\x96\x99\x9c'
                b'\x9e\xa1\xa3\xa5\xa9\xab\xad\xb0\xb3\xb5\xb8\xba\xbd\xc0\xc2'
                b'\xc4\xc6\xca\xcc\xce\xd1\xd4\xd6\xd9\xdb\xdd\xe1\xe3\xe5\xe8'
                b'\xeb\xed\xf0\xf2\xf5\xf8\xfa\xfc\x00\x00\x009')

        fileobj = cBytesIO(data)
        xing = XingHeader(fileobj)
        self.assertEqual(xing.bytes, 15580472)
        self.assertEqual(xing.frames, 14910)
        self.assertEqual(xing.vbr_scale, 57)
        self.assertTrue(xing.toc)
        self.assertEqual(len(xing.toc), 100)
        self.assertEqual(sum(xing.toc), 12625)  # only for coverage..
        self.assertEqual(xing.is_info, True)

        XingHeader(cBytesIO(data.replace(b'Info', b'Xing')))
开发者ID:maphew,项目名称:mutagen,代码行数:19,代码来源:test_mp3.py

示例15: test_xing_unknown_framecount

 def test_xing_unknown_framecount(self):
     frame = (
         b'\xff\xfb\xe4\x0c\x00\x0f\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00Info\x00\x00\x00\x02\x00\[email protected]\x00\xb4R\x80\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
     )
     fileobj = cBytesIO(frame)
     info = MPEGInfo(fileobj)
     assert info.bitrate == 320000
     assert info.length > 0
开发者ID:quodlibet,项目名称:mutagen,代码行数:11,代码来源:test_mp3.py


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