11import abc
22
3- from typing import List
3+ from typing import List , Union
44
55from algoliasearch .exceptions import RequestException
66from algoliasearch .helpers import get_items
@@ -26,6 +26,12 @@ def wait(self):
2626
2727 pass # pragma: no cover
2828
29+ @abc .abstractmethod
30+ def __getitem__ (self , key ):
31+ # type:(Union[int, str]) -> Union[int, str, dict]
32+
33+ pass # pragma: no cover
34+
2935
3036class IndexingResponse (Response ):
3137
@@ -48,6 +54,11 @@ def wait(self):
4854
4955 return self
5056
57+ def __getitem__ (self , key ):
58+ # type:(Union[int, str]) -> Union[int, str, dict]
59+
60+ return self .raw_responses [key ]
61+
5162
5263class MultipleResponse (Response ):
5364
@@ -57,6 +68,9 @@ def __init__(self, responses=None):
5768 self .responses = [] if responses is None else responses
5869 self ._waitable = list (self .responses )
5970
71+ def __repr__ (self ):
72+ return self .responses
73+
6074 def push (self , response ):
6175 # type: (Response) -> None
6276
@@ -75,6 +89,11 @@ def wait(self):
7589
7690 return self
7791
92+ def __getitem__ (self , key ):
93+ # type:(Union[int, str]) -> Union[int, str, dict]
94+
95+ return self .responses [key ]
96+
7897
7998class AddApiKeyResponse (Response ):
8099
@@ -98,6 +117,11 @@ def wait(self):
98117
99118 return self
100119
120+ def __getitem__ (self , key ):
121+ # type:(Union[int, str]) -> Union[int, str, dict]
122+
123+ return self .raw_response [key ]
124+
101125
102126class UpdateApiKeyResponse (Response ):
103127
@@ -114,7 +138,8 @@ def wait(self):
114138
115139 while not self ._done :
116140 api_key = self ._client ._sync ().get_api_key (
117- self .raw_response ['key' ]
141+ self .raw_response ['key' ],
142+ self ._request_options
118143 )
119144
120145 if self ._have_changed (api_key ):
@@ -136,6 +161,11 @@ def _have_changed(self, api_key):
136161 return any ([(valid_key in body and body [valid_key ] == api_key .get (
137162 valid_key )) for valid_key in valid_keys ])
138163
164+ def __getitem__ (self , key ):
165+ # type:(Union[int, str]) -> Union[int, str, dict]
166+
167+ return self .raw_response [key ]
168+
139169
140170class DeleteApiKeyResponse (Response ):
141171
@@ -158,6 +188,11 @@ def wait(self):
158188
159189 return self
160190
191+ def __getitem__ (self , key ):
192+ # type:(Union[int, str]) -> Union[int, str, dict]
193+
194+ return self .raw_response [key ]
195+
161196
162197class RestoreApiKeyResponse (Response ):
163198
@@ -182,6 +217,11 @@ def wait(self):
182217
183218 return self
184219
220+ def __getitem__ (self , key ):
221+ # type:(Union[int, str]) -> Union[int, str, dict]
222+
223+ return self .raw_response [key ]
224+
185225
186226class MultipleIndexBatchIndexingResponse (Response ):
187227
@@ -201,3 +241,8 @@ def wait(self):
201241 self ._done = True
202242
203243 return self
244+
245+ def __getitem__ (self , key ):
246+ # type:(Union[int, str]) -> Union[int, str, dict]
247+
248+ return self .raw_response [key ]
0 commit comments