Skip to content

Commit d36407f

Browse files
committed
Add __str__ methods
1 parent 7281bbb commit d36407f

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

batch_mailchimp/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ def __init__(self, config={}):
113113
self.verifiedDomains = VerifiedDomainsApi(self.api_client)
114114
self.batches = BatchesApi(self.api_client)
115115

116+
def __str__(self):
117+
return "batch mode {batch_mode_toggle}".format(
118+
batch_mode_toggle="ON" if self.api_client.batch_mode else "OFF",
119+
)
120+
116121
def __repr__(self):
117-
return "<{module}.{name}: batch mode {batch_mode_toggle}>".format(
122+
return "<{module}.{name}: {str_rep}>".format(
118123
module=self.__class__.__module__,
119124
name=self.__class__.__name__,
120-
batch_mode_toggle="ON" if self.api_client.batch_mode else "OFF",
125+
str_rep=str(self),
121126
)

batch_mailchimp/batches_api.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ def __init__(self, **kwargs):
1313
self.status_code = kwargs["status_code"]
1414
self.body = json.loads(kwargs["response"])
1515

16+
def __str__(self):
17+
return "{operation_id} ({status_code}".format(
18+
operation_id=self.operation_id,
19+
status_code=self.status_code,
20+
)
21+
1622
def __repr__(self):
17-
return "<{module}.{name}: {operation_id} ({status_code})>".format(
23+
return "<{module}.{name}: {str_rep}>".format(
1824
module=self.__class__.__module__,
1925
name=self.__class__.__name__,
20-
operation_id=self.operation_id,
21-
status_code=self.status_code,
26+
str_rep=str(self),
2227
)
2328

2429

@@ -39,16 +44,21 @@ def update(self, **kwargs):
3944
self.response_body_url = kwargs.get("response_body_url")
4045
self._status = kwargs.get("status")
4146

42-
def __repr__(self):
43-
return "<{module}.{name}: {finished}/{total} operation{s} ({status})>".format(
44-
module=self.__class__.__module__,
45-
name=self.__class__.__name__,
47+
def __str__(self):
48+
return "{finished}/{total} operation{s} ({status})".format(
4649
finished=self.finished_operations,
4750
total=self.total_operations,
4851
s="s" if self.total_operations != 1 else "",
4952
status=self._status,
5053
)
5154

55+
def __repr__(self):
56+
return "<{module}.{name}: {str_rep}>".format(
57+
module=self.__class__.__module__,
58+
name=self.__class__.__name__,
59+
str_rep=str(self),
60+
)
61+
5262
def status(self, refresh=False):
5363
if refresh:
5464
self._batches_api.status(self.batch_id, refresh=refresh)

batch_mailchimp/collections.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33

44
class MyCollection(UserDict):
5+
def __str__(self):
6+
return str(list(self.data.values())),
7+
58
def __repr__(self):
6-
return "<{module}.{name}: {data}>".format(
9+
return "<{module}.{name}: {str_rep}>".format(
710
module=self.__class__.__module__,
811
name=self.__class__.__name__,
9-
data=list(self.data.values()),
12+
str_rep=str(self),
1013
)
1114

1215
def __getitem__(self, item):

0 commit comments

Comments
 (0)