# 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
    if not path:
        return error('incomplete', 'Incomplete request (need path)')

    mime_type, enc = mimetypes.guess_type(path)
    if not mime_type or not mime_type.startswith('image/') or enc is not None:
        return error('wrongtype', 'Requested file of type (%s, %s) as image' % (mime_type, enc))

    idx = diff.find_diff_index(DIFF, side, path)
    if idx is None:
        return error('not found', 'Invalid path on side %s: %s' % (side, path))

    d = DIFF[idx]
    abs_path = d.a_path if side == 'a' else d.b_path

    try:
        contents = open(abs_path, mode='rb').read()
        return Response(contents, mimetype=mime_type)
    except Exception:
        return error('read-error', 'Unable to read %s' % abs_path)


@app.route("/pdiff/<int:idx>")
def get_pdiff(idx):
    idx = int(idx)
    d = DIFF[idx]
    try:
        _, pdiff_image = util.generate_pdiff_image(d.a_path, d.b_path)
        dilated_image = util.generate_dilated_pdiff_image(pdiff_image)
    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501

# 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

    if not path:
        return error('incomplete', 'Incomplete request (need path)')

    mime_type, enc = mimetypes.guess_type(path)
    if not mime_type or not mime_type.startswith('image/') or enc is not None:
        return error('wrongtype', 'Requested file of type (%s, %s) as image' % (mime_type, enc))

    idx = diff.find_diff_index(DIFF, side, path)
    if idx is None:
        return error('not found', 'Invalid path on side %s: %s' % (side, path))

    d = DIFF[idx]
    abs_path = d.a_path if side == 'a' else d.b_path

    try:
        contents = open(abs_path, mode='rb').read()
        return Response(contents, mimetype=mime_type)
    except Exception:
        return error('read-error', 'Unable to read %s' % abs_path)


@app.route("/pdiff/<int:idx>")
def get_pdiff(idx):
    idx = int(idx)
    d = DIFF[idx]
    try:
        _, pdiff_image = util.generate_pdiff_image(d.a_path, d.b_path)
        dilated_image = util.generate_dilated_pdiff_image(pdiff_image)
    except util.ImageMagickNotAvailableError:
        return 'ImageMagick is not available', 501

    except util.ImageMagickError as e: