Exemplo n.º 1
0
def respond(depot, request, response):
        path = request.path_info.strip("/")
        if path == "":
                path = "index.shtml"
        elif path.split("/")[0] == "feed":
                response.headers.update({ "Expires": 0, "Pragma": "no-cache",
                    "Cache-Control": "no-cache, no-transform, must-revalidate"
                    })
                return feed(depot, request, response)

        if not path.endswith(".shtml"):
                spath = urllib.unquote(path)
                fname = os.path.join(depot.web_root, spath)
                if not os.path.normpath(fname).startswith(
                    os.path.normpath(depot.web_root)):
                        # Ignore requests for files outside of the web root.
                        return __handle_error(path, httplib.NOT_FOUND)
                else:
                        return cherrypy.lib.static.serve_file(os.path.join(
                            depot.web_root, spath))

        try:
                response.headers.update({ "Expires": 0, "Pragma": "no-cache",
                    "Cache-Control": "no-cache, no-transform, must-revalidate"
                    })
                return __render_template(depot, request, path)
        except sae.VersionException, e:
                # The user shouldn't see why we can't render a template, but
                # the reason should be logged (cleanly).
                cherrypy.log("Template '%(path)s' is incompatible with current "
                    "server api: %(error)s" % { "path": path,
                    "error": str(e) })
                cherrypy.log("Ensure that the correct --content-root has been "
                    "provided to pkg.depotd.")
                return __handle_error(request.path_info, httplib.NOT_FOUND)
Exemplo n.º 2
0
Arquivo: face.py Projeto: aszeszo/test
def respond(depot, request, response, pub, http_depot=None):
        """'http_depot' if set should be the resource that points to the top
        level of repository being served (referred to as the repo_prefix in
        depot_index.py)"""
        path = request.path_info.strip("/")
        if pub and os.path.exists(os.path.join(depot.web_root, pub)):
                # If an item exists under the web root
                # with this name, it isn't a publisher
                # prefix.
                pub = None
        elif pub and pub not in depot.repo.publishers:
                raise cherrypy.NotFound()

        if pub:
                # Strip publisher from path as it can't be used to determine
                # resource locations.
                path = path.replace(pub, "").strip("/")
        else:
                # No publisher specified in request, so assume default.
                pub = depot.repo.cfg.get_property("publisher", "prefix")
                if not pub:
                        pub = None

        if path == "":
                path = "index.shtml"
        elif path.split("/")[0] == "feed":
                response.headers.update({ "Expires": 0, "Pragma": "no-cache",
                    "Cache-Control": "no-cache, no-transform, must-revalidate"
                    })
                return feed(depot, request, response, pub)

        if not path.endswith(".shtml"):
                spath = urllib.unquote(path)
                fname = os.path.join(depot.web_root, spath)
                if not os.path.normpath(fname).startswith(
                    os.path.normpath(depot.web_root)):
                        # Ignore requests for files outside of the web root.
                        return __handle_error(path, httplib.NOT_FOUND)
                else:
                        return cherrypy.lib.static.serve_file(os.path.join(
                            depot.web_root, spath))

        try:
                response.headers.update({ "Expires": 0, "Pragma": "no-cache",
                    "Cache-Control": "no-cache, no-transform, must-revalidate"
                    })
                return __render_template(depot, request, path, pub, http_depot)
        except sae.VersionException, e:
                # The user shouldn't see why we can't render a template, but
                # the reason should be logged (cleanly).
                cherrypy.log("Template '%(path)s' is incompatible with current "
                    "server api: %(error)s" % { "path": path,
                    "error": str(e) })
                cherrypy.log("Ensure that the correct --content-root has been "
                    "provided to pkg.depotd.")
                return __handle_error(request.path_info, httplib.NOT_FOUND)
Exemplo n.º 3
0
def respond(depot, request, response):
    path = request.path_info.strip("/")
    if path == "":
        path = "index.shtml"
    elif path.split("/")[0] == "feed":
        response.headers.update({
            "Expires":
            0,
            "Pragma":
            "no-cache",
            "Cache-Control":
            "no-cache, no-transform, must-revalidate"
        })
        return feed(depot, request, response)

    if not path.endswith(".shtml"):
        spath = urllib.unquote(path)
        fname = os.path.join(depot.web_root, spath)
        if not os.path.normpath(fname).startswith(
                os.path.normpath(depot.web_root)):
            # Ignore requests for files outside of the web root.
            return __handle_error(path, httplib.NOT_FOUND)
        else:
            return cherrypy.lib.static.serve_file(
                os.path.join(depot.web_root, spath))

    try:
        response.headers.update({
            "Expires":
            0,
            "Pragma":
            "no-cache",
            "Cache-Control":
            "no-cache, no-transform, must-revalidate"
        })
        return __render_template(depot, request, path)
    except sae.VersionException, e:
        # The user shouldn't see why we can't render a template, but
        # the reason should be logged (cleanly).
        cherrypy.log("Template '%(path)s' is incompatible with current "
                     "server api: %(error)s" % {
                         "path": path,
                         "error": str(e)
                     })
        cherrypy.log("Ensure that the correct --content-root has been "
                     "provided to pkg.depotd.")
        return __handle_error(request.path_info, httplib.NOT_FOUND)
Exemplo n.º 4
0
def respond(scfg, rcfg, request, response, *tokens, **params):
    path = request.path_info.strip("/")
    if path == "":
        path = "index.shtml"
    elif path.split("/")[0] == "feed":
        return feed(scfg, rcfg, request, response)

    if not path.endswith(".shtml"):
        spath = urllib.unquote(path)
        fname = os.path.join(scfg.web_root, spath)
        if not os.path.normpath(fname).startswith(
                os.path.normpath(scfg.web_root)):
            # Ignore requests for files outside of the web root.
            return __handle_error(request, path, httplib.NOT_FOUND)
        else:
            return cherrypy.lib.static.serve_file(
                os.path.join(scfg.web_root, spath))

    try:
        return __render_template(request, scfg, rcfg, path)
    except IOError, e:
        return __handle_error(request, path, httplib.INTERNAL_SERVER_ERROR)
Exemplo n.º 5
0
def respond(scfg, rcfg, request, response, *tokens, **params):
        path = request.path_info.strip("/")
        if path == "":
                path = "index.shtml"
        elif path.split("/")[0] == "feed":
                return feed(scfg, rcfg, request, response)

        if not path.endswith(".shtml"):
                spath = urllib.unquote(path)
                fname = os.path.join(scfg.web_root, spath)
                if not os.path.normpath(fname).startswith(os.path.normpath(
                    scfg.web_root)):
                        # Ignore requests for files outside of the web root.
                        return __handle_error(request, path, httplib.NOT_FOUND)
                else:
                        return cherrypy.lib.static.serve_file(os.path.join(
                            scfg.web_root, spath))

        try:
                return __render_template(request, scfg, rcfg, path)
        except IOError, e:
                return __handle_error(request, path,
                    httplib.INTERNAL_SERVER_ERROR)
Exemplo n.º 6
0
def respond(depot, request, response, pub, http_depot=None):
    """'http_depot' if set should be the resource that points to the top
        level of repository being served (referred to as the repo_prefix in
        depot_index.py)"""
    path = request.path_info.strip("/")
    if pub and os.path.exists(os.path.join(depot.web_root, pub)):
        # If an item exists under the web root
        # with this name, it isn't a publisher
        # prefix.
        pub = None
    elif pub and pub not in depot.repo.publishers:
        raise cherrypy.NotFound()

    if pub:
        # Strip publisher from path as it can't be used to determine
        # resource locations.
        path = path.replace(pub, "").strip("/")
    else:
        # No publisher specified in request, so assume default.
        pub = depot.repo.cfg.get_property("publisher", "prefix")
        if not pub:
            pub = None

    if path == "":
        path = "index.shtml"
    elif path.split("/")[0] == "feed":
        response.headers.update({
            "Expires":
            0,
            "Pragma":
            "no-cache",
            "Cache-Control":
            "no-cache, no-transform, must-revalidate"
        })
        return feed(depot, request, response, pub)

    if not path.endswith(".shtml"):
        spath = urllib.unquote(path)
        fname = os.path.join(depot.web_root, spath)
        if not os.path.normpath(fname).startswith(
                os.path.normpath(depot.web_root)):
            # Ignore requests for files outside of the web root.
            return __handle_error(path, httplib.NOT_FOUND)
        else:
            return cherrypy.lib.static.serve_file(
                os.path.join(depot.web_root, spath))

    try:
        response.headers.update({
            "Expires":
            0,
            "Pragma":
            "no-cache",
            "Cache-Control":
            "no-cache, no-transform, must-revalidate"
        })
        return __render_template(depot, request, path, pub, http_depot)
    except sae.VersionException as e:
        # The user shouldn't see why we can't render a template, but
        # the reason should be logged (cleanly).
        cherrypy.log("Template '{path}' is incompatible with current "
                     "server api: {error}".format(path=path, error=str(e)))
        cherrypy.log("Ensure that the correct --content-root has been "
                     "provided to pkg.depotd.")
        return __handle_error(request.path_info, httplib.NOT_FOUND)
    except IOError as e:
        return __handle_error(path, httplib.INTERNAL_SERVER_ERROR)
    except mako.exceptions.TemplateLookupException as e:
        # The above exception indicates that mako could not locate the
        # template (in most cases, Mako doesn't seem to always clearly
        # differentiate).
        return __handle_error(path, httplib.NOT_FOUND)
    except sae.RedirectException as e:
        raise cherrypy.HTTPRedirect(e.data)
    except:
        return __handle_error(path, httplib.INTERNAL_SERVER_ERROR)