[docs]classJoinPathAPIMixin:""" A mixin class that implements the join path operator. """
[docs]defjoinpath(self:"S3Path",*other:T.Union[str,"S3Path"])->"S3Path":""" Join with other relative path or string parts. Example:: # join with string parts >>> p = S3Path("bucket") >>> p.joinpath("folder", "file.txt") S3Path('s3://bucket/folder/file.txt') # join ith relative path or string parts >>> p = S3Path("bucket") >>> relpath = S3Path("my-bucket", "data", "folder/").relative_to(S3Path("my-bucket", "data")) >>> p.joinpath("data", relpath, "file.txt") S3Path('s3://bucket/data/folder/file.txt') :param others: many string or relative path .. versionadded:: 1.1.1 """args=[self,]forpartinother:ifisinstance(part,str):args.append(part)elifisinstance(part,RelativePathAPIMixin):ifpart.is_relpath()isFalse:msg=("you can only join with string part or relative path! ""{} is not a relative path").format(part)raiseTypeError(msg)else:args.append(part)else:msg=("you can only join with string part or relative path! ""{} is not a relative path").format(part)raiseTypeError(msg)returnself._from_parts(args)
def__truediv__(self:"S3Path",other:T.Union[str,"S3Path",T.List[T.Union[str,"S3Path"]]])->"S3Path":""" A syntax sugar. Basically ``S3Path(s3path, part1, part2, ...)`` is equal to ``s3path / part1 / part2 / ...`` or ``s3path / [part1, part2]`` Example:: >>> S3Path("bucket") / "folder" / "file.txt" S3Path('s3://bucket/folder/file.txt') >>> S3Path("bucket") / ["folder", "file.txt"] S3Path('s3://bucket/folder/file.txt') # relative path also work >>> S3Path("new-bucket") / (S3Path("bucket/file.txt").relative_to(S3Path("bucket"))) S3Path('s3://new-bucket/file.txt') .. versionadded:: 1.0.11 """ifself.is_void():raiseTypeError("You cannot do ``VoidS3Path / other``!")ifisinstance(other,list):res=selfforpartinother:res=res/partreturnreselse:if(self.is_relpath()andisinstance(other,RelativePathAPIMixin)andother.is_relpath()isFalse):raiseTypeError("you cannot do ``RelativeS3Path / NonRelativeS3Path``!")returnself.joinpath(other)