diff --git a/great_ai/large_file/large_file/large_file_base.py b/great_ai/large_file/large_file/large_file_base.py index 005f185..64138c5 100644 --- a/great_ai/large_file/large_file/large_file_base.py +++ b/great_ai/large_file/large_file/large_file_base.py @@ -64,7 +64,13 @@ class LargeFileBase(ABC): keep_last_n: Optional[int] = None, cache_only_mode: bool = False, ): - self._name = re.sub(r"[^a-zA-Z0-9._-]+", "", name) + clean_name = re.sub(r"[^!a-zA-Z0-9._-]+", "", name) + if clean_name != name: + raise ValueError( + f"Given name contains illegal characters, consider changing it to: `{clean_name}`" + ) + + self._name = name self._version = version self._mode = mode self._keep_last_n = keep_last_n diff --git a/great_ai/large_file/large_file/large_file_mongo.py b/great_ai/large_file/large_file/large_file_mongo.py index 3cbb9c0..3bed0a1 100644 --- a/great_ai/large_file/large_file/large_file_mongo.py +++ b/great_ai/large_file/large_file/large_file_mongo.py @@ -44,7 +44,7 @@ class LargeFileMongo(LargeFileBase): def _client(self) -> GridFSBucket: if self.mongo_connection_string is None or self.mongo_database is None: raise ValueError( - "Please configure the MongoDB access options by calling LargeFileMongo.configure_credentials or set offline_mode=True in the constructor." + "Please configure the MongoDB access options by calling LargeFileMongo.configure_credentials or set cache_only_mode=True in the constructor." ) db: Database = MongoClient(self.mongo_connection_string)[self.mongo_database] diff --git a/great_ai/large_file/large_file/large_file_s3.py b/great_ai/large_file/large_file/large_file_s3.py index eb2a307..119caa8 100644 --- a/great_ai/large_file/large_file/large_file_s3.py +++ b/great_ai/large_file/large_file/large_file_s3.py @@ -56,7 +56,7 @@ class LargeFileS3(LargeFileBase): or self.bucket_name is None ): raise ValueError( - "Please configure the S3 access options by calling LargeFileS3.configure_credentials or set offline_mode=True in the constructor." + "Please configure the S3 access options by calling LargeFileS3.configure_credentials or set cache_only_mode=True in the constructor." ) return boto3.client( diff --git a/tests/large_file/test_large_file.py b/tests/large_file/test_large_file.py index 87571fa..9afc615 100644 --- a/tests/large_file/test_large_file.py +++ b/tests/large_file/test_large_file.py @@ -24,6 +24,20 @@ def test_uninitialized() -> None: LargeFileS3("test-file") +def test_bad_file_name() -> None: + with pytest.raises(ValueError): + LargeFileS3("../no-no", cache_only_mode=True) + + with pytest.raises(ValueError): + LargeFileS3("is this wrong?", cache_only_mode=True) + + with pytest.raises(FileNotFoundError): + LargeFileS3("!378378_fer-ef", cache_only_mode=True) # this should work + + with pytest.raises(FileNotFoundError): + LargeFileS3("3", cache_only_mode=True) # this should work + + def test_bad_file_modes() -> None: with pytest.raises(ValueError): LargeFileS3("test-file", "w", version=3)