<commit_before>'''
Wand (>=v0.3.0) engine for Sorl-thumbnail
'''

from wand.image import Image
from wand.exceptions import CorruptImageError
from sorl.thumbnail.engines.base import EngineBase


class Engine(EngineBase):
    def get_image(self, source):
        return Image(blob=source.read())

    def get_image_size(self, image):
        return image.size

    def is_valid_image(self, raw_data):
        '''
        Wand library makes sure when opening any image that is fine, when
        the image is corrupted raises an exception.
        '''

        try:
            Image(blob=raw_data)
            return True
        except CorruptImageError:
            return False<commit_msg>Adds another possible exception to is_valid_image<commit_after>'''
Wand (>=v0.3.0) engine for Sorl-thumbnail
'''

from wand.image import Image
from wand.exceptions import CorruptImageError, MissingDelegateError
from sorl.thumbnail.engines.base import EngineBase


class Engine(EngineBase):
    def get_image(self, source):
        return Image(blob=source.read())

    def get_image_size(self, image):
        return image.size

    def is_valid_image(self, raw_data):
        '''
        Wand library makes sure when opening any image that is fine, when
        the image is corrupted raises an exception.
        '''

        try:
            Image(blob=raw_data)
            return True
        except (CorruptImageError, MissingDelegateError):
            return False
{'fraction_non_alphanumeric': 0.07934336525307797, 'fraction_numerical': 0.004103967168262654, 'mean_word_length': 2.7512820512820513, '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': '4723579', 'n_tokens_mistral': 412, 'n_tokens_neox': 399, 'n_words': 126}