From 5b290b7bafd9ed068865abb27357663574b86cf7 Mon Sep 17 00:00:00 2001 From: vincentpost Date: Thu, 16 Jul 2026 10:09:19 +0200 Subject: [PATCH] Modified CsvFileOrUrl to avoid AssertionError when a zip file contains a number of las files other than 1 --- brodata/dino.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/brodata/dino.py b/brodata/dino.py index 901f439..9dc0fc0 100644 --- a/brodata/dino.py +++ b/brodata/dino.py @@ -476,14 +476,18 @@ def __init__( if is_zipfile: # BoorgatMetingen are las files that are delivered in a zip-file with ZipFile(BytesIO(req.content)) as myzip: - files = myzip.namelist() - files = [f for f in files if f.endswith(".las")] - assert len(files) == 1, "Only one file in the zipfile supported" - with myzip.open(files[0]) as myfile: - if to_file is not None: - with open(to_file, "wb") as f: - f.write(myfile.read()) - self._read_contents(TextIOWrapper(myfile)) + files = [f for f in myzip.namelist() if f.endswith(".las")] + if len(files) == 0: + logger.warning("Zipfile contains no las files.") + self._read_contents(None) + else: + if len(files) > 1: + logger.warning(f"Zipfile contains {len(files)} las files. Only first file will be read.") + with myzip.open(files[0]) as myfile: + if to_file is not None: + with open(to_file, "wb") as f: + f.write(myfile.read()) + self._read_contents(TextIOWrapper(myfile)) else: if to_file is not None: with open(to_file, "w") as f: