From df3e8955b936480b590fa2afb542c649d2e31449 Mon Sep 17 00:00:00 2001 From: Bahram Aghaei Date: Mon, 24 May 2021 20:37:58 +0430 Subject: [PATCH] Bucket: add string representation and equality method (#1095) * add string representation as well as equality method * add __hash__ method to be able to use a bucket object inside a set or a dictionary --- minio/datatypes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/minio/datatypes.py b/minio/datatypes.py index 6c07d29c8..7c321d83e 100644 --- a/minio/datatypes.py +++ b/minio/datatypes.py @@ -51,6 +51,22 @@ def creation_date(self): """Get creation date.""" return self._creation_date + def __repr__(self): + return "{}({!r})".format(type(self).__name__, self.name) + + def __str__(self): + return self.name + + def __eq__(self, other): + if isinstance(other, Bucket): + return self.name == other.name + if isinstance(other, str): + return self.name == other + return NotImplemented + + def __hash__(self): + return hash(self.name) + class ListAllMyBucketsResult: """LissBuckets API result."""