<commit_before>'''
Created on 27 may 2014

@author: Scondo
'''
import unittest
import pngsuite
from PIL import Image
from io import BytesIO

from PIL import PngImagePlugin as pilpng
from png import PngImagePlugin as purepng

try:
    reload
except NameError:
    from imp import reload


class PilImageToPyPngAdapter:
    def __init__(self, im):
        self.im = im
        self.nowrow = 0

    def __len__(self):
        return self.im.size[1]

    def next(self):
        if self.nowrow >= self.__len__():
            raise StopIteration()
        else:
            self.nowrow += 1
            return self.__getitem__(self.nowrow)

    def __iter__(self):
        return self

    def __getitem__(self, row):
        out = []
        for col in range(self.im.size[0]):
            px = self.im.getpixel((col, row))
            if hasattr(px, '__iter__'):
                # Multi-channel image
                out.extend(px)
            else:
                # Single channel image
                out.append(px)
        return out


class BaseTest(unittest.TestCase):
    test_ = None

    def compareImages(self, im1, im2):
        if 'gamma' in im1.info:
            self.assertEqual(im1.info['gamma'], im2.info.get('gamma'))
        if im1.mode != im2.mode or im1.mode == 'P':
            im1 = im1.convert('RGBA')
            im2 = im2.convert('RGBA')
        pix1 = PilImageToPyPngAdapter(im1)
        pix2 = PilImageToPyPngAdapter(im2)
        if im1.mode == 'RGBA':
            self.assertEqual(pix1[0][3::4], pix2[0][3::4])  # alpha fast check
        self.assertEqual(pix1[0], pix2[0])  # fast check<commit_msg>fixed iterator<commit_after>'''
Created on 27 may 2014

@author: Scondo
'''
import unittest
import pngsuite
from PIL import Image
from io import BytesIO

from PIL import PngImagePlugin as pilpng
from png import PngImagePlugin as purepng

try:
    reload
except NameError:
    from imp import reload


class PilImageToPyPngAdapter:
    def __init__(self, im):
        self.im = im
        self.nowrow = 0

    def __len__(self):
        return self.im.size[1]

    def next(self):
        if self.nowrow >= self.__len__():
            raise StopIteration()
        else:
            self.nowrow += 1
            return self.__getitem__(self.nowrow - 1)

    def __iter__(self):
        return self

    def __getitem__(self, row):
        out = []
        for col in range(self.im.size[0]):
            px = self.im.getpixel((col, row))
            if hasattr(px, '__iter__'):
                # Multi-channel image
                out.extend(px)
            else:
                # Single channel image
                out.append(px)
        return out


class BaseTest(unittest.TestCase):
    test_ = None

    def compareImages(self, im1, im2):
        if 'gamma' in im1.info:
            self.assertEqual(im1.info['gamma'], im2.info.get('gamma'))
        if im1.mode != im2.mode or im1.mode == 'P':
            im1 = im1.convert('RGBA')
            im2 = im2.convert('RGBA')
        pix1 = PilImageToPyPngAdapter(im1)
        pix2 = PilImageToPyPngAdapter(im2)
        if im1.mode == 'RGBA':
            self.assertEqual(pix1[0][3::4], pix2[0][3::4])  # alpha fast check
        self.assertEqual(pix1[0], pix2[0])  # fast check
{'fraction_non_alphanumeric': 0.11035966799877037, 'fraction_numerical': 0.024285275130648633, 'mean_word_length': 2.021355617455896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5852861', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1019, 'n_words': 267}