Exemple #1
0
 def testTemporary(self):
     """
     Verify the "temporary" parameter sets the appropriate response code
     """
     req = http.RedirectResponse("http://example.com/", temporary=False)
     self.assertEquals(req.code, responsecode.MOVED_PERMANENTLY)
     req = http.RedirectResponse("http://example.com/", temporary=True)
     self.assertEquals(req.code, responsecode.TEMPORARY_REDIRECT)
Exemple #2
0
    def http_GET(self, request):
        if self.addSlash and request.prepath[-1] != '':
            # If this is a directory-ish resource...
            return http.RedirectResponse(
                request.unparseURL(path=request.path + '/'))

        return super(Resource, self).http_GET(request)
Exemple #3
0
    def render(self, req):
        """You know what you doing."""
        if not self.fp.exists():
            return responsecode.NOT_FOUND

        if self.fp.isdir():
            if req.path[-1] != "/":
                # Redirect to include trailing '/' in URI
                return http.RedirectResponse(
                    req.unparseURL(path=req.path + '/'))
            else:
                ifp = self.fp.childSearchPreauth(*self.indexNames)
                if ifp:
                    # Render from the index file
                    standin = self.createSimilarFile(ifp.path)
                else:
                    # Directory listing is in twistedcaldav.extensions
                    standin = Data(
                        "\n".join(["Directory: " + str(req.path), "---"] + [
                            x.basename() + ("/" if x.isdir() else "")
                            for x in self.fp.children()
                        ]), "text/plain")
                return standin.render(req)

        try:
            f = self.fp.open()
        except IOError, e:
            import errno
            if e[0] == errno.EACCES:
                return responsecode.FORBIDDEN
            elif e[0] == errno.ENOENT:
                return responsecode.NOT_FOUND
            else:
                raise
 def renderHTTP(self, request):
     return http.RedirectResponse(
         request.unparseURL(host=request.host, **self._kwargs))
Exemple #5
0
 def renderHTTP(self, request):
     return http.RedirectResponse(
         request.unparseURL(host=config.ServerHostName, **self._kwargs))