Exemplo n.º 1
0
    def cachedZipResource(self, request, name, url, segments):
        archivePath = self.config.Resources.child("{0}.zip".format(name))

        if archivePath.exists():
            d = Deferred()
            d.callback(None)
        else:
            d = http_download(archivePath, url)

        def readFromArchive(_):
            filePath = ZipArchive(archivePath.path)
            for segment in segments:
                filePath = filePath.child(segment)
            return filePath.getContent()

        def notFoundHandler(f):
            f.trap(KeyError)
            request.setResponseCode(http.NOT_FOUND)
            set_response_header(
                request, HeaderName.contentType, ContentType.plain
            )
            return "Not found."

        d.addCallback(readFromArchive)
        d.addErrback(notFoundHandler)
        return d
Exemplo n.º 2
0
    def cachedResource(self, name, url):
        name = "_{0}".format(name)
        filePath = self.config.Resources.child(name)

        if filePath.exists():
            return File(filePath.path)

        d = http_download(filePath, url)
        d.addCallback(lambda _: File(filePath.path))
        return d