Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_covr_blank_format(self):
data = Atom.render(
b"data", b"\x00\x00\x00\x00" + b"\x00" * 4 + b"whee")
covr = Atom.render(b"covr", data)
tags = self.wrap_ilst(covr)
self.failUnlessEqual(
MP4Cover.FORMAT_JPEG, tags["covr"][0].imageformat)
def test_strips_bad_unknown_types(self):
data = Atom.render(b"datA", b"\x00" * 8 + b"whee")
foob = Atom.render(b"foob", data)
tags = self.wrap_ilst(foob)
self.failIf(tags)
def test_mdhd_version_1(self, soun=b"soun"):
mdhd = Atom.render(b"mdhd", (b"\x01\x00\x00\x00" + b"\x00" * 16 +
b"\x00\x00\x00\x02" + # 2 Hz
b"\x00\x00\x00\x00\x00\x00\x00\x10"))
hdlr = Atom.render(b"hdlr", b"\x00" * 8 + soun)
mdia = Atom.render(b"mdia", mdhd + hdlr)
trak = Atom.render(b"trak", mdia)
moov = Atom.render(b"moov", trak)
fileobj = BytesIO(moov)
atoms = Atoms(fileobj)
info = MP4Info(atoms, fileobj)
self.failUnlessEqual(info.length, 8)
def wrap_ilst(self, data):
ilst = Atom.render(b"ilst", data)
meta = Atom.render(b"meta", b"\x00" * 4 + ilst)
data = Atom.render(b"moov", Atom.render(b"udta", meta))
fileobj = BytesIO(data)
return MP4Tags(Atoms(fileobj), fileobj)
def test_multiple_tracks(self):
hdlr = Atom.render(b"hdlr", b"\x00" * 8 + b"whee")
mdia = Atom.render(b"mdia", hdlr)
trak1 = Atom.render(b"trak", mdia)
mdhd = Atom.render(b"mdhd", (b"\x01\x00\x00\x00" + b"\x00" * 16 +
b"\x00\x00\x00\x02" + # 2 Hz
b"\x00\x00\x00\x00\x00\x00\x00\x10"))
hdlr = Atom.render(b"hdlr", b"\x00" * 8 + b"soun")
mdia = Atom.render(b"mdia", mdhd + hdlr)
trak2 = Atom.render(b"trak", mdia)
moov = Atom.render(b"moov", trak1 + trak2)
fileobj = cBytesIO(moov)
atoms = Atoms(fileobj)
info = MP4Info(atoms, fileobj)
self.failUnlessEqual(info.length, 8)
add(TMP4Info)
def test_genre_too_big(self):
data = Atom.render(b"data", b"\x00" * 8 + b"\x01\x00")
genre = Atom.render(b"gnre", data)
tags = self.wrap_ilst(genre)
self.failIf(b"gnre" in tags)
self.failIf(b"\xa9gen" in tags)
def test_genre_too_big(self):
data = Atom.render(b"data", b"\x00" * 8 + b"\x01\x00")
genre = Atom.render(b"gnre", data)
tags = self.wrap_ilst(genre)
self.failIf("gnre" in tags)
self.failIf("\xa9gen" in tags)
def test_render_too_big(self):
class TooBig(bytes):
def __len__(self):
return 1 << 32
data = TooBig(b"test")
try:
len(data)
except OverflowError:
# Py_ssize_t is still only 32 bits on this system.
self.failUnlessRaises(OverflowError, Atom.render, b"data", data)
else:
data = Atom.render(b"data", data)
self.failUnlessEqual(len(data), 4 + 4 + 8 + 4)
def test_render_too_big(self):
class TooBig(bytes):
def __len__(self):
return 1 << 32
data = TooBig(b"test")
try: len(data)
except OverflowError:
# Py_ssize_t is still only 32 bits on this system.
self.failUnlessRaises(OverflowError, Atom.render, b"data", data)
else:
data = Atom.render(b"data", data)
self.failUnlessEqual(len(data), 4 + 4 + 8 + 4)
def __render_data(self, key, flags, value):
return Atom.render(key, b''.join(
Atom.render(b"data", struct.pack(">2I", flags, 0) + data)
for data in value))