예제 #1
0
    def testRender(self):
        h = TagHeader()
        h.unsync = False
        header = h.render(100)

        h2 = TagHeader()
        found = h2.parse(StringIO(header))
        assert_false(h2.unsync)
        assert_true(found)
        assert_equal(header, h2.render(100))

        h = TagHeader()
        h.footer = True
        h.extended = True
        header = h.render(666)

        h2 = TagHeader()
        found = h2.parse(StringIO(header))
        assert_true(found)
        assert_false(h2.unsync)
        assert_false(h2.experimental)
        assert_true(h2.footer)
        assert_true(h2.extended)
        assert_equal(h2.tag_size, 666)
        assert_equal(header, h2.render(666))
예제 #2
0
def pilImage(source):
    if not _have_PIL:
        return None

    from PIL import Image
    if isinstance(source, ImageFrame):
        return Image.open(StringIO(source.image_data))
    else:
        return Image.open(source)
예제 #3
0
 def testVersionOutput(self):
         for arg in ["--version"]:
             with RedirectStdStreams(stderr=StringIO()) as out:
                 try:
                     args, parser = main.parseCommandLine([arg])
                 except SystemExit as ex:
                     out.stderr.seek(0)
                     expected = "eyeD3 %s-%s" % (info.VERSION, info.RELEASE)
                     assert_true(out.stderr.read().startswith(expected))
                     assert_equal(ex.code, 0)
예제 #4
0
 def testInvalidFlagBits(self):
     for bad_flags in [b"\x00\x20", b"\x01\x01"]:
         h = ExtendedTagHeader()
         try:
             h.parse(StringIO(b"\x00\x00\x00\xff" + bad_flags), (2, 4, 0))
         except TagException:
             pass
         else:
             assert_false("Bad ExtendedTagHeader flags, expected "
                          "TagException")
예제 #5
0
    def testRenderCrcPadding(self):
        version = (2, 4, 0)

        h = ExtendedTagHeader()
        h.crc_bit = 1
        header = h.render(version, "\x01", 0)

        h2 = ExtendedTagHeader()
        h2.parse(StringIO(header), version)
        assert_equal(h.crc, h2.crc)
예제 #6
0
    def testRender(self):
        version = (2, 4, 0)
        dummy_data = b"\xab" * 50
        dummy_padding_len = 1024

        h = ExtendedTagHeader()
        h.update_bit = 1
        h.crc_bit = 1
        h.tag_size_restriction = ExtendedTagHeader.RESTRICT_TAG_SZ_MED
        h.text_enc_restriction = ExtendedTagHeader.RESTRICT_TEXT_ENC_UTF8
        h.text_length_restriction = ExtendedTagHeader.RESTRICT_TEXT_LEN_128
        h.image_enc_restriction = ExtendedTagHeader.RESTRICT_IMG_ENC_PNG_JPG
        h.image_size_restriction = ExtendedTagHeader.RESTRICT_IMG_SZ_256
        header = h.render(version, dummy_data, dummy_padding_len)

        h2 = ExtendedTagHeader()
        h2.parse(StringIO(header), version)
        assert_true(h2.update_bit)
        assert_true(h2.crc_bit)
        assert_true(h2.restrictions_bit)
        assert_equal(h.crc, h2.crc)
        assert_equal(h.tag_size_restriction, h2.tag_size_restriction)
        assert_equal(h.text_enc_restriction, h2.text_enc_restriction)
        assert_equal(h.text_length_restriction, h2.text_length_restriction)
        assert_equal(h.image_enc_restriction, h2.image_enc_restriction)
        assert_equal(h.image_size_restriction, h2.image_size_restriction)

        assert_equal(h2.render(version, dummy_data, dummy_padding_len), header)

        # version 2.3
        header_23 = h.render((2, 3, 0), dummy_data, dummy_padding_len)

        h3 = ExtendedTagHeader()
        h3.parse(StringIO(header_23), (2, 3, 0))
        assert_false(h3.update_bit)
        assert_true(h3.crc_bit)
        assert_false(h3.restrictions_bit)
        assert_equal(h.crc, h3.crc)
        assert_equal(0, h3.tag_size_restriction)
        assert_equal(0, h3.text_enc_restriction)
        assert_equal(0, h3.text_length_restriction)
        assert_equal(0, h3.image_enc_restriction)
        assert_equal(0, h3.image_size_restriction)
예제 #7
0
def testFindHeader():
    from eyed3.mp3.headers import findHeader

    # No header
    buffer = StringIO(b'\x00' * 1024)
    (offset, header_int, header_bytes) = findHeader(buffer, 0)
    assert_equal(header_int, None)

    # Valid header
    buffer = StringIO(b'\x11\x12\x23' * 1024 + b"\xff\xfb\x90\x64" +
                      b"\x00" * 1024)
    (offset, header_int, header_bytes) = findHeader(buffer, 0)
    assert_equal(header_int, 0xfffb9064)

    # Same thing with a false sync in the mix
    buffer = StringIO(b'\x11\x12\x23' * 1024 + b"\x11" * 100 +
                      b"\xff\xea\x00\x00" +  # false sync
                      b"\x22" * 100 + b"\xff\xe2\x1c\x34" +  # false sync
                      b"\xee" * 100 + b"\xff\xfb\x90\x64" + b"\x00" * 1024)
    (offset, header_int, header_bytes) = findHeader(buffer, 0)
    assert_equal(header_int, 0xfffb9064)
예제 #8
0
    def testParse(self):
        # Incomplete headers
        for data in [
                b"",
                b"ID3",
                b"ID3\x04\x00",
                b"ID3\x02\x00\x00",
                b"ID3\x03\x00\x00",
                b"ID3\x04\x00\x00",
        ]:
            header = TagHeader()
            found = header.parse(StringIO(data))
            assert_false(found)

        # Inalid versions
        for data in [
                b"ID3\x01\x00\x00",
                b"ID3\x05\x00\x00",
                b"ID3\x06\x00\x00",
        ]:
            header = TagHeader()
            try:
                found = header.parse(StringIO(data))
            except TagException:
                pass
            else:
                assert_false("Expected TagException invalid version")

        # Complete headers
        for data in [
                b"ID3\x02\x00\x00",
                b"ID3\x03\x00\x00",
                b"ID3\x04\x00\x00",
        ]:
            for sz in [0, 10, 100, 1000, 2500, 5000, 7500, 10000]:
                sz_bytes = bin2bytes(bin2synchsafe(dec2bin(sz, 32)))
                header = TagHeader()
                found = header.parse(StringIO(data + sz_bytes))
                assert_true(found)
                assert_equal(header.tag_size, sz)
예제 #9
0
def profileMain(args, config):  # pragma: no cover
    """This is the main function for profiling
    http://code.google.com/appengine/kb/commontasks.html#profiling
    """
    import cProfile
    import pstats

    eyed3.log.debug("driver profileMain")
    prof = cProfile.Profile()
    prof = prof.runctx("main(args)", globals(), locals())

    stream = StringIO()
    stats = pstats.Stats(prof, stream=stream)
    stats.sort_stats("time")  # Or cumulative
    stats.print_stats(100)  # 80 = how many to print

    # The rest is optional.
    stats.print_callees()
    stats.print_callers()
    sys.stderr.write("Profile data:\n%s\n" % stream.getvalue())

    return 0
예제 #10
0
def profileMain(args, config):  # pragma: no cover
    '''This is the main function for profiling
    http://code.google.com/appengine/kb/commontasks.html#profiling
    '''
    import cProfile
    import pstats

    eyed3.log.debug("driver profileMain")
    prof = cProfile.Profile()
    prof = prof.runctx("main(args)", globals(), locals())

    stream = StringIO()
    stats = pstats.Stats(prof, stream=stream)
    stats.sort_stats("time")  # Or cumulative
    stats.print_stats(100)  # 80 = how many to print

    # The rest is optional.
    stats.print_callees()
    stats.print_callers()
    sys.stderr.write("Profile data:\n%s\n" % stream.getvalue())

    return 0
예제 #11
0
파일: __init__.py 프로젝트: janstarke/eyed3
 def __init__(self, stdout=None, stderr=None, seek_on_exit=0):
     self.stdout = stdout or StringIO()
     self.stderr = stderr or StringIO()
     self._seek_offset = seek_on_exit