• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python id3.BitPaddedInt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: save_frame

 def save_frame(frame):
     #Copied from mutagen.id3.ID3
     flags = 0
     framedata = frame._writeData()
     datasize = BitPaddedInt.to_str(len(framedata), width=4)
     header = pack('>4s4sH', type(frame).__name__, datasize, flags)
     return header + framedata
开发者ID:ltsavar,项目名称:prittag,代码行数:7,代码来源:mp3_chapter_frame.py


示例2: test_long

 def test_long(self):
     if PY2:
         data = BitPaddedInt.to_str(sys.maxint + 1, width=16)
         val = BitPaddedInt(data)
         self.assertEqual(val, sys.maxint + 1)
         self.assertTrue(isinstance(val, BitPaddedLong))
     else:
         self.assertTrue(BitPaddedInt is BitPaddedLong)
开发者ID:maphew,项目名称:mutagen,代码行数:8,代码来源:test__id3specs.py


示例3: __save_frame

 def __save_frame(self, frame, v2):
     flags = 0
     if self.PEDANTIC and isinstance(frame, TextFrame):
         if len(str(frame)) == 0: return ''
     framedata = frame._writeData()
     if v2 == 3: bits=8
     else: bits=7
     datasize = BitPaddedInt.to_str(len(framedata), width=4, bits=bits)
     header = pack('>4s4sH', type(frame).__name__, datasize, flags)
     return header + framedata
开发者ID:RobinDavid,项目名称:LyricsTagger,代码行数:10,代码来源:compatid3.py


示例4: test_w129l

 def test_w129l(self):
     self.assertEquals(
         BitPaddedInt.to_str(129, width=2, bigendian=False), b'\x01\x01')
开发者ID:svetlio2,项目名称:hackbg,代码行数:3,代码来源:test__id3specs.py


示例5: test_w129

 def test_w129(self):
     self.assertEquals(BitPaddedInt.to_str(129, width=2), b'\x01\x01')
开发者ID:svetlio2,项目名称:hackbg,代码行数:2,代码来源:test__id3specs.py


示例6: test_s65

 def test_s65(self):
     self.assertEquals(BitPaddedInt.to_str(0x41, 6), b'\x00\x00\x01\x01')
开发者ID:svetlio2,项目名称:hackbg,代码行数:2,代码来源:test__id3specs.py


示例7: test_s129

 def test_s129(self):
     self.assertEquals(BitPaddedInt.to_str(129), b'\x00\x00\x01\x01')
开发者ID:svetlio2,项目名称:hackbg,代码行数:2,代码来源:test__id3specs.py


示例8: test_s1l

 def test_s1l(self):
     self.assertEquals(
         BitPaddedInt.to_str(1, bigendian=False), b'\x01\x00\x00\x00')
开发者ID:svetlio2,项目名称:hackbg,代码行数:3,代码来源:test__id3specs.py


示例9: test_s1

 def test_s1(self):
     self.assertEquals(BitPaddedInt.to_bytes(1), b'\x00\x00\x00\x01')
开发者ID:fourth-4,项目名称:mutagen,代码行数:2,代码来源:test__id3specs.py


示例10: test_promote_long

 def test_promote_long(self):
     l = BitPaddedInt(sys.maxint ** 2)
     self.assertTrue(isinstance(l, long))
     self.assertEqual(BitPaddedInt(l.as_str(width=-1)), l)
开发者ID:svetlio2,项目名称:hackbg,代码行数:4,代码来源:test__id3specs.py


示例11: save

    def save(self, filename=None, v1=0):
        """Save changes to a file.
        If no filename is given, the one most recently loaded is used.
        Keyword arguments:
        v1 -- if 0, ID3v1 tags will be removed
                    if 1, ID3v1 tags will be updated but not added
                    if 2, ID3v1 tags will be created and/or updated
        The lack of a way to update only an ID3v1 tag is intentional.
        """
        # Sort frames by 'importance'
        order = ["TIT2", "TPE1", "TRCK", "TALB", "TPOS", "TDRC", "TCON"]
        order = dict(zip(order, range(len(order))))
        last = len(order)
        frames = self.items()
        frames.sort(lambda a, b: cmp(order.get(a[0][:4], last), order.get(b[0][:4], last)))

        framedata = [self.__save_frame(frame) for (key, frame) in frames]
        framedata.extend([data for data in self.unknown_frames if len(data) > 10])

        framedata = "".join(framedata)
        framesize = len(framedata)

        if filename is None:
            filename = self.filename
        f = open(filename, "rb+")
        try:
            idata = f.read(10)
            try:
                id3, vmaj, vrev, flags, insize = struct.unpack(">3sBBB4s", idata)
            except struct.error:
                id3, insize = "", 0
            insize = BitPaddedInt(insize)
            if id3 != "ID3":
                insize = -10
            if insize >= framesize:
                outsize = insize
            else:
                outsize = (framesize + 1023) & ~0x3FF
            framedata += "\x00" * (outsize - framesize)

            framesize = BitPaddedInt.to_str(outsize, width=4)
            flags = 0
            header = struct.pack(">3sBBB4s", "ID3", 4, 0, flags, framesize)
            data = header + framedata

            if insize < outsize:
                insert_bytes(f, outsize - insize, insize + 10)
            f.seek(0)

            try:
                f.seek(-128, 2)
            except IOError, err:
                if err.errno != EINVAL:
                    raise
                f.seek(0, 2)  # ensure read won't get "TAG"

            if f.read(3) == "TAG":
                f.seek(-128, 2)
                if v1 > 0:
                    f.write(MakeID3v1(self))
                else:
                    f.truncate()
            elif v1 == 2:
                f.seek(0, 2)
                f.write(MakeID3v1(self))
开发者ID:jbaiter,项目名称:beetfs,代码行数:65,代码来源:beetFs.py


示例12: test_has_valid_padding

    def test_has_valid_padding(self):
        self.failUnless(BitPaddedInt.has_valid_padding("\xff\xff", bits=8))
        self.failIf(BitPaddedInt.has_valid_padding("\xff"))
        self.failIf(BitPaddedInt.has_valid_padding("\x00\xff"))
        self.failUnless(BitPaddedInt.has_valid_padding("\x7f\x7f"))
        self.failIf(BitPaddedInt.has_valid_padding("\x7f", bits=6))
        self.failIf(BitPaddedInt.has_valid_padding("\x9f", bits=6))
        self.failUnless(BitPaddedInt.has_valid_padding("\x3f", bits=6))

        self.failUnless(BitPaddedInt.has_valid_padding(0xFF, bits=8))
        self.failIf(BitPaddedInt.has_valid_padding(0xFF))
        self.failIf(BitPaddedInt.has_valid_padding(0xFF << 8))
        self.failUnless(BitPaddedInt.has_valid_padding(0x7F << 8))
        self.failIf(BitPaddedInt.has_valid_padding(0x9F << 32, bits=6))
        self.failUnless(BitPaddedInt.has_valid_padding(0x3F << 16, bits=6))
开发者ID:hanvo,项目名称:MusicCloud,代码行数:15,代码来源:test__id3specs.py


示例13: test_s1

 def test_s1(self):
     self.assertEquals(BitPaddedInt.to_str(1), "\x00\x00\x00\x01")
开发者ID:hanvo,项目名称:MusicCloud,代码行数:2,代码来源:test__id3specs.py


示例14: unpack

            idata = f.read(10)
            try:
                id3, vmaj, vrev, flags, insize = unpack('>3sBBB4s', idata)
            except struct.error:
                id3, insize = '', 0
            insize = BitPaddedInt(insize)
            if id3 != 'ID3':
                insize = -10

            if insize >= framesize:
                outsize = insize
            else:
                outsize = (framesize + 1023) & ~0x3FF
            framedata += '\x00' * (outsize - framesize)

            framesize = BitPaddedInt.to_str(outsize, width=4)
            flags = 0
            header = pack('>3sBBB4s', 'ID3', v2, 0, flags, framesize)
            data = header + framedata

            if (insize < outsize):
                insert_bytes(f, outsize-insize, insize+10)
            f.seek(0)
            f.write(data)

            try:
                f.seek(-128, 2)
            except IOError, err:
                from errno import EINVAL
                if err.errno != EINVAL:
                    raise
开发者ID:kepstin,项目名称:picard,代码行数:31,代码来源:compatid3.py


示例15: test_varwidth

 def test_varwidth(self):
     self.assertEquals(len(BitPaddedInt.to_str(100)), 4)
     self.assertEquals(len(BitPaddedInt.to_str(100, width=-1)), 4)
     self.assertEquals(len(BitPaddedInt.to_str(2 ** 32, width=-1)), 5)
开发者ID:svetlio2,项目名称:hackbg,代码行数:4,代码来源:test__id3specs.py


示例16: test_minwidth

 def test_minwidth(self):
     self.assertEquals(
         len(BitPaddedInt.to_str(100, width=-1, minwidth=6)), 6)
开发者ID:svetlio2,项目名称:hackbg,代码行数:3,代码来源:test__id3specs.py


示例17: save

    def save(self, filename=None, v1=1, v2=4):
        """Save changes to a file.

        If no filename is given, the one most recently loaded is used.

        Keyword arguments:
        v1 -- if 0, ID3v1 tags will be removed
              if 1, ID3v1 tags will be updated but not added
              if 2, ID3v1 tags will be created and/or updated
        v2 -- version of ID3v2 tags (3 or 4). By default Mutagen saves ID3v2.4
              tags. If you want to save ID3v2.3 tags, you must call method
              update_to_v23 before saving the file.

        The lack of a way to update only an ID3v1 tag is intentional.
        """

        # Sort frames by 'importance'
        order = ["TIT2", "TPE1", "TRCK", "TALB", "TPOS", "TDRC", "TCON"]
        order = dict(zip(order, range(len(order))))
        last = len(order)
        frames = self.items()
        frames.sort(lambda a, b: cmp(order.get(a[0][:4], last),
                                     order.get(b[0][:4], last)))

        framedata = [self.__save_frame(frame, v2) for (key, frame) in frames]
        framedata.extend([data for data in self.unknown_frames
                          if len(data) > 10])
        if not framedata:
            try:
                self.delete(filename)
            except EnvironmentError as err:
                from errno import ENOENT
                if err.errno != ENOENT:
                    raise
            return

        framedata = ''.join(framedata)
        framesize = len(framedata)

        if filename is None:
            filename = self.filename
        try:
            f = open(filename, 'rb+')
        except IOError as err:
            from errno import ENOENT
            if err.errno != ENOENT:
                raise
            f = open(filename, 'ab')  # create, then reopen
            f = open(filename, 'rb+')
        try:
            idata = f.read(10)
            try:
                id3, vmaj, vrev, flags, insize = unpack('>3sBBB4s', idata)
            except struct.error:
                id3, insize = '', 0
            insize = BitPaddedInt(insize)
            if id3 != 'ID3':
                insize = -10

            if insize >= framesize:
                outsize = insize
            else:
                outsize = (framesize + 1023) & ~0x3FF
            framedata += '\x00' * (outsize - framesize)

            framesize = BitPaddedInt.to_str(outsize, width=4)
            flags = 0
            header = pack('>3sBBB4s', 'ID3', v2, 0, flags, framesize)
            data = header + framedata

            if (insize < outsize):
                insert_bytes(f, outsize - insize, insize + 10)
            f.seek(0)
            f.write(data)

            try:
                f.seek(-128, 2)
            except IOError as err:
                from errno import EINVAL
                if err.errno != EINVAL:
                    raise
                f.seek(0, 2)  # ensure read won't get "TAG"

            if f.read(3) == "TAG":
                f.seek(-128, 2)
                if v1 > 0:
                    f.write(MakeID3v1(self))
                else:
                    f.truncate()
            elif v1 == 2:
                f.seek(0, 2)
                f.write(MakeID3v1(self))

        finally:
            f.close()
开发者ID:mayhem,项目名称:picard,代码行数:95,代码来源:compatid3.py


示例18: test_has_valid_padding

    def test_has_valid_padding(self):
        self.failUnless(BitPaddedInt.has_valid_padding(b"\xff\xff", bits=8))
        self.failIf(BitPaddedInt.has_valid_padding(b"\xff"))
        self.failIf(BitPaddedInt.has_valid_padding(b"\x00\xff"))
        self.failUnless(BitPaddedInt.has_valid_padding(b"\x7f\x7f"))
        self.failIf(BitPaddedInt.has_valid_padding(b"\x7f", bits=6))
        self.failIf(BitPaddedInt.has_valid_padding(b"\x9f", bits=6))
        self.failUnless(BitPaddedInt.has_valid_padding(b"\x3f", bits=6))

        self.failUnless(BitPaddedInt.has_valid_padding(0xff, bits=8))
        self.failIf(BitPaddedInt.has_valid_padding(0xff))
        self.failIf(BitPaddedInt.has_valid_padding(0xff << 8))
        self.failUnless(BitPaddedInt.has_valid_padding(0x7f << 8))
        self.failIf(BitPaddedInt.has_valid_padding(0x9f << 32, bits=6))
        self.failUnless(BitPaddedInt.has_valid_padding(0x3f << 16, bits=6))
开发者ID:svetlio2,项目名称:hackbg,代码行数:15,代码来源:test__id3specs.py


示例19: test_s0

 def test_s0(self):
     self.assertEquals(BitPaddedInt.to_str(0), b'\x00\x00\x00\x00')
开发者ID:svetlio2,项目名称:hackbg,代码行数:2,代码来源:test__id3specs.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python m4a.Atom类代码示例发布时间:2022-05-27
下一篇:
Python id3.add函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap