Пример #1
0
    def __call__(self, environ, start_response):
        path = environ["PATH_INFO"]

        davres = None
        if environ["wsgidav.provider"]:
            davres = environ["wsgidav.provider"].getResourceInst(path, environ)

        if environ["REQUEST_METHOD"] in (
                "GET", "HEAD") and davres and davres.isCollection:

            # if "mozilla" not in environ.get("HTTP_USER_AGENT").lower():
            #     # issue 14: Nautilus sends GET on collections
            #     # http://code.google.com/p/wsgidav/issues/detail?id=14
            #     util.status("Directory browsing disabled for agent '{}'"
            #                 .format(environ.get("HTTP_USER_AGENT")))
            #     self._fail(HTTP_NOT_IMPLEMENTED)
            #     return self._application(environ, start_response)

            if util.getContentLength(environ) != 0:
                self._fail(HTTP_MEDIATYPE_NOT_SUPPORTED,
                           "The server does not handle any body content.")

            if environ["REQUEST_METHOD"] == "HEAD":
                return util.sendStatusResponse(environ, start_response,
                                               HTTP_OK)

            # Support DAV mount (http://www.ietf.org/rfc/rfc4709.txt)
            dirConfig = environ["wsgidav.config"].get("dir_browser", {})
            if dirConfig.get("davmount") and "davmount" in environ.get(
                    "QUERY_STRING", ""):
                #                collectionUrl = davres.getHref()
                collectionUrl = util.makeCompleteUrl(environ)
                collectionUrl = collectionUrl.split("?")[0]
                res = """
                    <dm:mount xmlns:dm="http://purl.org/NET/webdav/mount">
                        <dm:url>{}</dm:url>
                    </dm:mount>""".format(collectionUrl)
                # TODO: support <dm:open>%s</dm:open>

                start_response("200 OK", [
                    ("Content-Type", "application/davmount+xml"),
                    ("Content-Length", str(len(res))),
                    ("Cache-Control", "private"),
                    ("Date", util.getRfc1123Time()),
                ])
                return [res]

            # Profile calls
#            if True:
#                from cProfile import Profile
#                profile = Profile()
#                profile.runcall(self._listDirectory, environ, start_response)
#                # sort: 0:"calls",1:"time", 2: "cumulative"
#                profile.print_stats(sort=2)
            return self._listDirectory(davres, environ, start_response)

        return self._application(environ, start_response)
Пример #2
0
    def __call__(self, environ, start_response):
        path = environ["PATH_INFO"]

        davres = None
        if environ["wsgidav.provider"]:
            davres = environ["wsgidav.provider"].getResourceInst(path, environ)

        if environ["REQUEST_METHOD"] in (
                "GET", "HEAD") and davres and davres.isCollection:

            if util.getContentLength(environ) != 0:
                self._fail(HTTP_MEDIATYPE_NOT_SUPPORTED,
                           "The server does not handle any body content.")

            if environ["REQUEST_METHOD"] == "HEAD":
                return util.sendStatusResponse(environ, start_response,
                                               HTTP_OK)

            # Support DAV mount (http://www.ietf.org/rfc/rfc4709.txt)
            dirConfig = environ["wsgidav.config"].get("dir_browser", {})
            if dirConfig.get("davmount") and "davmount" in environ.get(
                    "QUERY_STRING", ""):
                collectionUrl = util.makeCompleteUrl(environ)
                collectionUrl = collectionUrl.split("?", 1)[0]
                res = """
                    <dm:mount xmlns:dm="http://purl.org/NET/webdav/mount">
                        <dm:url>{}</dm:url>
                    </dm:mount>""".format(collectionUrl)
                # TODO: support <dm:open>%s</dm:open>

                start_response("200 OK", [
                    ("Content-Type", "application/davmount+xml"),
                    ("Content-Length", str(len(res))),
                    ("Cache-Control", "private"),
                    ("Date", util.getRfc1123Time()),
                ])
                return [res]

            context = self._get_context(environ, davres)

            res = self.template.render(**context)
            res = compat.to_bytes(res)
            start_response("200 OK", [
                ("Content-Type", "text/html"),
                ("Content-Length", str(len(res))),
                ("Cache-Control", "private"),
                ("Date", util.getRfc1123Time()),
            ])
            return [res]

        return self.next_app(environ, start_response)