Beispiel #1
0
def test_exists():
    """Test the exists() function.
    """
    hooks.reset()
    assert hooks.exists("alien_invasion") == True
    assert hooks.exists("worldpeace") == False
    hooks.register("worldpeace")
    assert hooks.exists("worldpeace") == True
    hooks.reset()
    assert hooks.exists("worldpeace") == False
Beispiel #2
0
    def _load_data(self):
        """Download the image while yielding chunks as they are
        coming in.

        Called internally when access to the image data is needed. The
        fact that the data is yielded live means the caller may already
        start using it before the download is complete.
        """
        # TODO: store bigger files on disk?
        self._data = StringIO.StringIO()
        while True:
            chunk = self.request.read(self.chunk_size)
            if not chunk:
                break
            self._data.write(chunk)
            # HOOK: FEED_IMAGE_DOWNLOAD_CHUNK
            if hooks.exists('feed_image_download_chunk'):
                hooks.trigger('feed_image_download_chunk',
                              args=[self, self.data.tell()])
            yield chunk
        # reset once we initially loaded the data
        self.data.seek(0)