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


Python OggPage.write方法代码示例

本文整理汇总了Python中mutagenx.ogg.OggPage.write方法的典型用法代码示例。如果您正苦于以下问题:Python OggPage.write方法的具体用法?Python OggPage.write怎么用?Python OggPage.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagenx.ogg.OggPage的用法示例。


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

示例1: test_too_many_packets

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
    def test_too_many_packets(self):
        packets = [b"1"] * 3000
        pages = OggPage.from_packets(packets)

        for p in pages:
            OggPage.write(p)

        self.failUnless(len(pages) > 3000//255)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:10,代码来源:test_ogg.py

示例2: test_unsupported_version

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
    def test_unsupported_version(self):
        page = OggPage(open(self.filename, "rb"))
        data = bytearray(page.packets[0])

        data[8] = 0x03
        page.packets[0] = bytes(data)
        OggOpusInfo(io.BytesIO(page.write()))

        data[8] = 0x10
        page.packets[0] = bytes(data)
        self.failUnlessRaises(IOError, OggOpusInfo, io.BytesIO(page.write()))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:13,代码来源:test_oggopus.py

示例3: test_read_max_size

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 def test_read_max_size(self):
     page = OggPage()
     page.packets = [b"1" * 255 * 255]
     page.complete = False
     page2 = OggPage()
     page2.packets = [b"", b"foo"]
     page2.sequence = 1
     page2.continued = True
     data = page.write() + page2.write()
     fileobj = io.BytesIO(data)
     self.failUnlessEqual(OggPage(fileobj), page)
     self.failUnlessEqual(OggPage(fileobj), page2)
     self.failUnlessRaises(EOFError, OggPage, fileobj)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:15,代码来源:test_ogg.py

示例4: test_theora_bad_version

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 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 = io.BytesIO(page.write())
     self.failUnlessRaises(IOError, OggTheoraInfo, fileobj)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:9,代码来源:test_oggtheora.py

示例5: test_negative_bitrate

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 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(io.BytesIO(page.write()))
     self.failUnlessEqual(info.bitrate, 0)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:10,代码来源:test_oggvorbis.py

示例6: test_underestimated_bitrate

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 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(io.BytesIO(page.write()))
     self.failUnlessEqual(info.bitrate, 65536)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:10,代码来源:test_oggvorbis.py

示例7: test_crc_py25

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
    def test_crc_py25(self):
        # Make sure page.write can handle both signed/unsigned int
        # return values of crc32.
        # http://code.google.com/p/mutagen/issues/detail?id=63
        # http://docs.python.org/library/zlib.html#zlib.crc32

        import zlib
        old_crc = zlib.crc32
        def zlib_uint(*args):
            return (old_crc(*args) & 0xffffffff)
        def zlib_int(*args):
            return cdata.int_be(cdata.to_uint_be(old_crc(*args) & 0xffffffff))

        try:
            page = OggPage()
            page.packets = [b"abc"]
            zlib.crc32 = zlib_uint
            uint_data = page.write()
            zlib.crc32 = zlib_int
            int_data  = page.write()
        finally:
            zlib.crc32 = old_crc

        self.failUnlessEqual(uint_data, int_data)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:26,代码来源:test_ogg.py

示例8: test_invalid_not_first

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 def test_invalid_not_first(self):
     page = OggPage(open(self.filename, "rb"))
     page.first = False
     self.failUnlessRaises(IOError, OggVorbisInfo, io.BytesIO(page.write()))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:6,代码来源:test_oggvorbis.py

示例9: test_theora_not_first_page

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 def test_theora_not_first_page(self):
     page = OggPage(open(self.filename, "rb"))
     page.first = False
     fileobj = io.BytesIO(page.write())
     self.failUnlessRaises(IOError, OggTheoraInfo, fileobj)
开发者ID:badwtg1111,项目名称:mutagen,代码行数:7,代码来源:test_oggtheora.py

示例10: test_invalid_version

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
 def test_invalid_version(self):
     page = OggPage()
     OggPage(io.BytesIO(page.write()))
     page.version = 1
     self.failUnlessRaises(OggError, OggPage, io.BytesIO(page.write()))
开发者ID:badwtg1111,项目名称:mutagen,代码行数:7,代码来源:test_ogg.py

示例11: TOggPage

# 需要导入模块: from mutagenx.ogg import OggPage [as 别名]
# 或者: from mutagenx.ogg.OggPage import write [as 别名]
class TOggPage(TestCase):
    uses_mmap = False

    def setUp(self):
        self.fileobj = open(os.path.join("tests", "data", "empty.ogg"), "rb")
        self.page = OggPage(self.fileobj)

        pages = [OggPage(), OggPage(), OggPage()]
        pages[0].packets = [b"foo"]
        pages[1].packets = [b"bar"]
        pages[2].packets = [b"baz"]
        for i in range(len(pages)):
            pages[i].sequence = i
        for page in pages:
            page.serial = 1
        self.pages = pages

    def test_flags(self):
        self.failUnless(self.page.first)
        self.failIf(self.page.continued)
        self.failIf(self.page.last)
        self.failUnless(self.page.complete)

        for first in [True, False]:
            self.page.first = first
            for last in [True, False]:
                self.page.last = last
                for continued in [True, False]:
                    self.page.continued = continued
                    self.failUnlessEqual(self.page.first, first)
                    self.failUnlessEqual(self.page.last, last)
                    self.failUnlessEqual(self.page.continued, continued)

    def test_flags_next_page(self):
        page = OggPage(self.fileobj)
        self.failIf(page.first)
        self.failIf(page.continued)
        self.failIf(page.last)

    def test_length(self):
        # Always true for Ogg Vorbis files
        self.failUnlessEqual(self.page.size, 58)
        self.failUnlessEqual(len(self.page.write()), 58)

    def test_first_metadata_page_is_separate(self):
        self.failIf(OggPage(self.fileobj).continued)

    def test_single_page_roundtrip(self):
        self.failUnlessEqual(
            self.page, OggPage(io.BytesIO(self.page.write())))

    def test_at_least_one_audio_page(self):
        page = OggPage(self.fileobj)
        while not page.last:
            page = OggPage(self.fileobj)
        self.failUnless(page.last)

    def test_crappy_fragmentation(self):
        packets = [b"1" * 511, b"2" * 511, b"3" * 511]
        pages = OggPage.from_packets(packets, default_size=510, wiggle_room=0)
        self.failUnless(len(pages) > 3)
        self.failUnlessEqual(OggPage.to_packets(pages), packets)

    def test_wiggle_room(self):
        packets = [b"1" * 511, b"2" * 511, b"3" * 511]
        pages = OggPage.from_packets(packets, default_size=510, wiggle_room=100)
        self.failUnlessEqual(len(pages), 3)
        self.failUnlessEqual(OggPage.to_packets(pages), packets)

    def test_one_packet_per_wiggle(self):
        packets = [b"1" * 511, b"2" * 511, b"3" * 511]
        pages = OggPage.from_packets(
            packets, default_size=1000, wiggle_room=1000000)
        self.failUnlessEqual(len(pages), 2)
        self.failUnlessEqual(OggPage.to_packets(pages), packets)

    def test_renumber(self):
        self.failUnlessEqual(
            [page.sequence for page in self.pages], [0, 1, 2])
        fileobj = io.BytesIO()
        for page in self.pages:
            fileobj.write(page.write())
        fileobj.seek(0)
        OggPage.renumber(fileobj, 1, 10)
        fileobj.seek(0)
        pages = [OggPage(fileobj) for i in range(3)]
        self.failUnlessEqual([page.sequence for page in pages], [10, 11, 12])

        fileobj.seek(0)
        OggPage.renumber(fileobj, 1, 20)
        fileobj.seek(0)
        pages = [OggPage(fileobj) for i in range(3)]
        self.failUnlessEqual([page.sequence for page in pages], [20, 21, 22])

    def test_renumber_extradata(self):
        fileobj = io.BytesIO()
        for page in self.pages:
            fileobj.write(page.write())
        fileobj.write(b"left over data")
        fileobj.seek(0)
#.........这里部分代码省略.........
开发者ID:badwtg1111,项目名称:mutagen,代码行数:103,代码来源:test_ogg.py


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