Skip to content

Commit 8ab7b2f

Browse files
committed
Move stuff about a bit
1 parent dcb5ebc commit 8ab7b2f

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

batch_mailchimp/batches_api.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
from collections import UserDict
21
import json
32
from io import BytesIO
43
import tarfile
54
from itertools import islice
65
from mailchimp_marketing.api import batches_api
76
import requests
8-
9-
10-
class MyCollection(UserDict):
11-
def __repr__(self):
12-
return "<{module}.{name}: {data}>".format(
13-
module=self.__class__.__module__,
14-
name=self.__class__.__name__,
15-
data=list(self.data.values()),
16-
)
17-
18-
def __getitem__(self, item):
19-
if type(item) is str:
20-
return super().__getitem__(item)
21-
return list(self.data.values())[item]
22-
23-
def __iter__(self):
24-
for item in self.data.values():
25-
yield item
26-
27-
28-
class ResponseCollection(MyCollection):
29-
...
30-
31-
32-
class BatchCollection(MyCollection):
33-
...
7+
from .decorators import no_batch
8+
from .collections import BatchCollection, ResponseCollection
349

3510

3611
class Response:
@@ -102,18 +77,6 @@ def delete(self):
10277
return self._batches_api.delete_request(self.batch_id)
10378

10479

105-
def no_batch(func):
106-
def wrapper_no_batch(self, *args, **kwargs):
107-
batch_mode = self.api_client.batch_mode
108-
self.api_client.set_batch_mode(False)
109-
try:
110-
response = func(self, *args, **kwargs)
111-
finally:
112-
self.api_client.set_batch_mode(batch_mode)
113-
return response
114-
return wrapper_no_batch
115-
116-
11780
class BatchesApi(batches_api.BatchesApi):
11881
_max_operations = 1_000
11982

batch_mailchimp/collections.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from collections import UserDict
2+
3+
4+
class MyCollection(UserDict):
5+
def __repr__(self):
6+
return "<{module}.{name}: {data}>".format(
7+
module=self.__class__.__module__,
8+
name=self.__class__.__name__,
9+
data=list(self.data.values()),
10+
)
11+
12+
def __getitem__(self, item):
13+
if type(item) is str:
14+
return super().__getitem__(item)
15+
return list(self.data.values())[item]
16+
17+
def __iter__(self):
18+
for item in self.data.values():
19+
yield item
20+
21+
22+
class ResponseCollection(MyCollection):
23+
...
24+
25+
26+
class BatchCollection(MyCollection):
27+
...

batch_mailchimp/decorators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def no_batch(func):
2+
def wrapper_no_batch(self, *args, **kwargs):
3+
batch_mode = self.api_client.batch_mode
4+
self.api_client.set_batch_mode(False)
5+
try:
6+
response = func(self, *args, **kwargs)
7+
finally:
8+
self.api_client.set_batch_mode(batch_mode)
9+
return response
10+
return wrapper_no_batch

0 commit comments

Comments
 (0)