|
1 | | -from collections import UserDict |
2 | 1 | import json |
3 | 2 | from io import BytesIO |
4 | 3 | import tarfile |
5 | 4 | from itertools import islice |
6 | 5 | from mailchimp_marketing.api import batches_api |
7 | 6 | 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 |
34 | 9 |
|
35 | 10 |
|
36 | 11 | class Response: |
@@ -102,18 +77,6 @@ def delete(self): |
102 | 77 | return self._batches_api.delete_request(self.batch_id) |
103 | 78 |
|
104 | 79 |
|
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 | | - |
117 | 80 | class BatchesApi(batches_api.BatchesApi): |
118 | 81 | _max_operations = 1_000 |
119 | 82 |
|
|
0 commit comments