Ejemplo n.º 1
0
 def __iter__(self):
     for chunk in self.data:
         self.bytes_read += len(chunk)
         if self.bytes_read > self.limit:
             raise exception.ImageSizeLimitExceeded()
         else:
             yield chunk
 def test_image_stage_raises_image_size_exceeded(self, mock_store_add):
     mock_store_add.side_effect = exception.ImageSizeLimitExceeded()
     image_id = str(uuid.uuid4())
     request = unit_test_utils.get_fake_request()
     image = FakeImage(image_id=image_id)
     self.image_repo.result = image
     with mock.patch.object(self.controller, "_unstage"):
         self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                           self.controller.stage, request, image_id,
                           'YYYYYYY', 7)
Ejemplo n.º 3
0
def limiting_iter(iter, limit):
    """
    Iterator designed to fail when reading image data past the configured
    allowable amount.
    """
    bytes_read = 0
    for chunk in iter:
        bytes_read += len(chunk)
        if bytes_read > limit:
            raise exception.ImageSizeLimitExceeded()
        else:
            yield chunk
Ejemplo n.º 4
0
 def read(self, i):
     result = self.data.read(i)
     self.bytes_read += len(result)
     if self.bytes_read > self.limit:
         raise exception.ImageSizeLimitExceeded()
     return result