@@ -0,0 +1,3312 @@
+#!/usr/bin/python%0A# -*- coding: utf-8 -*-%0A%0Afrom __future__ import print_function%0Aimport BaseHTTPServer%0Aimport os%0Aimport os.path%0A%0A# A simple dictionary of file name extensions to MIME types. The empty string%0A# entry is used as the default when no extension was given or if the extension%0A# has no entry in this dictionary.%0AMIME_TYPE_MAP = %7B'': 'application/octet-stream',%0A                 'html': 'text/html',%0A                 'css': 'text/css',%0A                 'png': 'image/png',%0A                 'js': 'application/javascript'%0A                 %7D%0A%0A%0Aclass SkPDiffHandler(BaseHTTPServer.BaseHTTPRequestHandler):%0A    def send_file(self, file_path):%0A        # Grab the extension if there is one%0A        extension = os.path.splitext(file_path)%5B1%5D%0A        if len(extension) %3E= 1:%0A            extension = extension%5B1:%5D%0A%0A        # Determine the MIME type of the file from its extension%0A        mime_type = MIME_TYPE_MAP.get(extension, MIME_TYPE_MAP%5B''%5D)%0A%0A        # Open the file and send it over HTTP%0A        sending_file = open(file_path, 'rb')%0A        self.send_response(200)%0A        self.send_header('Content-type', mime_type)%0A        self.end_headers()%0A        self.wfile.write(sending_file.read())%0A        sending_file.close()%0A%0A    def serve_if_in_dir(self, dir_path, file_path):%0A        # Determine if the file exists relative to the given dir_path AND exists%0A        # under the dir_path. This is to prevent accidentally serving files%0A        # outside the directory intended using symlinks, or '../'.%0A        real_path = os.path.normpath(os.path.join(dir_path, file_path))%0A        print(repr(real_path))%0A        if os.path.commonprefix(%5Breal_path, dir_path%5D) == dir_path:%0A            if os.path.isfile(real_path):%0A                self.send_file(real_path)%0A                return True%0A        return False%0A%0A    def do_GET(self):%0A        # Grab the script path because that is where all the static assets are%0A        script_dir = os.path.dirname(os.path.abspath(__file__))%0A%0A        # Simple rewrite rule of the root path to 'viewer.html'%0A        if self.path == '' or self.path == '/':%0A            self.path = '/viewer.html'%0A%0A        # The %5B1:%5D chops off the leading '/'%0A        file_path = self.path%5B1:%5D%0A%0A        # Attempt to send static asset files first%0A        if self.serve_if_in_dir(script_dir, file_path):%0A            return%0A%0A        # WARNING: Using the root is a big ol' hack. Incredibly insecure. Only%0A        # allow serving to localhost unless you want the network to be able to%0A        # see ALL of the files you can.%0A        # Attempt to send gm image files%0A        if self.serve_if_in_dir('/', file_path):%0A            return%0A%0A        # If no file to send was found, just give the standard 404%0A        self.send_error(404)%0A%0A%0Adef main():%0A    # Do not bind to interfaces other than localhost because the server will%0A    # attempt to serve files relative to the root directory as a last resort%0A    # before 404ing. This means all of your files can be accessed from this%0A    # server, so DO NOT let this server listen to anything but localhost.%0A    server_address = ('127.0.0.1', 8080)%0A    http_server = BaseHTTPServer.HTTPServer(server_address, SkPDiffHandler)%0A    print('Navigate thine browser to: %7B%7D:%7B%7D'.format(*server_address))%0A    http_server.serve_forever()%0A%0Aif __name__ == '__main__':%0A    main()%0A

add basic HTTP server for viewing skpdiff results