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 schema
41
42
43class ListSchemasPager:
44 """A pager for iterating through ``list_schemas`` requests.
45
46 This class thinly wraps an initial
47 :class:`google.pubsub_v1.types.ListSchemasResponse` object, and
48 provides an ``__iter__`` method to iterate through its
49 ``schemas`` field.
50
51 If there are more pages, the ``__iter__`` method will make additional
52 ``ListSchemas`` requests and continue to iterate
53 through the ``schemas`` field on the
54 corresponding responses.
55
56 All the usual :class:`google.pubsub_v1.types.ListSchemasResponse`
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[..., schema.ListSchemasResponse],
64 request: schema.ListSchemasRequest,
65 response: schema.ListSchemasResponse,
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.ListSchemasRequest):
77 The initial request object.
78 response (google.pubsub_v1.types.ListSchemasResponse):
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 = schema.ListSchemasRequest(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[schema.ListSchemasResponse]:
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[schema.Schema]:
112 for page in self.pages:
113 yield from page.schemas
114
115 def __repr__(self) -> str:
116 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
117
118
119class ListSchemasAsyncPager:
120 """A pager for iterating through ``list_schemas`` requests.
121
122 This class thinly wraps an initial
123 :class:`google.pubsub_v1.types.ListSchemasResponse` object, and
124 provides an ``__aiter__`` method to iterate through its
125 ``schemas`` field.
126
127 If there are more pages, the ``__aiter__`` method will make additional
128 ``ListSchemas`` requests and continue to iterate
129 through the ``schemas`` field on the
130 corresponding responses.
131
132 All the usual :class:`google.pubsub_v1.types.ListSchemasResponse`
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[schema.ListSchemasResponse]],
140 request: schema.ListSchemasRequest,
141 response: schema.ListSchemasResponse,
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.ListSchemasRequest):
153 The initial request object.
154 response (google.pubsub_v1.types.ListSchemasResponse):
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 = schema.ListSchemasRequest(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[schema.ListSchemasResponse]:
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[schema.Schema]:
188 async def async_generator():
189 async for page in self.pages:
190 for response in page.schemas:
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 ListSchemaRevisionsPager:
200 """A pager for iterating through ``list_schema_revisions`` requests.
201
202 This class thinly wraps an initial
203 :class:`google.pubsub_v1.types.ListSchemaRevisionsResponse` object, and
204 provides an ``__iter__`` method to iterate through its
205 ``schemas`` field.
206
207 If there are more pages, the ``__iter__`` method will make additional
208 ``ListSchemaRevisions`` requests and continue to iterate
209 through the ``schemas`` field on the
210 corresponding responses.
211
212 All the usual :class:`google.pubsub_v1.types.ListSchemaRevisionsResponse`
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[..., schema.ListSchemaRevisionsResponse],
220 request: schema.ListSchemaRevisionsRequest,
221 response: schema.ListSchemaRevisionsResponse,
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.ListSchemaRevisionsRequest):
233 The initial request object.
234 response (google.pubsub_v1.types.ListSchemaRevisionsResponse):
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 = schema.ListSchemaRevisionsRequest(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[schema.ListSchemaRevisionsResponse]:
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[schema.Schema]:
268 for page in self.pages:
269 yield from page.schemas
270
271 def __repr__(self) -> str:
272 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
273
274
275class ListSchemaRevisionsAsyncPager:
276 """A pager for iterating through ``list_schema_revisions`` requests.
277
278 This class thinly wraps an initial
279 :class:`google.pubsub_v1.types.ListSchemaRevisionsResponse` object, and
280 provides an ``__aiter__`` method to iterate through its
281 ``schemas`` field.
282
283 If there are more pages, the ``__aiter__`` method will make additional
284 ``ListSchemaRevisions`` requests and continue to iterate
285 through the ``schemas`` field on the
286 corresponding responses.
287
288 All the usual :class:`google.pubsub_v1.types.ListSchemaRevisionsResponse`
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[schema.ListSchemaRevisionsResponse]],
296 request: schema.ListSchemaRevisionsRequest,
297 response: schema.ListSchemaRevisionsResponse,
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.ListSchemaRevisionsRequest):
309 The initial request object.
310 response (google.pubsub_v1.types.ListSchemaRevisionsResponse):
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 = schema.ListSchemaRevisionsRequest(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[schema.ListSchemaRevisionsResponse]:
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[schema.Schema]:
344 async def async_generator():
345 async for page in self.pages:
346 for response in page.schemas:
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)