Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/logging_v2/services/logging_service_v2/pagers.py: 35%
133 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +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.api import monitored_resource_pb2 # type: ignore
28from google.cloud.logging_v2.types import log_entry
29from google.cloud.logging_v2.types import logging
32class ListLogEntriesPager:
33 """A pager for iterating through ``list_log_entries`` requests.
35 This class thinly wraps an initial
36 :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and
37 provides an ``__iter__`` method to iterate through its
38 ``entries`` field.
40 If there are more pages, the ``__iter__`` method will make additional
41 ``ListLogEntries`` requests and continue to iterate
42 through the ``entries`` field on the
43 corresponding responses.
45 All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse`
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 """
50 def __init__(
51 self,
52 method: Callable[..., logging.ListLogEntriesResponse],
53 request: logging.ListLogEntriesRequest,
54 response: logging.ListLogEntriesResponse,
55 *,
56 metadata: Sequence[Tuple[str, str]] = ()
57 ):
58 """Instantiate the pager.
60 Args:
61 method (Callable): The method that was originally called, and
62 which instantiated this pager.
63 request (google.cloud.logging_v2.types.ListLogEntriesRequest):
64 The initial request object.
65 response (google.cloud.logging_v2.types.ListLogEntriesResponse):
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 = logging.ListLogEntriesRequest(request)
72 self._response = response
73 self._metadata = metadata
75 def __getattr__(self, name: str) -> Any:
76 return getattr(self._response, name)
78 @property
79 def pages(self) -> Iterator[logging.ListLogEntriesResponse]:
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
86 def __iter__(self) -> Iterator[log_entry.LogEntry]:
87 for page in self.pages:
88 yield from page.entries
90 def __repr__(self) -> str:
91 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
94class ListLogEntriesAsyncPager:
95 """A pager for iterating through ``list_log_entries`` requests.
97 This class thinly wraps an initial
98 :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and
99 provides an ``__aiter__`` method to iterate through its
100 ``entries`` field.
102 If there are more pages, the ``__aiter__`` method will make additional
103 ``ListLogEntries`` requests and continue to iterate
104 through the ``entries`` field on the
105 corresponding responses.
107 All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse`
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 """
112 def __init__(
113 self,
114 method: Callable[..., Awaitable[logging.ListLogEntriesResponse]],
115 request: logging.ListLogEntriesRequest,
116 response: logging.ListLogEntriesResponse,
117 *,
118 metadata: Sequence[Tuple[str, str]] = ()
119 ):
120 """Instantiates the pager.
122 Args:
123 method (Callable): The method that was originally called, and
124 which instantiated this pager.
125 request (google.cloud.logging_v2.types.ListLogEntriesRequest):
126 The initial request object.
127 response (google.cloud.logging_v2.types.ListLogEntriesResponse):
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 = logging.ListLogEntriesRequest(request)
134 self._response = response
135 self._metadata = metadata
137 def __getattr__(self, name: str) -> Any:
138 return getattr(self._response, name)
140 @property
141 async def pages(self) -> AsyncIterator[logging.ListLogEntriesResponse]:
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
148 def __aiter__(self) -> AsyncIterator[log_entry.LogEntry]:
149 async def async_generator():
150 async for page in self.pages:
151 for response in page.entries:
152 yield response
154 return async_generator()
156 def __repr__(self) -> str:
157 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
160class ListMonitoredResourceDescriptorsPager:
161 """A pager for iterating through ``list_monitored_resource_descriptors`` requests.
163 This class thinly wraps an initial
164 :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and
165 provides an ``__iter__`` method to iterate through its
166 ``resource_descriptors`` field.
168 If there are more pages, the ``__iter__`` method will make additional
169 ``ListMonitoredResourceDescriptors`` requests and continue to iterate
170 through the ``resource_descriptors`` field on the
171 corresponding responses.
173 All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse`
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 """
178 def __init__(
179 self,
180 method: Callable[..., logging.ListMonitoredResourceDescriptorsResponse],
181 request: logging.ListMonitoredResourceDescriptorsRequest,
182 response: logging.ListMonitoredResourceDescriptorsResponse,
183 *,
184 metadata: Sequence[Tuple[str, str]] = ()
185 ):
186 """Instantiate the pager.
188 Args:
189 method (Callable): The method that was originally called, and
190 which instantiated this pager.
191 request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest):
192 The initial request object.
193 response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse):
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 = logging.ListMonitoredResourceDescriptorsRequest(request)
200 self._response = response
201 self._metadata = metadata
203 def __getattr__(self, name: str) -> Any:
204 return getattr(self._response, name)
206 @property
207 def pages(self) -> Iterator[logging.ListMonitoredResourceDescriptorsResponse]:
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
214 def __iter__(self) -> Iterator[monitored_resource_pb2.MonitoredResourceDescriptor]:
215 for page in self.pages:
216 yield from page.resource_descriptors
218 def __repr__(self) -> str:
219 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
222class ListMonitoredResourceDescriptorsAsyncPager:
223 """A pager for iterating through ``list_monitored_resource_descriptors`` requests.
225 This class thinly wraps an initial
226 :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and
227 provides an ``__aiter__`` method to iterate through its
228 ``resource_descriptors`` field.
230 If there are more pages, the ``__aiter__`` method will make additional
231 ``ListMonitoredResourceDescriptors`` requests and continue to iterate
232 through the ``resource_descriptors`` field on the
233 corresponding responses.
235 All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse`
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 """
240 def __init__(
241 self,
242 method: Callable[
243 ..., Awaitable[logging.ListMonitoredResourceDescriptorsResponse]
244 ],
245 request: logging.ListMonitoredResourceDescriptorsRequest,
246 response: logging.ListMonitoredResourceDescriptorsResponse,
247 *,
248 metadata: Sequence[Tuple[str, str]] = ()
249 ):
250 """Instantiates the pager.
252 Args:
253 method (Callable): The method that was originally called, and
254 which instantiated this pager.
255 request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest):
256 The initial request object.
257 response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse):
258 The initial response object.
259 metadata (Sequence[Tuple[str, str]]): Strings which should be
260 sent along with the request as metadata.
261 """
262 self._method = method
263 self._request = logging.ListMonitoredResourceDescriptorsRequest(request)
264 self._response = response
265 self._metadata = metadata
267 def __getattr__(self, name: str) -> Any:
268 return getattr(self._response, name)
270 @property
271 async def pages(
272 self,
273 ) -> AsyncIterator[logging.ListMonitoredResourceDescriptorsResponse]:
274 yield self._response
275 while self._response.next_page_token:
276 self._request.page_token = self._response.next_page_token
277 self._response = await self._method(self._request, metadata=self._metadata)
278 yield self._response
280 def __aiter__(
281 self,
282 ) -> AsyncIterator[monitored_resource_pb2.MonitoredResourceDescriptor]:
283 async def async_generator():
284 async for page in self.pages:
285 for response in page.resource_descriptors:
286 yield response
288 return async_generator()
290 def __repr__(self) -> str:
291 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
294class ListLogsPager:
295 """A pager for iterating through ``list_logs`` requests.
297 This class thinly wraps an initial
298 :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and
299 provides an ``__iter__`` method to iterate through its
300 ``log_names`` field.
302 If there are more pages, the ``__iter__`` method will make additional
303 ``ListLogs`` requests and continue to iterate
304 through the ``log_names`` field on the
305 corresponding responses.
307 All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse`
308 attributes are available on the pager. If multiple requests are made, only
309 the most recent response is retained, and thus used for attribute lookup.
310 """
312 def __init__(
313 self,
314 method: Callable[..., logging.ListLogsResponse],
315 request: logging.ListLogsRequest,
316 response: logging.ListLogsResponse,
317 *,
318 metadata: Sequence[Tuple[str, str]] = ()
319 ):
320 """Instantiate the pager.
322 Args:
323 method (Callable): The method that was originally called, and
324 which instantiated this pager.
325 request (google.cloud.logging_v2.types.ListLogsRequest):
326 The initial request object.
327 response (google.cloud.logging_v2.types.ListLogsResponse):
328 The initial response object.
329 metadata (Sequence[Tuple[str, str]]): Strings which should be
330 sent along with the request as metadata.
331 """
332 self._method = method
333 self._request = logging.ListLogsRequest(request)
334 self._response = response
335 self._metadata = metadata
337 def __getattr__(self, name: str) -> Any:
338 return getattr(self._response, name)
340 @property
341 def pages(self) -> Iterator[logging.ListLogsResponse]:
342 yield self._response
343 while self._response.next_page_token:
344 self._request.page_token = self._response.next_page_token
345 self._response = self._method(self._request, metadata=self._metadata)
346 yield self._response
348 def __iter__(self) -> Iterator[str]:
349 for page in self.pages:
350 yield from page.log_names
352 def __repr__(self) -> str:
353 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)
356class ListLogsAsyncPager:
357 """A pager for iterating through ``list_logs`` requests.
359 This class thinly wraps an initial
360 :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and
361 provides an ``__aiter__`` method to iterate through its
362 ``log_names`` field.
364 If there are more pages, the ``__aiter__`` method will make additional
365 ``ListLogs`` requests and continue to iterate
366 through the ``log_names`` field on the
367 corresponding responses.
369 All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse`
370 attributes are available on the pager. If multiple requests are made, only
371 the most recent response is retained, and thus used for attribute lookup.
372 """
374 def __init__(
375 self,
376 method: Callable[..., Awaitable[logging.ListLogsResponse]],
377 request: logging.ListLogsRequest,
378 response: logging.ListLogsResponse,
379 *,
380 metadata: Sequence[Tuple[str, str]] = ()
381 ):
382 """Instantiates the pager.
384 Args:
385 method (Callable): The method that was originally called, and
386 which instantiated this pager.
387 request (google.cloud.logging_v2.types.ListLogsRequest):
388 The initial request object.
389 response (google.cloud.logging_v2.types.ListLogsResponse):
390 The initial response object.
391 metadata (Sequence[Tuple[str, str]]): Strings which should be
392 sent along with the request as metadata.
393 """
394 self._method = method
395 self._request = logging.ListLogsRequest(request)
396 self._response = response
397 self._metadata = metadata
399 def __getattr__(self, name: str) -> Any:
400 return getattr(self._response, name)
402 @property
403 async def pages(self) -> AsyncIterator[logging.ListLogsResponse]:
404 yield self._response
405 while self._response.next_page_token:
406 self._request.page_token = self._response.next_page_token
407 self._response = await self._method(self._request, metadata=self._metadata)
408 yield self._response
410 def __aiter__(self) -> AsyncIterator[str]:
411 async def async_generator():
412 async for page in self.pages:
413 for response in page.log_names:
414 yield response
416 return async_generator()
418 def __repr__(self) -> str:
419 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)