本文整理汇总了Python中mutagen.id3.BitPaddedInt类的典型用法代码示例。如果您正苦于以下问题:Python BitPaddedInt类的具体用法?Python BitPaddedInt怎么用?Python BitPaddedInt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitPaddedInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例4: test_w129l
def test_w129l(self):
self.assertEquals(
BitPaddedInt.to_str(129, width=2, bigendian=False), b'\x01\x01')
示例5: test_w129
def test_w129(self):
self.assertEquals(BitPaddedInt.to_str(129, width=2), b'\x01\x01')
示例6: test_s65
def test_s65(self):
self.assertEquals(BitPaddedInt.to_str(0x41, 6), b'\x00\x00\x01\x01')
示例7: test_s129
def test_s129(self):
self.assertEquals(BitPaddedInt.to_str(129), b'\x00\x00\x01\x01')
示例8: test_s1l
def test_s1l(self):
self.assertEquals(
BitPaddedInt.to_str(1, bigendian=False), b'\x01\x00\x00\x00')
示例9: test_s1
def test_s1(self):
self.assertEquals(BitPaddedInt.to_bytes(1), b'\x00\x00\x00\x01')
示例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)
示例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))
示例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))
示例13: test_s1
def test_s1(self):
self.assertEquals(BitPaddedInt.to_str(1), "\x00\x00\x00\x01")
示例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
示例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)