1# -*- coding: utf-8 -*-
2# Copyright 2025 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 google.api_core import gapic_v1
17from google.api_core import retry as retries
18from google.api_core import retry_async as retries_async
19from typing import (
20 Any,
21 AsyncIterator,
22 Awaitable,
23 Callable,
24 Sequence,
25 Tuple,
26 Optional,
27 Iterator,
28 Union,
29)
30
31try:
32 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
33 OptionalAsyncRetry = Union[
34 retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None
35 ]
36except AttributeError: # pragma: NO COVER
37 OptionalRetry = Union[retries.Retry, object, None] # type: ignore
38 OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore
39
40from google.pubsub_v1.types import pubsub
41
42
43class ListTopicsPager:
44 """A pager for iterating through ``list_topics`` requests.
45
46 This class thinly wraps an initial
47 :class:`google.pubsub_v1.types.ListTopicsResponse` object, and
48 provides an ``__iter__`` method to iterate through its
49 ``topics`` field.
50
51 If there are more pages, the ``__iter__`` method will make additional
52 ``ListTopics`` requests and continue to iterate
53 through the ``topics`` field on the
54 corresponding responses.
55
56 All the usual :class:`google.pubsub_v1.types.ListTopicsResponse`
57 attributes are available on the pager. If multiple requests are made, only
58 the most recent response is retained, and thus used for attribute lookup.
59 """
60
61 def __init__(
62 self,
63 method: Callable[..., pubsub.ListTopicsResponse],
64 request: pubsub.ListTopicsRequest,
65 response: pubsub.ListTopicsResponse,
66 *,
67 retry: OptionalRetry = gapic_v1.method.DEFAULT,
68 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
69 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
70 ):
71 """Instantiate the pager.
72
73 Args:
74 method (Callable): The method that was originally called, and
75 which instantiated this pager.
76 request (google.pubsub_v1.types.ListTopicsRequest):
77 The initial request object.
78 response (google.pubsub_v1.types.ListTopicsResponse):
79 The initial response object.
80 retry (google.api_core.retry.Retry): Designation of what errors,
81 if any, should be retried.
82 timeout (float): The timeout for this request.
83 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
84 sent along with the request as metadata. Normally, each value must be of type `str`,
85 but for metadata keys ending with the suffix `-bin`, the corresponding values must
86 be of type `bytes`.
87 """
88 self._method = method
89 self._request = pubsub.ListTopicsRequest(request)
90 self._response = response
91 self._retry = retry
92 self._timeout = timeout
93 self._metadata = metadata
94
95 def __getattr__(self, name: str) -> Any:
96 return getattr(self._response, name)
97
98 @property
99 def pages(self) -> Iterator[pubsub.ListTopicsResponse]:
100 yield self._response
101 while self._response.next_page_token:
102 self._request.page_token = self._response.next_page_token
103 self._response = self._method(
104 self._request,
105 retry=self._retry,
106 timeout=self._timeout,
107 metadata=self._metadata,
108 )
109 yield self._response
110
111 def __iter__(self) -> Iterator[pubsub.Topic]:
112 for page in self.pages:
113 yield from page.topics
114
115 def __repr__(self) -> str:
116 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
117
118
119class ListTopicsAsyncPager:
120 """A pager for iterating through ``list_topics`` requests.
121
122 This class thinly wraps an initial
123 :class:`google.pubsub_v1.types.ListTopicsResponse` object, and
124 provides an ``__aiter__`` method to iterate through its
125 ``topics`` field.
126
127 If there are more pages, the ``__aiter__`` method will make additional
128 ``ListTopics`` requests and continue to iterate
129 through the ``topics`` field on the
130 corresponding responses.
131
132 All the usual :class:`google.pubsub_v1.types.ListTopicsResponse`
133 attributes are available on the pager. If multiple requests are made, only
134 the most recent response is retained, and thus used for attribute lookup.
135 """
136
137 def __init__(
138 self,
139 method: Callable[..., Awaitable[pubsub.ListTopicsResponse]],
140 request: pubsub.ListTopicsRequest,
141 response: pubsub.ListTopicsResponse,
142 *,
143 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
144 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
145 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
146 ):
147 """Instantiates the pager.
148
149 Args:
150 method (Callable): The method that was originally called, and
151 which instantiated this pager.
152 request (google.pubsub_v1.types.ListTopicsRequest):
153 The initial request object.
154 response (google.pubsub_v1.types.ListTopicsResponse):
155 The initial response object.
156 retry (google.api_core.retry.AsyncRetry): Designation of what errors,
157 if any, should be retried.
158 timeout (float): The timeout for this request.
159 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
160 sent along with the request as metadata. Normally, each value must be of type `str`,
161 but for metadata keys ending with the suffix `-bin`, the corresponding values must
162 be of type `bytes`.
163 """
164 self._method = method
165 self._request = pubsub.ListTopicsRequest(request)
166 self._response = response
167 self._retry = retry
168 self._timeout = timeout
169 self._metadata = metadata
170
171 def __getattr__(self, name: str) -> Any:
172 return getattr(self._response, name)
173
174 @property
175 async def pages(self) -> AsyncIterator[pubsub.ListTopicsResponse]:
176 yield self._response
177 while self._response.next_page_token:
178 self._request.page_token = self._response.next_page_token
179 self._response = await self._method(
180 self._request,
181 retry=self._retry,
182 timeout=self._timeout,
183 metadata=self._metadata,
184 )
185 yield self._response
186
187 def __aiter__(self) -> AsyncIterator[pubsub.Topic]:
188 async def async_generator():
189 async for page in self.pages:
190 for response in page.topics:
191 yield response
192
193 return async_generator()
194
195 def __repr__(self) -> str:
196 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
197
198
199class ListTopicSubscriptionsPager:
200 """A pager for iterating through ``list_topic_subscriptions`` requests.
201
202 This class thinly wraps an initial
203 :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse` object, and
204 provides an ``__iter__`` method to iterate through its
205 ``subscriptions`` field.
206
207 If there are more pages, the ``__iter__`` method will make additional
208 ``ListTopicSubscriptions`` requests and continue to iterate
209 through the ``subscriptions`` field on the
210 corresponding responses.
211
212 All the usual :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse`
213 attributes are available on the pager. If multiple requests are made, only
214 the most recent response is retained, and thus used for attribute lookup.
215 """
216
217 def __init__(
218 self,
219 method: Callable[..., pubsub.ListTopicSubscriptionsResponse],
220 request: pubsub.ListTopicSubscriptionsRequest,
221 response: pubsub.ListTopicSubscriptionsResponse,
222 *,
223 retry: OptionalRetry = gapic_v1.method.DEFAULT,
224 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
225 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
226 ):
227 """Instantiate the pager.
228
229 Args:
230 method (Callable): The method that was originally called, and
231 which instantiated this pager.
232 request (google.pubsub_v1.types.ListTopicSubscriptionsRequest):
233 The initial request object.
234 response (google.pubsub_v1.types.ListTopicSubscriptionsResponse):
235 The initial response object.
236 retry (google.api_core.retry.Retry): Designation of what errors,
237 if any, should be retried.
238 timeout (float): The timeout for this request.
239 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
240 sent along with the request as metadata. Normally, each value must be of type `str`,
241 but for metadata keys ending with the suffix `-bin`, the corresponding values must
242 be of type `bytes`.
243 """
244 self._method = method
245 self._request = pubsub.ListTopicSubscriptionsRequest(request)
246 self._response = response
247 self._retry = retry
248 self._timeout = timeout
249 self._metadata = metadata
250
251 def __getattr__(self, name: str) -> Any:
252 return getattr(self._response, name)
253
254 @property
255 def pages(self) -> Iterator[pubsub.ListTopicSubscriptionsResponse]:
256 yield self._response
257 while self._response.next_page_token:
258 self._request.page_token = self._response.next_page_token
259 self._response = self._method(
260 self._request,
261 retry=self._retry,
262 timeout=self._timeout,
263 metadata=self._metadata,
264 )
265 yield self._response
266
267 def __iter__(self) -> Iterator[str]:
268 for page in self.pages:
269 yield from page.subscriptions
270
271 def __repr__(self) -> str:
272 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
273
274
275class ListTopicSubscriptionsAsyncPager:
276 """A pager for iterating through ``list_topic_subscriptions`` requests.
277
278 This class thinly wraps an initial
279 :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse` object, and
280 provides an ``__aiter__`` method to iterate through its
281 ``subscriptions`` field.
282
283 If there are more pages, the ``__aiter__`` method will make additional
284 ``ListTopicSubscriptions`` requests and continue to iterate
285 through the ``subscriptions`` field on the
286 corresponding responses.
287
288 All the usual :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse`
289 attributes are available on the pager. If multiple requests are made, only
290 the most recent response is retained, and thus used for attribute lookup.
291 """
292
293 def __init__(
294 self,
295 method: Callable[..., Awaitable[pubsub.ListTopicSubscriptionsResponse]],
296 request: pubsub.ListTopicSubscriptionsRequest,
297 response: pubsub.ListTopicSubscriptionsResponse,
298 *,
299 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
300 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
301 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
302 ):
303 """Instantiates the pager.
304
305 Args:
306 method (Callable): The method that was originally called, and
307 which instantiated this pager.
308 request (google.pubsub_v1.types.ListTopicSubscriptionsRequest):
309 The initial request object.
310 response (google.pubsub_v1.types.ListTopicSubscriptionsResponse):
311 The initial response object.
312 retry (google.api_core.retry.AsyncRetry): Designation of what errors,
313 if any, should be retried.
314 timeout (float): The timeout for this request.
315 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
316 sent along with the request as metadata. Normally, each value must be of type `str`,
317 but for metadata keys ending with the suffix `-bin`, the corresponding values must
318 be of type `bytes`.
319 """
320 self._method = method
321 self._request = pubsub.ListTopicSubscriptionsRequest(request)
322 self._response = response
323 self._retry = retry
324 self._timeout = timeout
325 self._metadata = metadata
326
327 def __getattr__(self, name: str) -> Any:
328 return getattr(self._response, name)
329
330 @property
331 async def pages(self) -> AsyncIterator[pubsub.ListTopicSubscriptionsResponse]:
332 yield self._response
333 while self._response.next_page_token:
334 self._request.page_token = self._response.next_page_token
335 self._response = await self._method(
336 self._request,
337 retry=self._retry,
338 timeout=self._timeout,
339 metadata=self._metadata,
340 )
341 yield self._response
342
343 def __aiter__(self) -> AsyncIterator[str]:
344 async def async_generator():
345 async for page in self.pages:
346 for response in page.subscriptions:
347 yield response
348
349 return async_generator()
350
351 def __repr__(self) -> str:
352 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
353
354
355class ListTopicSnapshotsPager:
356 """A pager for iterating through ``list_topic_snapshots`` requests.
357
358 This class thinly wraps an initial
359 :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse` object, and
360 provides an ``__iter__`` method to iterate through its
361 ``snapshots`` field.
362
363 If there are more pages, the ``__iter__`` method will make additional
364 ``ListTopicSnapshots`` requests and continue to iterate
365 through the ``snapshots`` field on the
366 corresponding responses.
367
368 All the usual :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse`
369 attributes are available on the pager. If multiple requests are made, only
370 the most recent response is retained, and thus used for attribute lookup.
371 """
372
373 def __init__(
374 self,
375 method: Callable[..., pubsub.ListTopicSnapshotsResponse],
376 request: pubsub.ListTopicSnapshotsRequest,
377 response: pubsub.ListTopicSnapshotsResponse,
378 *,
379 retry: OptionalRetry = gapic_v1.method.DEFAULT,
380 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
381 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
382 ):
383 """Instantiate the pager.
384
385 Args:
386 method (Callable): The method that was originally called, and
387 which instantiated this pager.
388 request (google.pubsub_v1.types.ListTopicSnapshotsRequest):
389 The initial request object.
390 response (google.pubsub_v1.types.ListTopicSnapshotsResponse):
391 The initial response object.
392 retry (google.api_core.retry.Retry): Designation of what errors,
393 if any, should be retried.
394 timeout (float): The timeout for this request.
395 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
396 sent along with the request as metadata. Normally, each value must be of type `str`,
397 but for metadata keys ending with the suffix `-bin`, the corresponding values must
398 be of type `bytes`.
399 """
400 self._method = method
401 self._request = pubsub.ListTopicSnapshotsRequest(request)
402 self._response = response
403 self._retry = retry
404 self._timeout = timeout
405 self._metadata = metadata
406
407 def __getattr__(self, name: str) -> Any:
408 return getattr(self._response, name)
409
410 @property
411 def pages(self) -> Iterator[pubsub.ListTopicSnapshotsResponse]:
412 yield self._response
413 while self._response.next_page_token:
414 self._request.page_token = self._response.next_page_token
415 self._response = self._method(
416 self._request,
417 retry=self._retry,
418 timeout=self._timeout,
419 metadata=self._metadata,
420 )
421 yield self._response
422
423 def __iter__(self) -> Iterator[str]:
424 for page in self.pages:
425 yield from page.snapshots
426
427 def __repr__(self) -> str:
428 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
429
430
431class ListTopicSnapshotsAsyncPager:
432 """A pager for iterating through ``list_topic_snapshots`` requests.
433
434 This class thinly wraps an initial
435 :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse` object, and
436 provides an ``__aiter__`` method to iterate through its
437 ``snapshots`` field.
438
439 If there are more pages, the ``__aiter__`` method will make additional
440 ``ListTopicSnapshots`` requests and continue to iterate
441 through the ``snapshots`` field on the
442 corresponding responses.
443
444 All the usual :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse`
445 attributes are available on the pager. If multiple requests are made, only
446 the most recent response is retained, and thus used for attribute lookup.
447 """
448
449 def __init__(
450 self,
451 method: Callable[..., Awaitable[pubsub.ListTopicSnapshotsResponse]],
452 request: pubsub.ListTopicSnapshotsRequest,
453 response: pubsub.ListTopicSnapshotsResponse,
454 *,
455 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT,
456 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
457 metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
458 ):
459 """Instantiates the pager.
460
461 Args:
462 method (Callable): The method that was originally called, and
463 which instantiated this pager.
464 request (google.pubsub_v1.types.ListTopicSnapshotsRequest):
465 The initial request object.
466 response (google.pubsub_v1.types.ListTopicSnapshotsResponse):
467 The initial response object.
468 retry (google.api_core.retry.AsyncRetry): Designation of what errors,
469 if any, should be retried.
470 timeout (float): The timeout for this request.
471 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
472 sent along with the request as metadata. Normally, each value must be of type `str`,
473 but for metadata keys ending with the suffix `-bin`, the corresponding values must
474 be of type `bytes`.
475 """
476 self._method = method
477 self._request = pubsub.ListTopicSnapshotsRequest(request)
478 self._response = response
479 self._retry = retry
480 self._timeout = timeout
481 self._metadata = metadata
482
483 def __getattr__(self, name: str) -> Any:
484 return getattr(self._response, name)
485
486 @property
487 async def pages(self) -> AsyncIterator[pubsub.ListTopicSnapshotsResponse]:
488 yield self._response
489 while self._response.next_page_token:
490 self._request.page_token = self._response.next_page_token
491 self._response = await self._method(
492 self._request,
493 retry=self._retry,
494 timeout=self._timeout,
495 metadata=self._metadata,
496 )
497 yield self._response
498
499 def __aiter__(self) -> AsyncIterator[str]:
500 async def async_generator():
501 async for page in self.pages:
502 for response in page.snapshots:
503 yield response
504
505 return async_generator()
506
507 def __repr__(self) -> str:
508 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)