Exemple #1
0
    def render_GET(self, ctx):
        req = IRequest(ctx)
        # This is where all of the directory-related ?t=* code goes.
        t = get_arg(req, "t", "").strip()

        # t=info contains variable ophandles, t=rename-form contains the name
        # of the child being renamed. Neither is allowed an ETag.
        FIXED_OUTPUT_TYPES =  ["", "json", "uri", "readonly-uri"]
        if not self.node.is_mutable() and t in FIXED_OUTPUT_TYPES:
            si = self.node.get_storage_index()
            if si and req.setETag('DIR:%s-%s' % (base32.b2a(si), t or "")):
                return ""

        if not t:
            # render the directory as HTML, using the docFactory and Nevow's
            # whole templating thing.
            return DirectoryAsHTML(self.node,
                                   self.client.mutable_file_default)

        if t == "json":
            return DirectoryJSONMetadata(ctx, self.node)
        if t == "info":
            return MoreInfo(self.node)
        if t == "uri":
            return DirectoryURI(ctx, self.node)
        if t == "readonly-uri":
            return DirectoryReadonlyURI(ctx, self.node)
        if t == 'rename-form':
            return RenameForm(self.node)

        raise WebError("GET directory: bad t=%s" % t)
Exemple #2
0
    def render_GET(self, ctx):
        req = IRequest(ctx)
        t = get_arg(req, "t", "").strip()

        # t=info contains variable ophandles, so is not allowed an ETag.
        FIXED_OUTPUT_TYPES = ["", "json", "uri", "readonly-uri"]
        if not self.node.is_mutable() and t in FIXED_OUTPUT_TYPES:
            # if the client already has the ETag then we can
            # short-circuit the whole process.
            si = self.node.get_storage_index()
            if si and req.setETag('%s-%s' % (base32.b2a(si), t or "")):
                return ""

        if not t:
            # just get the contents
            # the filename arrives as part of the URL or in a form input
            # element, and will be sent back in a Content-Disposition header.
            # Different browsers use various character sets for this name,
            # sometimes depending upon how language environment is
            # configured. Firefox sends the equivalent of
            # urllib.quote(name.encode("utf-8")), while IE7 sometimes does
            # latin-1. Browsers cannot agree on how to interpret the name
            # they see in the Content-Disposition header either, despite some
            # 11-year old standards (RFC2231) that explain how to do it
            # properly. So we assume that at least the browser will agree
            # with itself, and echo back the same bytes that we were given.
            filename = get_arg(req, "filename", self.name) or "unknown"
            d = self.node.get_best_readable_version()
            d.addCallback(lambda dn: FileDownloader(dn, filename))
            return d
        if t == "json":
            # We do this to make sure that fields like size and
            # mutable-type (which depend on the file on the grid and not
            # just on the cap) are filled in. The latter gets used in
            # tests, in particular.
            #
            # TODO: Make it so that the servermap knows how to update in
            # a mode specifically designed to fill in these fields, and
            # then update it in that mode.
            if self.node.is_mutable():
                d = self.node.get_servermap(MODE_READ)
            else:
                d = defer.succeed(None)
            if self.parentnode and self.name:
                d.addCallback(lambda ignored: self.parentnode.get_metadata_for(
                    self.name))
            else:
                d.addCallback(lambda ignored: None)
            d.addCallback(lambda md: FileJSONMetadata(ctx, self.node, md))
            return d
        if t == "info":
            return MoreInfo(self.node)
        if t == "uri":
            return FileURI(ctx, self.node)
        if t == "readonly-uri":
            return FileReadOnlyURI(ctx, self.node)
        raise WebError("GET file: bad t=%s" % t)
Exemple #3
0
 def render_GET(self, ctx):
     req = IRequest(ctx)
     t = get_arg(req, "t", "").strip()
     if t == "info":
         return MoreInfo(self.node)
     if t == "json":
         is_parent_known_immutable = self.parentnode and not self.parentnode.is_mutable()
         if self.parentnode and self.name:
             d = self.parentnode.get_metadata_for(self.name)
         else:
             d = defer.succeed(None)
         d.addCallback(lambda md: UnknownJSONMetadata(ctx, self.node, md, is_parent_known_immutable))
         return d
     raise WebError("GET unknown URI type: can only do t=info and t=json, not t=%s.\n"
                    "Using a webapi server that supports a later version of Tahoe "
                    "may help." % t)
Exemple #4
0
    def render_GET(self, ctx):
        req = IRequest(ctx)
        # This is where all of the directory-related ?t=* code goes.
        t = get_arg(req, "t", "").strip()
        if not t:
            # render the directory as HTML, using the docFactory and Nevow's
            # whole templating thing.
            return DirectoryAsHTML(self.node)

        if t == "json":
            return DirectoryJSONMetadata(ctx, self.node)
        if t == "info":
            return MoreInfo(self.node)
        if t == "uri":
            return DirectoryURI(ctx, self.node)
        if t == "readonly-uri":
            return DirectoryReadonlyURI(ctx, self.node)
        if t == 'rename-form':
            return RenameForm(self.node)

        raise WebError("GET directory: bad t=%s" % t)
Exemple #5
0
 def render_GET(self, ctx):
     req = IRequest(ctx)
     t = get_arg(req, "t", "").strip()
     if not t:
         # just get the contents
         # the filename arrives as part of the URL or in a form input
         # element, and will be sent back in a Content-Disposition header.
         # Different browsers use various character sets for this name,
         # sometimes depending upon how language environment is
         # configured. Firefox sends the equivalent of
         # urllib.quote(name.encode("utf-8")), while IE7 sometimes does
         # latin-1. Browsers cannot agree on how to interpret the name
         # they see in the Content-Disposition header either, despite some
         # 11-year old standards (RFC2231) that explain how to do it
         # properly. So we assume that at least the browser will agree
         # with itself, and echo back the same bytes that we were given.
         filename = get_arg(req, "filename", self.name) or "unknown"
         if self.node.is_mutable():
             # some day: d = self.node.get_best_version()
             d = makeMutableDownloadable(self.node)
         else:
             d = defer.succeed(self.node)
         d.addCallback(lambda dn: FileDownloader(dn, filename))
         return d
     if t == "json":
         if self.parentnode and self.name:
             d = self.parentnode.get_metadata_for(self.name)
         else:
             d = defer.succeed(None)
         d.addCallback(lambda md: FileJSONMetadata(ctx, self.node, md))
         return d
     if t == "info":
         return MoreInfo(self.node)
     if t == "uri":
         return FileURI(ctx, self.node)
     if t == "readonly-uri":
         return FileReadOnlyURI(ctx, self.node)
     raise WebError("GET file: bad t=%s" % t)