How to use the terracotta.exceptions function in terracotta

To help you get started, we’ve selected a few terracotta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DHI-GRAS / terracotta / tests / handlers / test_colorbar.py View on Github external
def test_colorbar_error(use_read_only_database):
    import terracotta
    from terracotta.handlers import colorbar

    keys = ('too', 'many', 'keys')
    with pytest.raises(terracotta.exceptions.UnknownKeyError):
        colorbar.colorbar(keys)

    keys = ('made-up', 'keys')
    with pytest.raises(terracotta.exceptions.DatasetNotFoundError):
        colorbar.colorbar(keys)
github DHI-GRAS / terracotta / tests / handlers / test_colorbar.py View on Github external
def test_colorbar_error(use_read_only_database):
    import terracotta
    from terracotta.handlers import colorbar

    keys = ('too', 'many', 'keys')
    with pytest.raises(terracotta.exceptions.UnknownKeyError):
        colorbar.colorbar(keys)

    keys = ('made-up', 'keys')
    with pytest.raises(terracotta.exceptions.DatasetNotFoundError):
        colorbar.colorbar(keys)
github DHI-GRAS / terracotta / terracotta / flask_api.py View on Github external
def inner(*args: Any, **kwargs: Any) -> Any:
        try:
            return fun(*args, **kwargs)
        except (exceptions.DatasetNotFoundError, exceptions.UnknownKeyError):
            if current_app.debug:
                raise
            abort(404)
        except (exceptions.InvalidArgumentsError, exceptions.TileOutOfBoundsError):
            if current_app.debug:
                raise
            abort(400)
github DHI-GRAS / terracotta / terracotta / server / flask_api.py View on Github external
def inner(*args: Any, **kwargs: Any) -> Any:
        try:
            return fun(*args, **kwargs)

        except exceptions.TileOutOfBoundsError:
            # send empty image
            from terracotta import get_settings, image
            settings = get_settings()
            return send_file(image.empty_image(settings.DEFAULT_TILE_SIZE), mimetype='image/png')

        except exceptions.DatasetNotFoundError as exc:
            # wrong path -> 404
            if current_app.debug:
                raise
            return abort(404, str(exc))

        except (exceptions.InvalidArgumentsError, exceptions.InvalidKeyError,
                marshmallow.ValidationError) as exc:
            # wrong query arguments -> 400
            if current_app.debug:
                raise
            return abort(400, str(exc))
github DHI-GRAS / terracotta / terracotta / drivers / mysql.py View on Github external
def delete(self, keys: Union[Sequence[str], Mapping[str, str]]) -> None:
        cursor = self._cursor

        if len(keys) != len(self.key_names):
            raise exceptions.InvalidKeyError(
                f'Got wrong number of keys (available keys: {self.key_names})'
            )

        keys = self._key_dict_to_sequence(keys)
        key_dict = dict(zip(self.key_names, keys))

        if not self.get_datasets(key_dict):
            raise exceptions.DatasetNotFoundError(f'No dataset found with keys {keys}')

        where_string = ' AND '.join([f'{key}=%s' for key in self.key_names])
        cursor.execute(f'DELETE FROM datasets WHERE {where_string}', keys)
        cursor.execute(f'DELETE FROM metadata WHERE {where_string}', keys)
github DHI-GRAS / terracotta / terracotta / xyz.py View on Github external
if tile_xyz is None:
        # read whole dataset
        return driver.get_raster_tile(
            keys, tile_size=tile_size, preserve_values=preserve_values,
            asynchronous=asynchronous
        )

    # determine bounds for given tile
    metadata = driver.get_metadata(keys)
    wgs_bounds = metadata['bounds']

    tile_x, tile_y, tile_z = tile_xyz

    if not tile_exists(wgs_bounds, tile_x, tile_y, tile_z):
        raise exceptions.TileOutOfBoundsError(
            f'Tile {tile_z}/{tile_x}/{tile_y} is outside image bounds'
        )

    mercator_tile = mercantile.Tile(x=tile_x, y=tile_y, z=tile_z)
    target_bounds = mercantile.xy_bounds(mercator_tile)

    return driver.get_raster_tile(
        keys, tile_bounds=target_bounds, tile_size=tile_size,
        preserve_values=preserve_values, asynchronous=asynchronous
    )