Exemplo n.º 1
0
    def get(self, key=None, type_code=None, meta=None):
        key = self._validate_get_args(key, type_code, meta)
        path = self.get_path(key)
        if not exists(path):
            metrics_counter('commcare.blobdb.notfound')
            raise NotFound(key)

        file_obj = open(path, "rb")
        if meta and meta.is_compressed:
            content_length, compressed_length = meta.content_length, meta.compressed_length
            file_obj = GzipFile(fileobj=file_obj, mode='rb')
        else:
            content_length, compressed_length = self.size(key), None
        return BlobStream(file_obj, self, key, content_length, compressed_length)
Exemplo n.º 2
0
    def get(self, key=None, type_code=None, meta=None):
        key = self._validate_get_args(key, type_code, meta)
        check_safe_key(key)
        with maybe_not_found(throw=NotFound(key)), self.report_timing(
                'get', key):
            resp = self._s3_bucket().Object(key).get()
        reported_content_length = resp['ContentLength']

        body = resp["Body"]
        if meta and meta.is_compressed:
            content_length, compressed_length = meta.content_length, meta.compressed_length
            body = GzipFile(key, mode='rb', fileobj=body)
        else:
            content_length, compressed_length = reported_content_length, None
        return BlobStream(body, self, key, content_length, compressed_length)
Exemplo n.º 3
0
 def test_close_on_exit_context(self):
     fake = FakeStream()
     self.assertEqual(fake.close_calls, 0)
     with BlobStream(fake, fake, None, 0, 0):
         pass
     self.assertEqual(fake.close_calls, 1)
Exemplo n.º 4
0
 def test_close(self):
     fake = FakeStream()
     self.assertEqual(fake.close_calls, 0)
     BlobStream(fake, fake, None, 0, 0).close()
     self.assertEqual(fake.close_calls, 1)