'Translate a web-path to a local filesystem path
Odd path elements (e.g., ones that contain local filesystem path
separators) are stripped.'

def translate_path(self, path, include_prefix=True):

    def fixpath(p):
        o = []
        skip = 0
        while True:
            (p, tail) = posixpath.split(p)
            if ((p in ('/', '')) and (tail == '')):
                break
            if (tail in ('', '.', os.path.curdir, os.path.pardir)):
                continue
            if (os.path.sep in tail):
                continue
            if (os.path.altsep and (os.path.altsep in tail)):
                continue
            if (os.path.splitdrive(tail)[0] != ''):
                continue
            if (tail == '..'):
                skip += 1
                continue
            if skip:
                skip -= 1
                continue
            o.append(tail)
        o.reverse()
        return o
    if ('?' in path):
        path = path[:path.index('?')]
    if ('#' in path):
        path = path[:path.index('#')]
    path = fixpath(path)
    if path:
        path = os.path.join(*path)
    else:
        path = ''
    if include_prefix:
        path = os.path.join(os.path.abspath(self.args['root']), path)
    return path
