Esempio n. 1
0
    def render(self, request):
        if not self.producers:
            for bucket, key in self.objects:
                producer = AwsProducer(bucket, key)
                self.producers.append(producer)
        
        zipstream = ZipStream(request)
        deferreds = []

        for producer in self.producers:
            d = zipstream.addProducer(producer)
            deferreds.append(d)

        deferredlist = DeferredList(deferreds)
        deferredlist.addCallback(lambda _: zipstream.centralDirectory())
        return deferredlist
Esempio n. 2
0
    def create_zipstream_from_tempfiles(self, num_files, min_size=0, max_size=10 * (1024 ** 2)):
        consumer = TestConsumer()
        zipstream = ZipStream(consumer)
        deferreds = []
        producers = {}

        for i in range(num_files):
            producersize = random.randint(min_size, max_size)
            filename = make_random_temp_file(producersize)

            producer = FileProducer(filename)
            deferreds.append(zipstream.addProducer(producer))
            producers.update({filename: producer})
            self.tempfiles.append(filename)

        deferredlist = DeferredList(deferreds)
        deferredlist.addCallback(lambda _: zipstream.centralDirectory())
        deferredlist.addCallback(lambda _: consumer.seek(0))
        yield deferredlist

        returnValue((zipstream, consumer, producers))