1# -*- coding: utf-8 -*-
2# Copyright 2024 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 Callable,
19 Sequence,
20 Tuple,
21)
22
23from google.longrunning import operations_pb2
24
25
26class ListOperationsPagerBase:
27 """A pager for iterating through ``list_operations`` requests.
28
29 This class thinly wraps an initial
30 :class:`google.longrunning.operations_pb2.ListOperationsResponse` object, and
31 provides an ``__iter__`` method to iterate through its
32 ``operations`` field.
33
34 If there are more pages, the ``__iter__`` method will make additional
35 ``ListOperations`` requests and continue to iterate
36 through the ``operations`` field on the
37 corresponding responses.
38
39 All the usual :class:`google.longrunning.operations_pb2.ListOperationsResponse`
40 attributes are available on the pager. If multiple requests are made, only
41 the most recent response is retained, and thus used for attribute lookup.
42 """
43
44 def __init__(
45 self,
46 method: Callable[..., operations_pb2.ListOperationsResponse],
47 request: operations_pb2.ListOperationsRequest,
48 response: operations_pb2.ListOperationsResponse,
49 *,
50 metadata: Sequence[Tuple[str, str]] = ()
51 ):
52 """Instantiate the pager.
53
54 Args:
55 method (Callable): The method that was originally called, and
56 which instantiated this pager.
57 request (google.longrunning.operations_pb2.ListOperationsRequest):
58 The initial request object.
59 response (google.longrunning.operations_pb2.ListOperationsResponse):
60 The initial response object.
61 metadata (Sequence[Tuple[str, str]]): Strings which should be
62 sent along with the request as metadata.
63 """
64 self._method = method
65 self._request = request
66 self._response = response
67 self._metadata = metadata
68
69 def __getattr__(self, name: str) -> Any:
70 return getattr(self._response, name)
71
72 def __repr__(self) -> str:
73 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)