Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/publisher/pagers.py: 34%
131 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:25 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:25 +0000
1# -*- coding: utf-8 -*-
2# Copyright 2022 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)
27from google.pubsub_v1.types import pubsub
30class ListTopicsPager:
31 """A pager for iterating through ``list_topics`` requests.
33 This class thinly wraps an initial
34 :class:`google.pubsub_v1.types.ListTopicsResponse` object, and
35 provides an ``__iter__`` method to iterate through its
36 ``topics`` field.
38 If there are more pages, the ``__iter__`` method will make additional
39 ``ListTopics`` requests and continue to iterate
40 through the ``topics`` field on the
41 corresponding responses.
43 All the usual :class:`google.pubsub_v1.types.ListTopicsResponse`
44 attributes are available on the pager. If multiple requests are made, only
45 the most recent response is retained, and thus used for attribute lookup.
46 """
48 def __init__(
49 self,
50 method: Callable[..., pubsub.ListTopicsResponse],
51 request: pubsub.ListTopicsRequest,
52 response: pubsub.ListTopicsResponse,
53 *,
54 metadata: Sequence[Tuple[str, str]] = ()
55 ):
56 """Instantiate the pager.
58 Args:
59 method (Callable): The method that was originally called, and
60 which instantiated this pager.
61 request (google.pubsub_v1.types.ListTopicsRequest):
62 The initial request object.
63 response (google.pubsub_v1.types.ListTopicsResponse):
64 The initial response object.
65 metadata (Sequence[Tuple[str, str]]): Strings which should be
66 sent along with the request as metadata.
67 """
68 self._method = method
69 self._request = pubsub.ListTopicsRequest(request)
70 self._response = response
71 self._metadata = metadata
73 def __getattr__(self, name: str) -> Any:
74 return getattr(self._response, name)
76 @property
77 def pages(self) -> Iterator[pubsub.ListTopicsResponse]:
78 yield self._response
79 while self._response.next_page_token:
80 self._request.page_token = self._response.next_page_token
81 self._response = self._method(self._request, metadata=self._metadata)
82 yield self._response
84 def __iter__(self) -> Iterator[pubsub.Topic]:
85 for page in self.pages:
86 yield from page.topics
88 def __repr__(self) -> str:
89 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
92class ListTopicsAsyncPager:
93 """A pager for iterating through ``list_topics`` requests.
95 This class thinly wraps an initial
96 :class:`google.pubsub_v1.types.ListTopicsResponse` object, and
97 provides an ``__aiter__`` method to iterate through its
98 ``topics`` field.
100 If there are more pages, the ``__aiter__`` method will make additional
101 ``ListTopics`` requests and continue to iterate
102 through the ``topics`` field on the
103 corresponding responses.
105 All the usual :class:`google.pubsub_v1.types.ListTopicsResponse`
106 attributes are available on the pager. If multiple requests are made, only
107 the most recent response is retained, and thus used for attribute lookup.
108 """
110 def __init__(
111 self,
112 method: Callable[..., Awaitable[pubsub.ListTopicsResponse]],
113 request: pubsub.ListTopicsRequest,
114 response: pubsub.ListTopicsResponse,
115 *,
116 metadata: Sequence[Tuple[str, str]] = ()
117 ):
118 """Instantiates the pager.
120 Args:
121 method (Callable): The method that was originally called, and
122 which instantiated this pager.
123 request (google.pubsub_v1.types.ListTopicsRequest):
124 The initial request object.
125 response (google.pubsub_v1.types.ListTopicsResponse):
126 The initial response object.
127 metadata (Sequence[Tuple[str, str]]): Strings which should be
128 sent along with the request as metadata.
129 """
130 self._method = method
131 self._request = pubsub.ListTopicsRequest(request)
132 self._response = response
133 self._metadata = metadata
135 def __getattr__(self, name: str) -> Any:
136 return getattr(self._response, name)
138 @property
139 async def pages(self) -> AsyncIterator[pubsub.ListTopicsResponse]:
140 yield self._response
141 while self._response.next_page_token:
142 self._request.page_token = self._response.next_page_token
143 self._response = await self._method(self._request, metadata=self._metadata)
144 yield self._response
146 def __aiter__(self) -> AsyncIterator[pubsub.Topic]:
147 async def async_generator():
148 async for page in self.pages:
149 for response in page.topics:
150 yield response
152 return async_generator()
154 def __repr__(self) -> str:
155 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
158class ListTopicSubscriptionsPager:
159 """A pager for iterating through ``list_topic_subscriptions`` requests.
161 This class thinly wraps an initial
162 :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse` object, and
163 provides an ``__iter__`` method to iterate through its
164 ``subscriptions`` field.
166 If there are more pages, the ``__iter__`` method will make additional
167 ``ListTopicSubscriptions`` requests and continue to iterate
168 through the ``subscriptions`` field on the
169 corresponding responses.
171 All the usual :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse`
172 attributes are available on the pager. If multiple requests are made, only
173 the most recent response is retained, and thus used for attribute lookup.
174 """
176 def __init__(
177 self,
178 method: Callable[..., pubsub.ListTopicSubscriptionsResponse],
179 request: pubsub.ListTopicSubscriptionsRequest,
180 response: pubsub.ListTopicSubscriptionsResponse,
181 *,
182 metadata: Sequence[Tuple[str, str]] = ()
183 ):
184 """Instantiate the pager.
186 Args:
187 method (Callable): The method that was originally called, and
188 which instantiated this pager.
189 request (google.pubsub_v1.types.ListTopicSubscriptionsRequest):
190 The initial request object.
191 response (google.pubsub_v1.types.ListTopicSubscriptionsResponse):
192 The initial response object.
193 metadata (Sequence[Tuple[str, str]]): Strings which should be
194 sent along with the request as metadata.
195 """
196 self._method = method
197 self._request = pubsub.ListTopicSubscriptionsRequest(request)
198 self._response = response
199 self._metadata = metadata
201 def __getattr__(self, name: str) -> Any:
202 return getattr(self._response, name)
204 @property
205 def pages(self) -> Iterator[pubsub.ListTopicSubscriptionsResponse]:
206 yield self._response
207 while self._response.next_page_token:
208 self._request.page_token = self._response.next_page_token
209 self._response = self._method(self._request, metadata=self._metadata)
210 yield self._response
212 def __iter__(self) -> Iterator[str]:
213 for page in self.pages:
214 yield from page.subscriptions
216 def __repr__(self) -> str:
217 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
220class ListTopicSubscriptionsAsyncPager:
221 """A pager for iterating through ``list_topic_subscriptions`` requests.
223 This class thinly wraps an initial
224 :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse` object, and
225 provides an ``__aiter__`` method to iterate through its
226 ``subscriptions`` field.
228 If there are more pages, the ``__aiter__`` method will make additional
229 ``ListTopicSubscriptions`` requests and continue to iterate
230 through the ``subscriptions`` field on the
231 corresponding responses.
233 All the usual :class:`google.pubsub_v1.types.ListTopicSubscriptionsResponse`
234 attributes are available on the pager. If multiple requests are made, only
235 the most recent response is retained, and thus used for attribute lookup.
236 """
238 def __init__(
239 self,
240 method: Callable[..., Awaitable[pubsub.ListTopicSubscriptionsResponse]],
241 request: pubsub.ListTopicSubscriptionsRequest,
242 response: pubsub.ListTopicSubscriptionsResponse,
243 *,
244 metadata: Sequence[Tuple[str, str]] = ()
245 ):
246 """Instantiates the pager.
248 Args:
249 method (Callable): The method that was originally called, and
250 which instantiated this pager.
251 request (google.pubsub_v1.types.ListTopicSubscriptionsRequest):
252 The initial request object.
253 response (google.pubsub_v1.types.ListTopicSubscriptionsResponse):
254 The initial response object.
255 metadata (Sequence[Tuple[str, str]]): Strings which should be
256 sent along with the request as metadata.
257 """
258 self._method = method
259 self._request = pubsub.ListTopicSubscriptionsRequest(request)
260 self._response = response
261 self._metadata = metadata
263 def __getattr__(self, name: str) -> Any:
264 return getattr(self._response, name)
266 @property
267 async def pages(self) -> AsyncIterator[pubsub.ListTopicSubscriptionsResponse]:
268 yield self._response
269 while self._response.next_page_token:
270 self._request.page_token = self._response.next_page_token
271 self._response = await self._method(self._request, metadata=self._metadata)
272 yield self._response
274 def __aiter__(self) -> AsyncIterator[str]:
275 async def async_generator():
276 async for page in self.pages:
277 for response in page.subscriptions:
278 yield response
280 return async_generator()
282 def __repr__(self) -> str:
283 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
286class ListTopicSnapshotsPager:
287 """A pager for iterating through ``list_topic_snapshots`` requests.
289 This class thinly wraps an initial
290 :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse` object, and
291 provides an ``__iter__`` method to iterate through its
292 ``snapshots`` field.
294 If there are more pages, the ``__iter__`` method will make additional
295 ``ListTopicSnapshots`` requests and continue to iterate
296 through the ``snapshots`` field on the
297 corresponding responses.
299 All the usual :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse`
300 attributes are available on the pager. If multiple requests are made, only
301 the most recent response is retained, and thus used for attribute lookup.
302 """
304 def __init__(
305 self,
306 method: Callable[..., pubsub.ListTopicSnapshotsResponse],
307 request: pubsub.ListTopicSnapshotsRequest,
308 response: pubsub.ListTopicSnapshotsResponse,
309 *,
310 metadata: Sequence[Tuple[str, str]] = ()
311 ):
312 """Instantiate the pager.
314 Args:
315 method (Callable): The method that was originally called, and
316 which instantiated this pager.
317 request (google.pubsub_v1.types.ListTopicSnapshotsRequest):
318 The initial request object.
319 response (google.pubsub_v1.types.ListTopicSnapshotsResponse):
320 The initial response object.
321 metadata (Sequence[Tuple[str, str]]): Strings which should be
322 sent along with the request as metadata.
323 """
324 self._method = method
325 self._request = pubsub.ListTopicSnapshotsRequest(request)
326 self._response = response
327 self._metadata = metadata
329 def __getattr__(self, name: str) -> Any:
330 return getattr(self._response, name)
332 @property
333 def pages(self) -> Iterator[pubsub.ListTopicSnapshotsResponse]:
334 yield self._response
335 while self._response.next_page_token:
336 self._request.page_token = self._response.next_page_token
337 self._response = self._method(self._request, metadata=self._metadata)
338 yield self._response
340 def __iter__(self) -> Iterator[str]:
341 for page in self.pages:
342 yield from page.snapshots
344 def __repr__(self) -> str:
345 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
348class ListTopicSnapshotsAsyncPager:
349 """A pager for iterating through ``list_topic_snapshots`` requests.
351 This class thinly wraps an initial
352 :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse` object, and
353 provides an ``__aiter__`` method to iterate through its
354 ``snapshots`` field.
356 If there are more pages, the ``__aiter__`` method will make additional
357 ``ListTopicSnapshots`` requests and continue to iterate
358 through the ``snapshots`` field on the
359 corresponding responses.
361 All the usual :class:`google.pubsub_v1.types.ListTopicSnapshotsResponse`
362 attributes are available on the pager. If multiple requests are made, only
363 the most recent response is retained, and thus used for attribute lookup.
364 """
366 def __init__(
367 self,
368 method: Callable[..., Awaitable[pubsub.ListTopicSnapshotsResponse]],
369 request: pubsub.ListTopicSnapshotsRequest,
370 response: pubsub.ListTopicSnapshotsResponse,
371 *,
372 metadata: Sequence[Tuple[str, str]] = ()
373 ):
374 """Instantiates the pager.
376 Args:
377 method (Callable): The method that was originally called, and
378 which instantiated this pager.
379 request (google.pubsub_v1.types.ListTopicSnapshotsRequest):
380 The initial request object.
381 response (google.pubsub_v1.types.ListTopicSnapshotsResponse):
382 The initial response object.
383 metadata (Sequence[Tuple[str, str]]): Strings which should be
384 sent along with the request as metadata.
385 """
386 self._method = method
387 self._request = pubsub.ListTopicSnapshotsRequest(request)
388 self._response = response
389 self._metadata = metadata
391 def __getattr__(self, name: str) -> Any:
392 return getattr(self._response, name)
394 @property
395 async def pages(self) -> AsyncIterator[pubsub.ListTopicSnapshotsResponse]:
396 yield self._response
397 while self._response.next_page_token:
398 self._request.page_token = self._response.next_page_token
399 self._response = await self._method(self._request, metadata=self._metadata)
400 yield self._response
402 def __aiter__(self) -> AsyncIterator[str]:
403 async def async_generator():
404 async for page in self.pages:
405 for response in page.snapshots:
406 yield response
408 return async_generator()
410 def __repr__(self) -> str:
411 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)