<commit_before>import atexit
import logging
import os
import shutil
import tempfile
from logging import DEBUG

log = logging.getLogger(__name__)

CLEANUP = True


class ImageDebug(object):
    def __init__(self):
        self.index = 0
        self.dir = tempfile.mkdtemp(prefix="pyscreenshot_img_")
        if CLEANUP:
            atexit.register(shutil.rmtree, self.dir)

    def img_debug(self, im, text):
        if not log.isEnabledFor(DEBUG):<commit_msg>test: put grabbed images in testout dir<commit_after>import atexit
import logging
import os
import shutil
import tempfile
from logging import DEBUG

log = logging.getLogger(__name__)

CLEANUP = False

# for image debug
USE_TESTOUT_DIR = 1


class ImageDebug(object):
    def __init__(self):
        self.index = 0
        d = None
        if USE_TESTOUT_DIR:
            d = os.path.join(os.getcwd(), "testout")
            os.makedirs(d, exist_ok=True)
        self.dir = tempfile.mkdtemp(dir=d, prefix="pyscreenshot_img_")
        if CLEANUP:
            atexit.register(shutil.rmtree, self.dir)

    def img_debug(self, im, text):
        if not log.isEnabledFor(DEBUG):
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.00264783759929391, 'mean_word_length': 3.0355871886120998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5963311', 'n_tokens_mistral': 376, 'n_tokens_neox': 366, 'n_words': 94}