Exemplo n.º 1
0
 def raw(self):
     if 'r' not in request.identity.access(self):
         return drink.unauthorized()
     try:
         if self.content:
             root, fname = os.path.split(self.content.filename)
             return drink.static_file(fname, root, mimetype=self.mimetype, download=self.content_name)
     except Exception, e:
         log.error('Error while handling %r', self.path)
Exemplo n.º 2
0
    def view(self, *a, **kw):
        if self.mime == "folder":
            if "index.html" in self.keys():
                return self["index.html"].view(*a, **kw)
            return drink.default_view(self, html='<div id="main_list" class="sortable" />')
        else:
            mime = get_type(self.id)

            if mime.startswith("text"):
                mime += " ; charset=utf-8"
            else:
                drink.response.headers["Content-Disposition"] = 'attachment; filename="%s"' % self.id
            drink.response.headers["Content-Type"] = mime
            try:
                drink.response.headers["Content-Length"] = self.o.fd.getsize(self.realpath)
            except fs.errors.ResourceNotFoundError:
                return {"error": True, "code": 404, "message": "%r not found" % self.id}
            if mime.split("/", 1)[0] == "text":
                return self.o.fd.open(self.realpath, "rb").read()
            else:
                root, fname = "/".join((self.local_path, self.realpath)).rsplit("/", 1)
                return drink.static_file(fname, root, mimetype=mime, download=self.id)