Translates a path for a static file request. The server base path
           could be different from our cwd.

        Parameters
        ----------
        path : string
            The path.

        Returns
        -------
        The absolute file path denoted by the original path.

def translate_path(self, orig_path):
        """Translates a path for a static file request. The server base path
           could be different from our cwd.

        Parameters
        ----------
        path : string
            The path.

        Returns
        -------
        The absolute file path denoted by the original path.
        """
        init_path = orig_path
        orig_path = urlparse.urlparse(orig_path)[2]
        needs_redirect = False
        is_folder = len(orig_path) <= 1 or orig_path[-1] == '/'
        orig_path = posixpath.normpath(urlparse_unquote(orig_path))
        if is_folder:
            orig_path += '/'
        path = None
        for (name, fm) in self.server._folder_masks:
            if not orig_path.startswith(name):
                continue
            cur_base = os.path.abspath(os.path.join(self.server.base_path, fm))
            path = cur_base
            words = orig_path[len(name):].split('/')
            words = filter(None, words)
            for word in words:
                _drive, word = os.path.splitdrive(word)
                _head, word = os.path.split(word)
                if word in (os.curdir, os.pardir):
                    continue
                if word.startswith('.'):  # don't ever allow any hidden files
                    raise PreventDefaultResponse(404, "File not found")
                path = os.path.join(path, word)
            # make path absolute and check if it exists
            path = os.path.abspath(path)
            if os.path.exists(path):
                break
        # if pass is still None here the file cannot be found
        if path is None:
            # try proxies
            for (name, pxy) in self.server._folder_proxys:
                if not orig_path.startswith(name):
                    continue
                remain = orig_path[len(name) - 1:]
                proxy = urlparse.urlparse(pxy)
                reala = urlparse.urlparse(init_path)
                pxya = urlparse.urlunparse((
                    proxy[0],  # scheme
                    proxy[1],  # netloc
                    "{0}{1}".format(proxy[2], remain),  # path
                    reala[3],  # params
                    reala[4],  # query
                    reala[5],  # fragment
                ))
                self.send_to_proxy(pxya)  # raises PreventDefaultResponse
            msg("no matching folder alias: {0}".format(orig_path))
            raise PreventDefaultResponse(404, "File not found")
        if os.path.isdir(path):
            if not is_folder:
                needs_redirect = True
            else:
                for orig_index in ["index.html", "index.htm"]:
                    index = os.path.join(path, orig_index)
                    if os.path.isfile(index):
                        path = index
                        break
        if os.path.isdir(path):
            # no black-/white-list for directories
            is_white = True
        else:
            # match agains black- and white-list
            is_white = len(self.server._pattern_white) == 0
            for pattern in self.server._pattern_white:
                if fnmatch.fnmatch(path, pattern):
                    is_white = True
                    break
            for pattern in self.server._pattern_black:
                if fnmatch.fnmatch(path, pattern):
                    is_white = False
                    break
        if not is_white:
            raise PreventDefaultResponse(404, "File not found")
        # make sure to not accept any trickery to get away from the base path
        if not path.startswith(cur_base):
            raise ValueError("WARNING: attempt to access {0}".format(path))
        # favicon handling
        if self.server.favicon_everywhere and \
                os.path.basename(path) == 'favicon.ico' and \
                not os.path.exists(path):
            for (name, fm) in self.server._folder_masks:
                fav_base = os.path.abspath(
                    os.path.join(self.server.base_path, fm))
                favicon = os.path.join(fav_base, 'favicon.ico')
                if os.path.exists(favicon):
                    path = favicon
                    break
                if self.server.favicon_fallback is not None and \
                        os.path.exists(self.server.favicon_fallback):
                    path = os.path.join(
                        self.server.base_path, self.server.favicon_fallback)
                    break
        # redirect improper index requests
        if needs_redirect:
            self.send_response(301, "Use index page with slash")
            location = urlparse.urlunparse(tuple([
                seg if ix != 2 else seg + '/'
                for (ix, seg) in enumerate(urlparse.urlparse(init_path))
            ]))
            self.send_header("Location", location)
            self.end_headers()
            raise PreventDefaultResponse()
        # handle ETag caching
        if self.request_version >= "HTTP/1.1" and os.path.isfile(path):
            e_tag = None
            with open(path, 'rb') as input_f:
                e_tag = "{0:x}".format(zlib.crc32(input_f.read()) & 0xFFFFFFFF)
                thread_local.size = input_f.tell()
            if e_tag is not None:
                match = _getheader(self.headers, 'if-none-match')
                if match is not None:
                    if self.check_cache(e_tag, match):
                        raise PreventDefaultResponse()
                self.send_header("ETag", e_tag, end_header=True)
                self.send_header("Cache-Control",
                                 "max-age={0}".format(self.server.max_age),
                                 end_header=True)
        return path