# -*- coding: utf-8 -*-"""Is the S3Path a XYZ testing.- :meth:`~IsTestAPIMixin.is_void`- :meth:`~IsTestAPIMixin.is_dir`- :meth:`~IsTestAPIMixin.is_file`- :meth:`~IsTestAPIMixin.is_bucket`"""importtypingasTfrom..excimport(S3PathIsNotFolderError,S3PathIsNotFileError,S3PathIsNotBucketError,)from..constantsimportIS_DELETE_MARKERifT.TYPE_CHECKING:# pragma: no coverfrom.s3pathimportS3Path
[docs]classIsTestAPIMixin:""" A mixin class that implements the condition test methods. """
[docs]defis_void(self:"S3Path")->bool:""" Test if it is a void S3 path. **Definition** no bucket, no key, no parts, no type, no nothing. A void path is also a special :meth:`relative path <is_relpath>`, because any path join with void path results to itself. """return(self._bucketisNone)and(len(self._parts)==0)
[docs]defis_dir(self:"S3Path")->bool:""" Test if it is a S3 directory **Definition** A logical S3 directory that never physically exists. An S3 :meth:`bucket <is_bucket>` is also a special dir, which is the root dir. .. versionadded:: 1.0.1 """ifself._is_dirisNone:returnFalseelse:returnself._is_dir
[docs]defis_file(self:"S3Path")->bool:""" Test if it is a S3 object **Definition** A S3 object. .. versionadded:: 1.0.1 """ifself._is_dirisNone:returnFalseelse:returnnotself._is_dir
[docs]defis_bucket(self:"S3Path")->bool:""" Test if it is a S3 bucket. **Definition** A S3 bucket, the root folder S3 path is equivalent to a S3 bucket. A S3 bucket are always :meth:`is_dir() is True <is_dir>` .. versionadded:: 1.0.1 """return((self._bucketisnotNone)and(len(self._parts)==0)and(self._is_dirisTrue))
[docs]defis_delete_marker(self:"S3Path")->bool:""" Test if it is a delete-marker. A delete-marker is just a version of an object without content. .. versionadded:: 2.0.1 """ifself.is_file():if(self.version_idisnotNone)and(IS_DELETE_MARKERinself._meta):returnTrueelse:returnFalseelse:returnFalse
[docs]defensure_object(self:"S3Path")->None:""" A validator method that ensure it represents a S3 object. .. versionadded:: 1.0.1 """ifself.is_file()isnotTrue:raiseS3PathIsNotFileError.make(self.uri)
[docs]defensure_file(self:"S3Path")->None:""" A validator method that ensure it represents a S3 object. .. versionadded:: 1.2.1 """returnself.ensure_object()
[docs]defensure_not_object(self:"S3Path")->None:""" A validator method that ensure it IS NOT a S3 object. .. versionadded:: 1.2.1 """ifself.is_file()isTrue:raiseTypeError(f"S3 URI: {self} IS an s3 object!")
[docs]defensure_not_file(self:"S3Path")->None:""" A validator method that ensure it IS NOT a S3 object. .. versionadded:: 1.2.1 """self.ensure_not_object()
[docs]defensure_dir(self:"S3Path")->None:""" A validator method that ensure it represents a S3 dir. .. versionadded:: 1.0.1 """ifself.is_dir()isnotTrue:raiseS3PathIsNotFolderError.make(self.uri)
[docs]defensure_not_dir(self:"S3Path")->None:""" A validator method that ensure it IS NOT a S3 dir. .. versionadded:: 1.2.1 """ifself.is_dir()isTrue:raiseTypeError(f"{self} IS an s3 directory!")
[docs]defensure_bucket(self:"S3Path")->None:""" A validator method that ensure it represents a S3 bucket. .. versionadded:: 2.1.1 """ifself.is_bucket()isnotTrue:raiseS3PathIsNotBucketError.make(self.uri)