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.cloud.errorreporting_v1beta1.types import common 
    41from google.cloud.errorreporting_v1beta1.types import error_stats_service 
    42 
    43 
    44class ListGroupStatsPager: 
    45    """A pager for iterating through ``list_group_stats`` requests. 
    46 
    47    This class thinly wraps an initial 
    48    :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` object, and 
    49    provides an ``__iter__`` method to iterate through its 
    50    ``error_group_stats`` field. 
    51 
    52    If there are more pages, the ``__iter__`` method will make additional 
    53    ``ListGroupStats`` requests and continue to iterate 
    54    through the ``error_group_stats`` field on the 
    55    corresponding responses. 
    56 
    57    All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` 
    58    attributes are available on the pager. If multiple requests are made, only 
    59    the most recent response is retained, and thus used for attribute lookup. 
    60    """ 
    61 
    62    def __init__( 
    63        self, 
    64        method: Callable[..., error_stats_service.ListGroupStatsResponse], 
    65        request: error_stats_service.ListGroupStatsRequest, 
    66        response: error_stats_service.ListGroupStatsResponse, 
    67        *, 
    68        retry: OptionalRetry = gapic_v1.method.DEFAULT, 
    69        timeout: Union[float, object] = gapic_v1.method.DEFAULT, 
    70        metadata: Sequence[Tuple[str, Union[str, bytes]]] = () 
    71    ): 
    72        """Instantiate the pager. 
    73 
    74        Args: 
    75            method (Callable): The method that was originally called, and 
    76                which instantiated this pager. 
    77            request (google.cloud.errorreporting_v1beta1.types.ListGroupStatsRequest): 
    78                The initial request object. 
    79            response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse): 
    80                The initial response object. 
    81            retry (google.api_core.retry.Retry): Designation of what errors, 
    82                if any, should be retried. 
    83            timeout (float): The timeout for this request. 
    84            metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 
    85                sent along with the request as metadata. Normally, each value must be of type `str`, 
    86                but for metadata keys ending with the suffix `-bin`, the corresponding values must 
    87                be of type `bytes`. 
    88        """ 
    89        self._method = method 
    90        self._request = error_stats_service.ListGroupStatsRequest(request) 
    91        self._response = response 
    92        self._retry = retry 
    93        self._timeout = timeout 
    94        self._metadata = metadata 
    95 
    96    def __getattr__(self, name: str) -> Any: 
    97        return getattr(self._response, name) 
    98 
    99    @property 
    100    def pages(self) -> Iterator[error_stats_service.ListGroupStatsResponse]: 
    101        yield self._response 
    102        while self._response.next_page_token: 
    103            self._request.page_token = self._response.next_page_token 
    104            self._response = self._method( 
    105                self._request, 
    106                retry=self._retry, 
    107                timeout=self._timeout, 
    108                metadata=self._metadata, 
    109            ) 
    110            yield self._response 
    111 
    112    def __iter__(self) -> Iterator[error_stats_service.ErrorGroupStats]: 
    113        for page in self.pages: 
    114            yield from page.error_group_stats 
    115 
    116    def __repr__(self) -> str: 
    117        return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 
    118 
    119 
    120class ListGroupStatsAsyncPager: 
    121    """A pager for iterating through ``list_group_stats`` requests. 
    122 
    123    This class thinly wraps an initial 
    124    :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` object, and 
    125    provides an ``__aiter__`` method to iterate through its 
    126    ``error_group_stats`` field. 
    127 
    128    If there are more pages, the ``__aiter__`` method will make additional 
    129    ``ListGroupStats`` requests and continue to iterate 
    130    through the ``error_group_stats`` field on the 
    131    corresponding responses. 
    132 
    133    All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse` 
    134    attributes are available on the pager. If multiple requests are made, only 
    135    the most recent response is retained, and thus used for attribute lookup. 
    136    """ 
    137 
    138    def __init__( 
    139        self, 
    140        method: Callable[..., Awaitable[error_stats_service.ListGroupStatsResponse]], 
    141        request: error_stats_service.ListGroupStatsRequest, 
    142        response: error_stats_service.ListGroupStatsResponse, 
    143        *, 
    144        retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, 
    145        timeout: Union[float, object] = gapic_v1.method.DEFAULT, 
    146        metadata: Sequence[Tuple[str, Union[str, bytes]]] = () 
    147    ): 
    148        """Instantiates the pager. 
    149 
    150        Args: 
    151            method (Callable): The method that was originally called, and 
    152                which instantiated this pager. 
    153            request (google.cloud.errorreporting_v1beta1.types.ListGroupStatsRequest): 
    154                The initial request object. 
    155            response (google.cloud.errorreporting_v1beta1.types.ListGroupStatsResponse): 
    156                The initial response object. 
    157            retry (google.api_core.retry.AsyncRetry): Designation of what errors, 
    158                if any, should be retried. 
    159            timeout (float): The timeout for this request. 
    160            metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 
    161                sent along with the request as metadata. Normally, each value must be of type `str`, 
    162                but for metadata keys ending with the suffix `-bin`, the corresponding values must 
    163                be of type `bytes`. 
    164        """ 
    165        self._method = method 
    166        self._request = error_stats_service.ListGroupStatsRequest(request) 
    167        self._response = response 
    168        self._retry = retry 
    169        self._timeout = timeout 
    170        self._metadata = metadata 
    171 
    172    def __getattr__(self, name: str) -> Any: 
    173        return getattr(self._response, name) 
    174 
    175    @property 
    176    async def pages(self) -> AsyncIterator[error_stats_service.ListGroupStatsResponse]: 
    177        yield self._response 
    178        while self._response.next_page_token: 
    179            self._request.page_token = self._response.next_page_token 
    180            self._response = await self._method( 
    181                self._request, 
    182                retry=self._retry, 
    183                timeout=self._timeout, 
    184                metadata=self._metadata, 
    185            ) 
    186            yield self._response 
    187 
    188    def __aiter__(self) -> AsyncIterator[error_stats_service.ErrorGroupStats]: 
    189        async def async_generator(): 
    190            async for page in self.pages: 
    191                for response in page.error_group_stats: 
    192                    yield response 
    193 
    194        return async_generator() 
    195 
    196    def __repr__(self) -> str: 
    197        return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 
    198 
    199 
    200class ListEventsPager: 
    201    """A pager for iterating through ``list_events`` requests. 
    202 
    203    This class thinly wraps an initial 
    204    :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` object, and 
    205    provides an ``__iter__`` method to iterate through its 
    206    ``error_events`` field. 
    207 
    208    If there are more pages, the ``__iter__`` method will make additional 
    209    ``ListEvents`` requests and continue to iterate 
    210    through the ``error_events`` field on the 
    211    corresponding responses. 
    212 
    213    All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` 
    214    attributes are available on the pager. If multiple requests are made, only 
    215    the most recent response is retained, and thus used for attribute lookup. 
    216    """ 
    217 
    218    def __init__( 
    219        self, 
    220        method: Callable[..., error_stats_service.ListEventsResponse], 
    221        request: error_stats_service.ListEventsRequest, 
    222        response: error_stats_service.ListEventsResponse, 
    223        *, 
    224        retry: OptionalRetry = gapic_v1.method.DEFAULT, 
    225        timeout: Union[float, object] = gapic_v1.method.DEFAULT, 
    226        metadata: Sequence[Tuple[str, Union[str, bytes]]] = () 
    227    ): 
    228        """Instantiate the pager. 
    229 
    230        Args: 
    231            method (Callable): The method that was originally called, and 
    232                which instantiated this pager. 
    233            request (google.cloud.errorreporting_v1beta1.types.ListEventsRequest): 
    234                The initial request object. 
    235            response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse): 
    236                The initial response object. 
    237            retry (google.api_core.retry.Retry): Designation of what errors, 
    238                if any, should be retried. 
    239            timeout (float): The timeout for this request. 
    240            metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 
    241                sent along with the request as metadata. Normally, each value must be of type `str`, 
    242                but for metadata keys ending with the suffix `-bin`, the corresponding values must 
    243                be of type `bytes`. 
    244        """ 
    245        self._method = method 
    246        self._request = error_stats_service.ListEventsRequest(request) 
    247        self._response = response 
    248        self._retry = retry 
    249        self._timeout = timeout 
    250        self._metadata = metadata 
    251 
    252    def __getattr__(self, name: str) -> Any: 
    253        return getattr(self._response, name) 
    254 
    255    @property 
    256    def pages(self) -> Iterator[error_stats_service.ListEventsResponse]: 
    257        yield self._response 
    258        while self._response.next_page_token: 
    259            self._request.page_token = self._response.next_page_token 
    260            self._response = self._method( 
    261                self._request, 
    262                retry=self._retry, 
    263                timeout=self._timeout, 
    264                metadata=self._metadata, 
    265            ) 
    266            yield self._response 
    267 
    268    def __iter__(self) -> Iterator[common.ErrorEvent]: 
    269        for page in self.pages: 
    270            yield from page.error_events 
    271 
    272    def __repr__(self) -> str: 
    273        return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 
    274 
    275 
    276class ListEventsAsyncPager: 
    277    """A pager for iterating through ``list_events`` requests. 
    278 
    279    This class thinly wraps an initial 
    280    :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` object, and 
    281    provides an ``__aiter__`` method to iterate through its 
    282    ``error_events`` field. 
    283 
    284    If there are more pages, the ``__aiter__`` method will make additional 
    285    ``ListEvents`` requests and continue to iterate 
    286    through the ``error_events`` field on the 
    287    corresponding responses. 
    288 
    289    All the usual :class:`google.cloud.errorreporting_v1beta1.types.ListEventsResponse` 
    290    attributes are available on the pager. If multiple requests are made, only 
    291    the most recent response is retained, and thus used for attribute lookup. 
    292    """ 
    293 
    294    def __init__( 
    295        self, 
    296        method: Callable[..., Awaitable[error_stats_service.ListEventsResponse]], 
    297        request: error_stats_service.ListEventsRequest, 
    298        response: error_stats_service.ListEventsResponse, 
    299        *, 
    300        retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, 
    301        timeout: Union[float, object] = gapic_v1.method.DEFAULT, 
    302        metadata: Sequence[Tuple[str, Union[str, bytes]]] = () 
    303    ): 
    304        """Instantiates the pager. 
    305 
    306        Args: 
    307            method (Callable): The method that was originally called, and 
    308                which instantiated this pager. 
    309            request (google.cloud.errorreporting_v1beta1.types.ListEventsRequest): 
    310                The initial request object. 
    311            response (google.cloud.errorreporting_v1beta1.types.ListEventsResponse): 
    312                The initial response object. 
    313            retry (google.api_core.retry.AsyncRetry): Designation of what errors, 
    314                if any, should be retried. 
    315            timeout (float): The timeout for this request. 
    316            metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 
    317                sent along with the request as metadata. Normally, each value must be of type `str`, 
    318                but for metadata keys ending with the suffix `-bin`, the corresponding values must 
    319                be of type `bytes`. 
    320        """ 
    321        self._method = method 
    322        self._request = error_stats_service.ListEventsRequest(request) 
    323        self._response = response 
    324        self._retry = retry 
    325        self._timeout = timeout 
    326        self._metadata = metadata 
    327 
    328    def __getattr__(self, name: str) -> Any: 
    329        return getattr(self._response, name) 
    330 
    331    @property 
    332    async def pages(self) -> AsyncIterator[error_stats_service.ListEventsResponse]: 
    333        yield self._response 
    334        while self._response.next_page_token: 
    335            self._request.page_token = self._response.next_page_token 
    336            self._response = await self._method( 
    337                self._request, 
    338                retry=self._retry, 
    339                timeout=self._timeout, 
    340                metadata=self._metadata, 
    341            ) 
    342            yield self._response 
    343 
    344    def __aiter__(self) -> AsyncIterator[common.ErrorEvent]: 
    345        async def async_generator(): 
    346            async for page in self.pages: 
    347                for response in page.error_events: 
    348                    yield response 
    349 
    350        return async_generator() 
    351 
    352    def __repr__(self) -> str: 
    353        return "{0}<{1!r}>".format(self.__class__.__name__, self._response)