Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
- Fixing broken references released since minio-py version 7.0.0 (https://github.com/minio/minio-py/releases/tag/7.0.0)
- definitions.Object moved to datatypes.Object
- All the custom exceptions were removed from minio.error. Using the base S3Error as the exception and S3Error.code to determine the type of known error.
  • Loading branch information
novama-ot1 committed Aug 9, 2024
1 parent 4817a5c commit 130861e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pyminio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import pytz
from attrdict import AttrDict
from minio import Minio, definitions
from minio.error import NoSuchKey, BucketNotEmpty
from minio import Minio, datatypes
from minio.error import S3Error

from .exceptions import DirectoryNotEmptyError
from .structures import Match, ObjectData, File, Folder, ROOT
Expand Down Expand Up @@ -89,7 +89,7 @@ def mkdirs(self, path: str):
object_name=match.prefix,
data=empty_file, length=0)

def _get_objects_at(self, match: Match) -> List[definitions.Object]:
def _get_objects_at(self, match: Match) -> List[datatypes.Object]:
"""Return all objects in the specified bucket and directory path.
Args:
Expand Down Expand Up @@ -236,9 +236,11 @@ def rmdir(self, path: str, recursive: bool = False) -> 'Pyminio':
try:
self.minio_obj.remove_bucket(match.bucket)

except BucketNotEmpty:
raise DirectoryNotEmptyError("can not recursively delete "
"non-empty directory")
except S3Error as e:
if e.code in ["BucketNotEmpty"]:
raise DirectoryNotEmptyError("can not recursively delete "
"non-empty directory")
raise
else:
self.minio_obj.remove_object(match.bucket, match.prefix)

Expand Down Expand Up @@ -406,9 +408,10 @@ def get(self, path: str) -> ObjectData:
name = join(basename(normpath(details.object_name)), '')
return_obj = Folder

except (NoSuchKey, StopIteration):
raise ValueError(f"cannot access {path!r}: "
"No such file or directory")
except S3Error as e:
if e.code in ["NoSuchKey", "StopIteration"]:
raise ValueError(f"cannot access {path!r}: "
"No such file or directory")

details_metadata = \
self._extract_metadata(details.metadata)
Expand Down

0 comments on commit 130861e

Please sign in to comment.