# Path: webdiff/diff.py
# def get_thin_dict(diff):
# def get_thick_dict(diff):
# def get_thin_list(diffs, thick_idx=None):
# def no_changes(diff):
# def is_image_diff(diff):
#     def is_image(path):
# def find_diff_index(diffs, side, path):
#     def norm(p):
# 
# 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/argparser.py
# class UsageError(Exception):
# USAGE = '''Usage: webdiff <left_dir> <right_dir>
#        webdiff <left_file> <right_file>
#        webdiff https://github.com/<owner>/<repo>/pull/<num>
# 
# Or run "git webdiff" from a git repository.
# '''
# PULL_REQUEST_RE = re.compile(
#     r'http[s]://(?:www.)?github.com/([^/]+)/([^/]+)/pull/([0-9]+)(?:/.*)?'
# )
# PULL_REQUEST_NUM_RE = re.compile(r'^#([0-9]+)$')
# def parse(args, version=None):
# def _shim_for_file_diff(a_file, b_file):
# def diff_for_args(args):


from binaryornot.check import is_binary
from threading import Timer
from flask import (
    Flask,
    render_template,
    send_from_directory,
    send_file,
    request,
    jsonify,
    Response,
)
from webdiff import diff
from webdiff import util
from webdiff import argparser
import logging
import mimetypes
import os
import platform
import requests
import socket
import sys
import time
import webbrowser
    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501
    except util.ImageMagickError as e:
        return 'ImageMagick error %s' % e, 501
    return send_file(dilated_image)


@app.route("/pdiffbbox/<int:idx>")
def get_pdiff_bbox(idx):
    idx = int(idx)
    d = DIFF[idx]
    try:
        _, pdiff_image = util.generate_pdiff_image(d.a_path, d.b_path)
        bbox = util.get_pdiff_bbox(pdiff_image)
    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501
    except util.ImageMagickError as e:
        return 'ImageMagick error %s' % e, 501
    return jsonify(bbox)


# Show the first diff by default
@app.route("/")
def index():
    return file_diff('0')


@app.route("/<int:idx>")
def file_diff(idx):
    idx = int(idx)

# Path: webdiff/diff.py
# def get_thin_dict(diff):
# def get_thick_dict(diff):
# def get_thin_list(diffs, thick_idx=None):
# def no_changes(diff):
# def is_image_diff(diff):
#     def is_image(path):
# def find_diff_index(diffs, side, path):
#     def norm(p):
# 
# 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/argparser.py
# class UsageError(Exception):
# USAGE = '''Usage: webdiff <left_dir> <right_dir>
#        webdiff <left_file> <right_file>
#        webdiff https://github.com/<owner>/<repo>/pull/<num>
# 
# Or run "git webdiff" from a git repository.
# '''
# PULL_REQUEST_RE = re.compile(
#     r'http[s]://(?:www.)?github.com/([^/]+)/([^/]+)/pull/([0-9]+)(?:/.*)?'
# )
# PULL_REQUEST_NUM_RE = re.compile(r'^#([0-9]+)$')
# def parse(args, version=None):
# def _shim_for_file_diff(a_file, b_file):
# def diff_for_args(args):


# Path: webdiff/app.py
from binaryornot.check import is_binary
from threading import Timer
from flask import (
    Flask,
    render_template,
    send_from_directory,
    send_file,
    request,
    jsonify,
    Response,
)
from webdiff import diff
from webdiff import util
from webdiff import argparser
import logging
import mimetypes
import os
import platform
import requests
import socket
import sys
import time
import webbrowser

    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501
    except util.ImageMagickError as e:
        return 'ImageMagick error %s' % e, 501
    return send_file(dilated_image)


@app.route("/pdiffbbox/<int:idx>")
def get_pdiff_bbox(idx):
    idx = int(idx)
    d = DIFF[idx]
    try:
        _, pdiff_image = util.generate_pdiff_image(d.a_path, d.b_path)
        bbox = util.get_pdiff_bbox(pdiff_image)
    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501
    except util.ImageMagickError as e:
        return 'ImageMagick error %s' % e, 501
    return jsonify(bbox)


# Show the first diff by default
@app.route("/")
def index():
    return file_diff('0')


@app.route("/<int:idx>")
def file_diff(idx):
    idx = int(idx)

    pairs = diff.get_thin_list(DIFF)