diff --git a/tiled/_tests/test_slicer.py b/tiled/_tests/test_slicer.py index 8e874d91c..5ad419d3c 100644 --- a/tiled/_tests/test_slicer.py +++ b/tiled/_tests/test_slicer.py @@ -129,8 +129,8 @@ def test_slicer_malicious_exec(slice: str): _ = slice_(slice) -@pytest.mark.parametrize("slice", slice_typo_data + slice_malicious_data) -def test_slicer_fastapi_query_rejectsion(slice, client): +@pytest.mark.parametrize("slice_", slice_typo_data + slice_malicious_data) +def test_slicer_fastapi_query_rejection(slice_, client): http_client = client.context.http_client - response = http_client.get(f"/api/v1/array/block/x?block=0&slice={slice}") + response = http_client.get(f"/api/v1/array/block/x?block=0&slice={slice_}") assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY diff --git a/tiled/client/array.py b/tiled/client/array.py index c0a89bec6..edfdffa5d 100644 --- a/tiled/client/array.py +++ b/tiled/client/array.py @@ -125,7 +125,7 @@ def read_block(self, block, slice=None): def read(self, slice=None): """ - Acess the entire array or a slice. + Access the entire array or a slice. The array will be internally chunked with dask. """ diff --git a/tiled/server/dependencies.py b/tiled/server/dependencies.py index 300f5ee43..f13c676fc 100644 --- a/tiled/server/dependencies.py +++ b/tiled/server/dependencies.py @@ -165,17 +165,17 @@ def expected_shape( return tuple(map(int, expected_shape.split(","))) +def np_style_slicer(indices: tuple): + return indices[0] if len(indices) == 1 else slice_func(*indices) + + +def parse_slice_str(dim: str): + return np_style_slicer(tuple(int(idx) if idx else None for idx in dim.split(":"))) + + def slice_( - slice: str = Query(None, pattern=SLICE_REGEX), + slice: Optional[str] = Query(None, pattern=SLICE_REGEX), ): "Specify and parse a block index parameter." - def np_style_slicer(indices: tuple): - return indices[0] if len(indices) == 1 else slice_func(*indices) - - def parse_slice_str(dim: str): - return np_style_slicer( - tuple(int(idx) if idx else None for idx in dim.split(":")) - ) - return tuple(parse_slice_str(dim) for dim in (slice or "").split(",") if dim)