@route("/view/:path#.+#")
def view(path):
    """
    Handles the viewing of a file
    """

    if "sorted_by" in request.GET.dict:
        sorted_by = request.GET.dict["sorted_by"][0]
    else:
        sorted_by = None

    reverse = "reverse" in request.GET and (
        int(request.GET.dict["reverse"][0]) == 1)

    document_root = os.path.expanduser(config.get(
            "markupserve", "document_root"))

    absolute_path = os.path.abspath(document_root + "/" + path)

    if not os.path.exists(absolute_path):
        abort(404, "The path '%s' couldn't be found" % (absolute_path))

    if os.path.isdir(absolute_path):
        if path != "/":
            parent_path = os.path.abspath(absolute_path + "/" +  os.pardir)
        else:
            parent_path = None

        markupserve_dir_config_file = os.path.join(absolute_path,
                                                   DIR_CONFIG_FILE_NAME)

        if os.path.exists(markupserve_dir_config_file):
            dir_config = ConfigParser.ConfigParser()
            parsed_files = dir_config.read([markupserve_dir_config_file])

            if len(parsed_files) != 1:
                abort(500, "Can't parse dir config file '%s'" %
                      (markupserve_dir_config_file))

            try:
                dir_style = dir_config.get("style", "name")
            except ConfigParser.Error, e:
                abort(500, "Can't find option ('style', 'name') in directory "
                      "config")

            if dir_style == "calendar":
                return view_calendar(absolute_path, parent_path, document_root,
                                     dir_config)

        return view_dir(absolute_path, parent_path, document_root,
                        sorted_by, reverse)
    else:
        return view_file(absolute_path, document_root)
dataset/ETHPy150Open alexras/markupserve/markupserve.py/view/original