<commit_before># -*- coding: utf-8 -*-

from __future__ import absolute_import

from .base import Type
from .isobmff import IsoBmff


class Jpeg(Type):
    """
    Implements the JPEG image type matcher.
    """
    MIME = 'image/jpeg'
    EXTENSION = 'jpg'

    def __init__(self):
        super(Jpeg, self).__init__(
            mime=Jpeg.MIME,
            extension=Jpeg.EXTENSION
        )

    def match(self, buf):
        return (len(buf) > 2 and
                buf[0] == 0xFF and
                buf[1] == 0xD8 and
                buf[2] == 0xFF)


class Jpx(Type):
    """
    Implements the JPEG2000 image type matcher.
    """

    MIME = "image/jpx"
    EXTENSION = "jpx"

    def __init__(self):
        super(Jpx, self).__init__(mime=Jpx.MIME, extension=Jpx.EXTENSION)

    def match(self, buf):
        return (
            len(buf) > 50
            and buf[0] == 0x00
            and buf[1] == 0x00
            and buf[2] == 0x00
            and buf[3] == 0x0C
            and buf[16:24] == b"ftypjp2 "
        )


class Png(Type):<commit_msg>add APNG support (part 1)<commit_after># -*- coding: utf-8 -*-

from __future__ import absolute_import

from .base import Type
from .isobmff import IsoBmff


class Jpeg(Type):
    """
    Implements the JPEG image type matcher.
    """
    MIME = 'image/jpeg'
    EXTENSION = 'jpg'

    def __init__(self):
        super(Jpeg, self).__init__(
            mime=Jpeg.MIME,
            extension=Jpeg.EXTENSION
        )

    def match(self, buf):
        return (len(buf) > 2 and
                buf[0] == 0xFF and
                buf[1] == 0xD8 and
                buf[2] == 0xFF)


class Jpx(Type):
    """
    Implements the JPEG2000 image type matcher.
    """

    MIME = "image/jpx"
    EXTENSION = "jpx"

    def __init__(self):
        super(Jpx, self).__init__(mime=Jpx.MIME, extension=Jpx.EXTENSION)

    def match(self, buf):
        return (
            len(buf) > 50
            and buf[0] == 0x00
            and buf[1] == 0x00
            and buf[2] == 0x00
            and buf[3] == 0x0C
            and buf[16:24] == b"ftypjp2 "
        )


class Apng(Type):
    """
    Implements the APNG image type matcher.
    """
    MIME = 'image/apng'
    EXTENSION = 'apng'

    def __init__(self):
        super(Apng, self).__init__(
            mime=Apng.MIME,
            extension=Apng.EXTENSION
        )

    def match(self, buf):
        if(len(buf) > 8 and
           buf[:8] == bytearray([0x89, 0x50, 0x4e, 0x47,
                                 0x0d, 0x0a, 0x1a, 0x0a])):
            #cursor in buf, skip already readed 8 bytes
            i = 8
            while len(buf) > i:
                data_length = int.from_bytes(buf[i:i+4], byteorder="big")
                i += 4

                chunk_type = buf[i:i+4].decode("ascii")
                i += 4

                #acTL chunk in APNG should appears first than IDAT
                #IEND is end of PNG
                if (chunk_type == "IDAT" or chunk_type == "IEND"):
                    return 0
                elif (chunk_type == "acTL"):
                    return 1

                #move to the next chank by skipping data and crc (4 bytes)
                i += data_length + 4
            return 0
        else:
            return 0


class Png(Type):
{'fraction_non_alphanumeric': 0.11630731855450957, 'fraction_numerical': 0.0315821439416945, 'mean_word_length': 1.5241379310344827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1967127', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1083, 'n_words': 281}