def static_file(filename, root=MEDIA_ROOT):
    if filename is None:
        raise Forbidden("You must specify a file you'd like to access.")

    # Strip the '/' from the beginning/end.
    valid_path = filename.strip('/')

    # Kill off any character trying to work their way up the filesystem.
    valid_path = valid_path.replace('//', '/').replace('/./', '/').replace('/../', '/')

    desired_path = os.path.join(root, valid_path)

    if not os.path.exists(desired_path):
        raise NotFound("File does not exist.")

    if not os.access(desired_path, os.R_OK):
        raise Forbidden("You do not have permission to access this file.")

    ct = str(content_type(desired_path))

    # Do the text types as a non-binary read.
    if ct.startswith('text') or ct.endswith('xml') or ct.endswith('json'):
        return open(desired_path, 'r').read()

    # Fall back to binary for everything else.
    return open(desired_path, 'rb').read()


# Static file handler
Fetches a static file from the filesystem, relative to either the given
dataset/ETHPy150Open toastdriven/itty/itty.py/static_file