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.errorreporting_v1beta1.types import common
28from google.cloud.errorreporting_v1beta1.types import error_stats_service
29
30
31class ListGroupStatsPager:
32 """A pager for iterating through ``list_group_stats`` requests.
33
34 This class thinly wraps an initial
35 :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` object, and
36 provides an ``__iter__`` method to iterate through its
37 ``error_group_stats`` field.
38
39 If there are more pages, the ``__iter__`` method will make additional
40 ``ListGroupStats`` requests and continue to iterate
41 through the ``error_group_stats`` field on the
42 corresponding responses.
43
44 All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse`
45 attributes are available on the pager. If multiple requests are made, only
46 the most recent response is retained, and thus used for attribute lookup.
47 """
48
49 def __init__(
50 self,
51 method: Callable[..., error_stats_service.ListGroupStatsResponse],
52 request: error_stats_service.ListGroupStatsRequest,
53 response: error_stats_service.ListGroupStatsResponse,
54 *,
55 metadata: Sequence[Tuple[str, str]] = ()
56 ):
57 """Instantiate the pager.
58
59 Args:
60 method (Callable): The method that was originally called, and
61 which instantiated this pager.
62 request (google.cloud.errorreporting_v1beta1.types.ListGroupStatsRequest):
63 The initial request object.
64 response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse):
65 The initial response object.
66 metadata (Sequence[Tuple[str, str]]): Strings which should be
67 sent along with the request as metadata.
68 """
69 self._method = method
70 self._request = error_stats_service.ListGroupStatsRequest(request)
71 self._response = response
72 self._metadata = metadata
73
74 def __getattr__(self, name: str) -> Any:
75 return getattr(self._response, name)
76
77 @property
78 def pages(self) -> Iterator[error_stats_service.ListGroupStatsResponse]:
79 yield self._response
80 while self._response.next_page_token:
81 self._request.page_token = self._response.next_page_token
82 self._response = self._method(self._request, metadata=self._metadata)
83 yield self._response
84
85 def __iter__(self) -> Iterator[error_stats_service.ErrorGroupStats]:
86 for page in self.pages:
87 yield from page.error_group_stats
88
89 def __repr__(self) -> str:
90 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
91
92
93class ListGroupStatsAsyncPager:
94 """A pager for iterating through ``list_group_stats`` requests.
95
96 This class thinly wraps an initial
97 :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` object, and
98 provides an ``__aiter__`` method to iterate through its
99 ``error_group_stats`` field.
100
101 If there are more pages, the ``__aiter__`` method will make additional
102 ``ListGroupStats`` requests and continue to iterate
103 through the ``error_group_stats`` field on the
104 corresponding responses.
105
106 All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse`
107 attributes are available on the pager. If multiple requests are made, only
108 the most recent response is retained, and thus used for attribute lookup.
109 """
110
111 def __init__(
112 self,
113 method: Callable[..., Awaitable[error_stats_service.ListGroupStatsResponse]],
114 request: error_stats_service.ListGroupStatsRequest,
115 response: error_stats_service.ListGroupStatsResponse,
116 *,
117 metadata: Sequence[Tuple[str, str]] = ()
118 ):
119 """Instantiates the pager.
120
121 Args:
122 method (Callable): The method that was originally called, and
123 which instantiated this pager.
124 request (google.cloud.errorreporting_v1beta1.types.ListGroupStatsRequest):
125 The initial request object.
126 response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse):
127 The initial response object.
128 metadata (Sequence[Tuple[str, str]]): Strings which should be
129 sent along with the request as metadata.
130 """
131 self._method = method
132 self._request = error_stats_service.ListGroupStatsRequest(request)
133 self._response = response
134 self._metadata = metadata
135
136 def __getattr__(self, name: str) -> Any:
137 return getattr(self._response, name)
138
139 @property
140 async def pages(self) -> AsyncIterator[error_stats_service.ListGroupStatsResponse]:
141 yield self._response
142 while self._response.next_page_token:
143 self._request.page_token = self._response.next_page_token
144 self._response = await self._method(self._request, metadata=self._metadata)
145 yield self._response
146
147 def __aiter__(self) -> AsyncIterator[error_stats_service.ErrorGroupStats]:
148 async def async_generator():
149 async for page in self.pages:
150 for response in page.error_group_stats:
151 yield response
152
153 return async_generator()
154
155 def __repr__(self) -> str:
156 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
157
158
159class ListEventsPager:
160 """A pager for iterating through ``list_events`` requests.
161
162 This class thinly wraps an initial
163 :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` object, and
164 provides an ``__iter__`` method to iterate through its
165 ``error_events`` field.
166
167 If there are more pages, the ``__iter__`` method will make additional
168 ``ListEvents`` requests and continue to iterate
169 through the ``error_events`` field on the
170 corresponding responses.
171
172 All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse`
173 attributes are available on the pager. If multiple requests are made, only
174 the most recent response is retained, and thus used for attribute lookup.
175 """
176
177 def __init__(
178 self,
179 method: Callable[..., error_stats_service.ListEventsResponse],
180 request: error_stats_service.ListEventsRequest,
181 response: error_stats_service.ListEventsResponse,
182 *,
183 metadata: Sequence[Tuple[str, str]] = ()
184 ):
185 """Instantiate the pager.
186
187 Args:
188 method (Callable): The method that was originally called, and
189 which instantiated this pager.
190 request (google.cloud.errorreporting_v1beta1.types.ListEventsRequest):
191 The initial request object.
192 response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse):
193 The initial response object.
194 metadata (Sequence[Tuple[str, str]]): Strings which should be
195 sent along with the request as metadata.
196 """
197 self._method = method
198 self._request = error_stats_service.ListEventsRequest(request)
199 self._response = response
200 self._metadata = metadata
201
202 def __getattr__(self, name: str) -> Any:
203 return getattr(self._response, name)
204
205 @property
206 def pages(self) -> Iterator[error_stats_service.ListEventsResponse]:
207 yield self._response
208 while self._response.next_page_token:
209 self._request.page_token = self._response.next_page_token
210 self._response = self._method(self._request, metadata=self._metadata)
211 yield self._response
212
213 def __iter__(self) -> Iterator[common.ErrorEvent]:
214 for page in self.pages:
215 yield from page.error_events
216
217 def __repr__(self) -> str:
218 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
219
220
221class ListEventsAsyncPager:
222 """A pager for iterating through ``list_events`` requests.
223
224 This class thinly wraps an initial
225 :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` object, and
226 provides an ``__aiter__`` method to iterate through its
227 ``error_events`` field.
228
229 If there are more pages, the ``__aiter__`` method will make additional
230 ``ListEvents`` requests and continue to iterate
231 through the ``error_events`` field on the
232 corresponding responses.
233
234 All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse`
235 attributes are available on the pager. If multiple requests are made, only
236 the most recent response is retained, and thus used for attribute lookup.
237 """
238
239 def __init__(
240 self,
241 method: Callable[..., Awaitable[error_stats_service.ListEventsResponse]],
242 request: error_stats_service.ListEventsRequest,
243 response: error_stats_service.ListEventsResponse,
244 *,
245 metadata: Sequence[Tuple[str, str]] = ()
246 ):
247 """Instantiates the pager.
248
249 Args:
250 method (Callable): The method that was originally called, and
251 which instantiated this pager.
252 request (google.cloud.errorreporting_v1beta1.types.ListEventsRequest):
253 The initial request object.
254 response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse):
255 The initial response object.
256 metadata (Sequence[Tuple[str, str]]): Strings which should be
257 sent along with the request as metadata.
258 """
259 self._method = method
260 self._request = error_stats_service.ListEventsRequest(request)
261 self._response = response
262 self._metadata = metadata
263
264 def __getattr__(self, name: str) -> Any:
265 return getattr(self._response, name)
266
267 @property
268 async def pages(self) -> AsyncIterator[error_stats_service.ListEventsResponse]:
269 yield self._response
270 while self._response.next_page_token:
271 self._request.page_token = self._response.next_page_token
272 self._response = await self._method(self._request, metadata=self._metadata)
273 yield self._response
274
275 def __aiter__(self) -> AsyncIterator[common.ErrorEvent]:
276 async def async_generator():
277 async for page in self.pages:
278 for response in page.error_events:
279 yield response
280
281 return async_generator()
282
283 def __repr__(self) -> str:
284 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)