Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/services/firestore/pagers.py: 35%

133 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-09 06:27 +0000

1# -*- coding: utf-8 -*- 

2# Copyright 2023 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16from typing import ( 

17 Any, 

18 AsyncIterator, 

19 Awaitable, 

20 Callable, 

21 Sequence, 

22 Tuple, 

23 Optional, 

24 Iterator, 

25) 

26 

27from google.cloud.firestore_v1.types import document 

28from google.cloud.firestore_v1.types import firestore 

29from google.cloud.firestore_v1.types import query 

30 

31 

32class ListDocumentsPager: 

33 """A pager for iterating through ``list_documents`` requests. 

34 

35 This class thinly wraps an initial 

36 :class:`google.cloud.firestore_v1.types.ListDocumentsResponse` object, and 

37 provides an ``__iter__`` method to iterate through its 

38 ``documents`` field. 

39 

40 If there are more pages, the ``__iter__`` method will make additional 

41 ``ListDocuments`` requests and continue to iterate 

42 through the ``documents`` field on the 

43 corresponding responses. 

44 

45 All the usual :class:`google.cloud.firestore_v1.types.ListDocumentsResponse` 

46 attributes are available on the pager. If multiple requests are made, only 

47 the most recent response is retained, and thus used for attribute lookup. 

48 """ 

49 

50 def __init__( 

51 self, 

52 method: Callable[..., firestore.ListDocumentsResponse], 

53 request: firestore.ListDocumentsRequest, 

54 response: firestore.ListDocumentsResponse, 

55 *, 

56 metadata: Sequence[Tuple[str, str]] = () 

57 ): 

58 """Instantiate the pager. 

59 

60 Args: 

61 method (Callable): The method that was originally called, and 

62 which instantiated this pager. 

63 request (google.cloud.firestore_v1.types.ListDocumentsRequest): 

64 The initial request object. 

65 response (google.cloud.firestore_v1.types.ListDocumentsResponse): 

66 The initial response object. 

67 metadata (Sequence[Tuple[str, str]]): Strings which should be 

68 sent along with the request as metadata. 

69 """ 

70 self._method = method 

71 self._request = firestore.ListDocumentsRequest(request) 

72 self._response = response 

73 self._metadata = metadata 

74 

75 def __getattr__(self, name: str) -> Any: 

76 return getattr(self._response, name) 

77 

78 @property 

79 def pages(self) -> Iterator[firestore.ListDocumentsResponse]: 

80 yield self._response 

81 while self._response.next_page_token: 

82 self._request.page_token = self._response.next_page_token 

83 self._response = self._method(self._request, metadata=self._metadata) 

84 yield self._response 

85 

86 def __iter__(self) -> Iterator[document.Document]: 

87 for page in self.pages: 

88 yield from page.documents 

89 

90 def __repr__(self) -> str: 

91 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

92 

93 

94class ListDocumentsAsyncPager: 

95 """A pager for iterating through ``list_documents`` requests. 

96 

97 This class thinly wraps an initial 

98 :class:`google.cloud.firestore_v1.types.ListDocumentsResponse` object, and 

99 provides an ``__aiter__`` method to iterate through its 

100 ``documents`` field. 

101 

102 If there are more pages, the ``__aiter__`` method will make additional 

103 ``ListDocuments`` requests and continue to iterate 

104 through the ``documents`` field on the 

105 corresponding responses. 

106 

107 All the usual :class:`google.cloud.firestore_v1.types.ListDocumentsResponse` 

108 attributes are available on the pager. If multiple requests are made, only 

109 the most recent response is retained, and thus used for attribute lookup. 

110 """ 

111 

112 def __init__( 

113 self, 

114 method: Callable[..., Awaitable[firestore.ListDocumentsResponse]], 

115 request: firestore.ListDocumentsRequest, 

116 response: firestore.ListDocumentsResponse, 

117 *, 

118 metadata: Sequence[Tuple[str, str]] = () 

119 ): 

120 """Instantiates the pager. 

121 

122 Args: 

123 method (Callable): The method that was originally called, and 

124 which instantiated this pager. 

125 request (google.cloud.firestore_v1.types.ListDocumentsRequest): 

126 The initial request object. 

127 response (google.cloud.firestore_v1.types.ListDocumentsResponse): 

128 The initial response object. 

129 metadata (Sequence[Tuple[str, str]]): Strings which should be 

130 sent along with the request as metadata. 

131 """ 

132 self._method = method 

133 self._request = firestore.ListDocumentsRequest(request) 

134 self._response = response 

135 self._metadata = metadata 

136 

137 def __getattr__(self, name: str) -> Any: 

138 return getattr(self._response, name) 

139 

140 @property 

141 async def pages(self) -> AsyncIterator[firestore.ListDocumentsResponse]: 

142 yield self._response 

143 while self._response.next_page_token: 

144 self._request.page_token = self._response.next_page_token 

145 self._response = await self._method(self._request, metadata=self._metadata) 

146 yield self._response 

147 

148 def __aiter__(self) -> AsyncIterator[document.Document]: 

149 async def async_generator(): 

150 async for page in self.pages: 

151 for response in page.documents: 

152 yield response 

153 

154 return async_generator() 

155 

156 def __repr__(self) -> str: 

157 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

158 

159 

160class PartitionQueryPager: 

161 """A pager for iterating through ``partition_query`` requests. 

162 

163 This class thinly wraps an initial 

164 :class:`google.cloud.firestore_v1.types.PartitionQueryResponse` object, and 

165 provides an ``__iter__`` method to iterate through its 

166 ``partitions`` field. 

167 

168 If there are more pages, the ``__iter__`` method will make additional 

169 ``PartitionQuery`` requests and continue to iterate 

170 through the ``partitions`` field on the 

171 corresponding responses. 

172 

173 All the usual :class:`google.cloud.firestore_v1.types.PartitionQueryResponse` 

174 attributes are available on the pager. If multiple requests are made, only 

175 the most recent response is retained, and thus used for attribute lookup. 

176 """ 

177 

178 def __init__( 

179 self, 

180 method: Callable[..., firestore.PartitionQueryResponse], 

181 request: firestore.PartitionQueryRequest, 

182 response: firestore.PartitionQueryResponse, 

183 *, 

184 metadata: Sequence[Tuple[str, str]] = () 

185 ): 

186 """Instantiate the pager. 

187 

188 Args: 

189 method (Callable): The method that was originally called, and 

190 which instantiated this pager. 

191 request (google.cloud.firestore_v1.types.PartitionQueryRequest): 

192 The initial request object. 

193 response (google.cloud.firestore_v1.types.PartitionQueryResponse): 

194 The initial response object. 

195 metadata (Sequence[Tuple[str, str]]): Strings which should be 

196 sent along with the request as metadata. 

197 """ 

198 self._method = method 

199 self._request = firestore.PartitionQueryRequest(request) 

200 self._response = response 

201 self._metadata = metadata 

202 

203 def __getattr__(self, name: str) -> Any: 

204 return getattr(self._response, name) 

205 

206 @property 

207 def pages(self) -> Iterator[firestore.PartitionQueryResponse]: 

208 yield self._response 

209 while self._response.next_page_token: 

210 self._request.page_token = self._response.next_page_token 

211 self._response = self._method(self._request, metadata=self._metadata) 

212 yield self._response 

213 

214 def __iter__(self) -> Iterator[query.Cursor]: 

215 for page in self.pages: 

216 yield from page.partitions 

217 

218 def __repr__(self) -> str: 

219 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

220 

221 

222class PartitionQueryAsyncPager: 

223 """A pager for iterating through ``partition_query`` requests. 

224 

225 This class thinly wraps an initial 

226 :class:`google.cloud.firestore_v1.types.PartitionQueryResponse` object, and 

227 provides an ``__aiter__`` method to iterate through its 

228 ``partitions`` field. 

229 

230 If there are more pages, the ``__aiter__`` method will make additional 

231 ``PartitionQuery`` requests and continue to iterate 

232 through the ``partitions`` field on the 

233 corresponding responses. 

234 

235 All the usual :class:`google.cloud.firestore_v1.types.PartitionQueryResponse` 

236 attributes are available on the pager. If multiple requests are made, only 

237 the most recent response is retained, and thus used for attribute lookup. 

238 """ 

239 

240 def __init__( 

241 self, 

242 method: Callable[..., Awaitable[firestore.PartitionQueryResponse]], 

243 request: firestore.PartitionQueryRequest, 

244 response: firestore.PartitionQueryResponse, 

245 *, 

246 metadata: Sequence[Tuple[str, str]] = () 

247 ): 

248 """Instantiates the pager. 

249 

250 Args: 

251 method (Callable): The method that was originally called, and 

252 which instantiated this pager. 

253 request (google.cloud.firestore_v1.types.PartitionQueryRequest): 

254 The initial request object. 

255 response (google.cloud.firestore_v1.types.PartitionQueryResponse): 

256 The initial response object. 

257 metadata (Sequence[Tuple[str, str]]): Strings which should be 

258 sent along with the request as metadata. 

259 """ 

260 self._method = method 

261 self._request = firestore.PartitionQueryRequest(request) 

262 self._response = response 

263 self._metadata = metadata 

264 

265 def __getattr__(self, name: str) -> Any: 

266 return getattr(self._response, name) 

267 

268 @property 

269 async def pages(self) -> AsyncIterator[firestore.PartitionQueryResponse]: 

270 yield self._response 

271 while self._response.next_page_token: 

272 self._request.page_token = self._response.next_page_token 

273 self._response = await self._method(self._request, metadata=self._metadata) 

274 yield self._response 

275 

276 def __aiter__(self) -> AsyncIterator[query.Cursor]: 

277 async def async_generator(): 

278 async for page in self.pages: 

279 for response in page.partitions: 

280 yield response 

281 

282 return async_generator() 

283 

284 def __repr__(self) -> str: 

285 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

286 

287 

288class ListCollectionIdsPager: 

289 """A pager for iterating through ``list_collection_ids`` requests. 

290 

291 This class thinly wraps an initial 

292 :class:`google.cloud.firestore_v1.types.ListCollectionIdsResponse` object, and 

293 provides an ``__iter__`` method to iterate through its 

294 ``collection_ids`` field. 

295 

296 If there are more pages, the ``__iter__`` method will make additional 

297 ``ListCollectionIds`` requests and continue to iterate 

298 through the ``collection_ids`` field on the 

299 corresponding responses. 

300 

301 All the usual :class:`google.cloud.firestore_v1.types.ListCollectionIdsResponse` 

302 attributes are available on the pager. If multiple requests are made, only 

303 the most recent response is retained, and thus used for attribute lookup. 

304 """ 

305 

306 def __init__( 

307 self, 

308 method: Callable[..., firestore.ListCollectionIdsResponse], 

309 request: firestore.ListCollectionIdsRequest, 

310 response: firestore.ListCollectionIdsResponse, 

311 *, 

312 metadata: Sequence[Tuple[str, str]] = () 

313 ): 

314 """Instantiate the pager. 

315 

316 Args: 

317 method (Callable): The method that was originally called, and 

318 which instantiated this pager. 

319 request (google.cloud.firestore_v1.types.ListCollectionIdsRequest): 

320 The initial request object. 

321 response (google.cloud.firestore_v1.types.ListCollectionIdsResponse): 

322 The initial response object. 

323 metadata (Sequence[Tuple[str, str]]): Strings which should be 

324 sent along with the request as metadata. 

325 """ 

326 self._method = method 

327 self._request = firestore.ListCollectionIdsRequest(request) 

328 self._response = response 

329 self._metadata = metadata 

330 

331 def __getattr__(self, name: str) -> Any: 

332 return getattr(self._response, name) 

333 

334 @property 

335 def pages(self) -> Iterator[firestore.ListCollectionIdsResponse]: 

336 yield self._response 

337 while self._response.next_page_token: 

338 self._request.page_token = self._response.next_page_token 

339 self._response = self._method(self._request, metadata=self._metadata) 

340 yield self._response 

341 

342 def __iter__(self) -> Iterator[str]: 

343 for page in self.pages: 

344 yield from page.collection_ids 

345 

346 def __repr__(self) -> str: 

347 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

348 

349 

350class ListCollectionIdsAsyncPager: 

351 """A pager for iterating through ``list_collection_ids`` requests. 

352 

353 This class thinly wraps an initial 

354 :class:`google.cloud.firestore_v1.types.ListCollectionIdsResponse` object, and 

355 provides an ``__aiter__`` method to iterate through its 

356 ``collection_ids`` field. 

357 

358 If there are more pages, the ``__aiter__`` method will make additional 

359 ``ListCollectionIds`` requests and continue to iterate 

360 through the ``collection_ids`` field on the 

361 corresponding responses. 

362 

363 All the usual :class:`google.cloud.firestore_v1.types.ListCollectionIdsResponse` 

364 attributes are available on the pager. If multiple requests are made, only 

365 the most recent response is retained, and thus used for attribute lookup. 

366 """ 

367 

368 def __init__( 

369 self, 

370 method: Callable[..., Awaitable[firestore.ListCollectionIdsResponse]], 

371 request: firestore.ListCollectionIdsRequest, 

372 response: firestore.ListCollectionIdsResponse, 

373 *, 

374 metadata: Sequence[Tuple[str, str]] = () 

375 ): 

376 """Instantiates the pager. 

377 

378 Args: 

379 method (Callable): The method that was originally called, and 

380 which instantiated this pager. 

381 request (google.cloud.firestore_v1.types.ListCollectionIdsRequest): 

382 The initial request object. 

383 response (google.cloud.firestore_v1.types.ListCollectionIdsResponse): 

384 The initial response object. 

385 metadata (Sequence[Tuple[str, str]]): Strings which should be 

386 sent along with the request as metadata. 

387 """ 

388 self._method = method 

389 self._request = firestore.ListCollectionIdsRequest(request) 

390 self._response = response 

391 self._metadata = metadata 

392 

393 def __getattr__(self, name: str) -> Any: 

394 return getattr(self._response, name) 

395 

396 @property 

397 async def pages(self) -> AsyncIterator[firestore.ListCollectionIdsResponse]: 

398 yield self._response 

399 while self._response.next_page_token: 

400 self._request.page_token = self._response.next_page_token 

401 self._response = await self._method(self._request, metadata=self._metadata) 

402 yield self._response 

403 

404 def __aiter__(self) -> AsyncIterator[str]: 

405 async def async_generator(): 

406 async for page in self.pages: 

407 for response in page.collection_ids: 

408 yield response 

409 

410 return async_generator() 

411 

412 def __repr__(self) -> str: 

413 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)