# Path: webdiff/util.py
# class ImageMagickNotAvailableError(Exception):
# class ImageMagickError(Exception):
# def memoize(obj):
#     def memoizer(*args, **kwargs):
# def contentHash(path):
# def are_files_identical(path1, path2):
# def image_metadata(path):
# def is_imagemagick_available():
# def generate_pdiff_image(before_path, after_path):
# def generate_dilated_pdiff_image(diff_path):
# def get_pdiff_bbox(diff_path):
#     PIPE = subprocess.PIPE


import mimetypes
import os
from webdiff import util
    '''Similar to thin_dict, but includes potentially expensive fields.'''
    d = get_thin_dict(diff)
    d.update({'is_image_diff': is_image_diff(diff), 'no_changes': no_changes(diff)})
    if d['is_image_diff']:
        if d['a']:
            d['image_a'] = util.image_metadata(diff.a_path)
        if d['b']:
            d['image_b'] = util.image_metadata(diff.b_path)
        if d['a'] and d['b']:
            try:
                d['are_same_pixels'], _ = util.generate_pdiff_image(diff.a_path, diff.b_path)
            except util.ImageMagickError:
                d['are_same_pixels'] = False
            except util.ImageMagickNotAvailableError:
                pass
    return d


def get_thin_list(diffs, thick_idx=None):
    '''Convert a list of diffs to dicts. This adds an 'idx' field.'''
    ds = [get_thin_dict(d) for d in diffs]
    if thick_idx is not None:
        ds[thick_idx] = get_thick_dict(ds[thick_idx])
    for i, d in enumerate(ds):
        d['idx'] = i
    return ds


def no_changes(diff):
    if diff.a_path and diff.b_path:

# Path: webdiff/util.py
# class ImageMagickNotAvailableError(Exception):
# class ImageMagickError(Exception):
# def memoize(obj):
#     def memoizer(*args, **kwargs):
# def contentHash(path):
# def are_files_identical(path1, path2):
# def image_metadata(path):
# def is_imagemagick_available():
# def generate_pdiff_image(before_path, after_path):
# def generate_dilated_pdiff_image(diff_path):
# def get_pdiff_bbox(diff_path):
#     PIPE = subprocess.PIPE


# Path: webdiff/diff.py
import mimetypes
import os
from webdiff import util

    '''Similar to thin_dict, but includes potentially expensive fields.'''
    d = get_thin_dict(diff)
    d.update({'is_image_diff': is_image_diff(diff), 'no_changes': no_changes(diff)})
    if d['is_image_diff']:
        if d['a']:
            d['image_a'] = util.image_metadata(diff.a_path)
        if d['b']:
            d['image_b'] = util.image_metadata(diff.b_path)
        if d['a'] and d['b']:
            try:
                d['are_same_pixels'], _ = util.generate_pdiff_image(diff.a_path, diff.b_path)
            except util.ImageMagickError:
                d['are_same_pixels'] = False
            except util.ImageMagickNotAvailableError:
                pass
    return d


def get_thin_list(diffs, thick_idx=None):
    '''Convert a list of diffs to dicts. This adds an 'idx' field.'''
    ds = [get_thin_dict(d) for d in diffs]
    if thick_idx is not None:
        ds[thick_idx] = get_thick_dict(ds[thick_idx])
    for i, d in enumerate(ds):
        d['idx'] = i
    return ds


def no_changes(diff):
    if diff.a_path and diff.b_path:

        return util.are_files_identical(diff.a_path, diff.b_path)