Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/_rest_streaming_base.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/client_info.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/client_logging.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/datetime_helpers.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/exceptions.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/extended_operation.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/general_helpers.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/grpc_helpers.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/grpc_helpers_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/iam.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/operation_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/page_iterator_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/path_template.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/protobuf_helpers.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/rest_streaming.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/rest_streaming_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/timeout.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/universe.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/__pycache__/version_header.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__init__.py +19 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/_helpers.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/async_future.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/base.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/polling.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/_helpers.py +39 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/async_future.py +162 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/base.py +64 -0
- .venv/lib/python3.11/site-packages/google/api_core/future/polling.py +323 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__init__.py +29 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/client_info.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/config.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/config_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/method.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/method_async.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/routing_header.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/client_info.py +57 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/config.py +175 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/config_async.py +42 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py +253 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/method_async.py +59 -0
- .venv/lib/python3.11/site-packages/google/api_core/gapic_v1/routing_header.py +87 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/__pycache__/__init__.cpython-311.pyc +0 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/abstract_operations_client.py +387 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_async_client.py +364 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_client_config.py +60 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_rest_client_async.py +345 -0
- .venv/lib/python3.11/site-packages/google/api_core/operations_v1/pagers.py +67 -0
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (426 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/_rest_streaming_base.cpython-311.pyc
ADDED
|
Binary file (4.91 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/client_info.cpython-311.pyc
ADDED
|
Binary file (3.73 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/client_logging.cpython-311.pyc
ADDED
|
Binary file (5.42 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/datetime_helpers.cpython-311.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/exceptions.cpython-311.pyc
ADDED
|
Binary file (31.1 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/extended_operation.cpython-311.pyc
ADDED
|
Binary file (9.22 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/general_helpers.cpython-311.pyc
ADDED
|
Binary file (250 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/grpc_helpers.cpython-311.pyc
ADDED
|
Binary file (24.2 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/grpc_helpers_async.cpython-311.pyc
ADDED
|
Binary file (17.9 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/iam.cpython-311.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/operation_async.cpython-311.pyc
ADDED
|
Binary file (9.52 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/page_iterator_async.cpython-311.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/path_template.cpython-311.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/protobuf_helpers.cpython-311.pyc
ADDED
|
Binary file (14.1 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/rest_streaming.cpython-311.pyc
ADDED
|
Binary file (3.03 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/rest_streaming_async.cpython-311.pyc
ADDED
|
Binary file (4.27 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/timeout.cpython-311.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/universe.cpython-311.pyc
ADDED
|
Binary file (3.56 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/__pycache__/version_header.cpython-311.pyc
ADDED
|
Binary file (730 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Futures for dealing with asynchronous operations."""
|
| 16 |
+
|
| 17 |
+
from google.api_core.future.base import Future
|
| 18 |
+
|
| 19 |
+
__all__ = ["Future"]
|
.venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (364 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/_helpers.cpython-311.pyc
ADDED
|
Binary file (1.21 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/async_future.cpython-311.pyc
ADDED
|
Binary file (7.42 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (2.55 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/__pycache__/polling.cpython-311.pyc
ADDED
|
Binary file (15.3 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/future/_helpers.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Private helpers for futures."""
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import threading
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
_LOGGER = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def start_daemon_thread(*args, **kwargs):
|
| 25 |
+
"""Starts a thread and marks it as a daemon thread."""
|
| 26 |
+
thread = threading.Thread(*args, **kwargs)
|
| 27 |
+
thread.daemon = True
|
| 28 |
+
thread.start()
|
| 29 |
+
return thread
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def safe_invoke_callback(callback, *args, **kwargs):
|
| 33 |
+
"""Invoke a callback, swallowing and logging any exceptions."""
|
| 34 |
+
# pylint: disable=bare-except
|
| 35 |
+
# We intentionally want to swallow all exceptions.
|
| 36 |
+
try:
|
| 37 |
+
return callback(*args, **kwargs)
|
| 38 |
+
except Exception:
|
| 39 |
+
_LOGGER.exception("Error while executing Future callback.")
|
.venv/lib/python3.11/site-packages/google/api_core/future/async_future.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""AsyncIO implementation of the abstract base Future class."""
|
| 16 |
+
|
| 17 |
+
import asyncio
|
| 18 |
+
|
| 19 |
+
from google.api_core import exceptions
|
| 20 |
+
from google.api_core import retry
|
| 21 |
+
from google.api_core import retry_async
|
| 22 |
+
from google.api_core.future import base
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class _OperationNotComplete(Exception):
|
| 26 |
+
"""Private exception used for polling via retry."""
|
| 27 |
+
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
RETRY_PREDICATE = retry.if_exception_type(
|
| 32 |
+
_OperationNotComplete,
|
| 33 |
+
exceptions.TooManyRequests,
|
| 34 |
+
exceptions.InternalServerError,
|
| 35 |
+
exceptions.BadGateway,
|
| 36 |
+
)
|
| 37 |
+
DEFAULT_RETRY = retry_async.AsyncRetry(predicate=RETRY_PREDICATE)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class AsyncFuture(base.Future):
|
| 41 |
+
"""A Future that polls peer service to self-update.
|
| 42 |
+
|
| 43 |
+
The :meth:`done` method should be implemented by subclasses. The polling
|
| 44 |
+
behavior will repeatedly call ``done`` until it returns True.
|
| 45 |
+
|
| 46 |
+
.. note::
|
| 47 |
+
|
| 48 |
+
Privacy here is intended to prevent the final class from
|
| 49 |
+
overexposing, not to prevent subclasses from accessing methods.
|
| 50 |
+
|
| 51 |
+
Args:
|
| 52 |
+
retry (google.api_core.retry.Retry): The retry configuration used
|
| 53 |
+
when polling. This can be used to control how often :meth:`done`
|
| 54 |
+
is polled. Regardless of the retry's ``deadline``, it will be
|
| 55 |
+
overridden by the ``timeout`` argument to :meth:`result`.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
def __init__(self, retry=DEFAULT_RETRY):
|
| 59 |
+
super().__init__()
|
| 60 |
+
self._retry = retry
|
| 61 |
+
self._future = asyncio.get_event_loop().create_future()
|
| 62 |
+
self._background_task = None
|
| 63 |
+
|
| 64 |
+
async def done(self, retry=DEFAULT_RETRY):
|
| 65 |
+
"""Checks to see if the operation is complete.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
|
| 69 |
+
|
| 70 |
+
Returns:
|
| 71 |
+
bool: True if the operation is complete, False otherwise.
|
| 72 |
+
"""
|
| 73 |
+
# pylint: disable=redundant-returns-doc, missing-raises-doc
|
| 74 |
+
raise NotImplementedError()
|
| 75 |
+
|
| 76 |
+
async def _done_or_raise(self):
|
| 77 |
+
"""Check if the future is done and raise if it's not."""
|
| 78 |
+
result = await self.done()
|
| 79 |
+
if not result:
|
| 80 |
+
raise _OperationNotComplete()
|
| 81 |
+
|
| 82 |
+
async def running(self):
|
| 83 |
+
"""True if the operation is currently running."""
|
| 84 |
+
result = await self.done()
|
| 85 |
+
return not result
|
| 86 |
+
|
| 87 |
+
async def _blocking_poll(self, timeout=None):
|
| 88 |
+
"""Poll and await for the Future to be resolved.
|
| 89 |
+
|
| 90 |
+
Args:
|
| 91 |
+
timeout (int):
|
| 92 |
+
How long (in seconds) to wait for the operation to complete.
|
| 93 |
+
If None, wait indefinitely.
|
| 94 |
+
"""
|
| 95 |
+
if self._future.done():
|
| 96 |
+
return
|
| 97 |
+
|
| 98 |
+
retry_ = self._retry.with_timeout(timeout)
|
| 99 |
+
|
| 100 |
+
try:
|
| 101 |
+
await retry_(self._done_or_raise)()
|
| 102 |
+
except exceptions.RetryError:
|
| 103 |
+
raise asyncio.TimeoutError(
|
| 104 |
+
"Operation did not complete within the designated " "timeout."
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
async def result(self, timeout=None):
|
| 108 |
+
"""Get the result of the operation.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
timeout (int):
|
| 112 |
+
How long (in seconds) to wait for the operation to complete.
|
| 113 |
+
If None, wait indefinitely.
|
| 114 |
+
|
| 115 |
+
Returns:
|
| 116 |
+
google.protobuf.Message: The Operation's result.
|
| 117 |
+
|
| 118 |
+
Raises:
|
| 119 |
+
google.api_core.GoogleAPICallError: If the operation errors or if
|
| 120 |
+
the timeout is reached before the operation completes.
|
| 121 |
+
"""
|
| 122 |
+
await self._blocking_poll(timeout=timeout)
|
| 123 |
+
return self._future.result()
|
| 124 |
+
|
| 125 |
+
async def exception(self, timeout=None):
|
| 126 |
+
"""Get the exception from the operation.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
timeout (int): How long to wait for the operation to complete.
|
| 130 |
+
If None, wait indefinitely.
|
| 131 |
+
|
| 132 |
+
Returns:
|
| 133 |
+
Optional[google.api_core.GoogleAPICallError]: The operation's
|
| 134 |
+
error.
|
| 135 |
+
"""
|
| 136 |
+
await self._blocking_poll(timeout=timeout)
|
| 137 |
+
return self._future.exception()
|
| 138 |
+
|
| 139 |
+
def add_done_callback(self, fn):
|
| 140 |
+
"""Add a callback to be executed when the operation is complete.
|
| 141 |
+
|
| 142 |
+
If the operation is completed, the callback will be scheduled onto the
|
| 143 |
+
event loop. Otherwise, the callback will be stored and invoked when the
|
| 144 |
+
future is done.
|
| 145 |
+
|
| 146 |
+
Args:
|
| 147 |
+
fn (Callable[Future]): The callback to execute when the operation
|
| 148 |
+
is complete.
|
| 149 |
+
"""
|
| 150 |
+
if self._background_task is None:
|
| 151 |
+
self._background_task = asyncio.get_event_loop().create_task(
|
| 152 |
+
self._blocking_poll()
|
| 153 |
+
)
|
| 154 |
+
self._future.add_done_callback(fn)
|
| 155 |
+
|
| 156 |
+
def set_result(self, result):
|
| 157 |
+
"""Set the Future's result."""
|
| 158 |
+
self._future.set_result(result)
|
| 159 |
+
|
| 160 |
+
def set_exception(self, exception):
|
| 161 |
+
"""Set the Future's exception."""
|
| 162 |
+
self._future.set_exception(exception)
|
.venv/lib/python3.11/site-packages/google/api_core/future/base.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Abstract and helper bases for Future implementations."""
|
| 16 |
+
|
| 17 |
+
import abc
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Future(object, metaclass=abc.ABCMeta):
|
| 21 |
+
# pylint: disable=missing-docstring
|
| 22 |
+
# We inherit the interfaces here from concurrent.futures.
|
| 23 |
+
|
| 24 |
+
"""Future interface.
|
| 25 |
+
|
| 26 |
+
This interface is based on :class:`concurrent.futures.Future`.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
@abc.abstractmethod
|
| 30 |
+
def cancel(self):
|
| 31 |
+
raise NotImplementedError()
|
| 32 |
+
|
| 33 |
+
@abc.abstractmethod
|
| 34 |
+
def cancelled(self):
|
| 35 |
+
raise NotImplementedError()
|
| 36 |
+
|
| 37 |
+
@abc.abstractmethod
|
| 38 |
+
def running(self):
|
| 39 |
+
raise NotImplementedError()
|
| 40 |
+
|
| 41 |
+
@abc.abstractmethod
|
| 42 |
+
def done(self):
|
| 43 |
+
raise NotImplementedError()
|
| 44 |
+
|
| 45 |
+
@abc.abstractmethod
|
| 46 |
+
def result(self, timeout=None):
|
| 47 |
+
raise NotImplementedError()
|
| 48 |
+
|
| 49 |
+
@abc.abstractmethod
|
| 50 |
+
def exception(self, timeout=None):
|
| 51 |
+
raise NotImplementedError()
|
| 52 |
+
|
| 53 |
+
@abc.abstractmethod
|
| 54 |
+
def add_done_callback(self, fn):
|
| 55 |
+
# pylint: disable=invalid-name
|
| 56 |
+
raise NotImplementedError()
|
| 57 |
+
|
| 58 |
+
@abc.abstractmethod
|
| 59 |
+
def set_result(self, result):
|
| 60 |
+
raise NotImplementedError()
|
| 61 |
+
|
| 62 |
+
@abc.abstractmethod
|
| 63 |
+
def set_exception(self, exception):
|
| 64 |
+
raise NotImplementedError()
|
.venv/lib/python3.11/site-packages/google/api_core/future/polling.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017, Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Abstract and helper bases for Future implementations."""
|
| 16 |
+
|
| 17 |
+
import abc
|
| 18 |
+
import concurrent.futures
|
| 19 |
+
|
| 20 |
+
from google.api_core import exceptions
|
| 21 |
+
from google.api_core import retry as retries
|
| 22 |
+
from google.api_core.future import _helpers
|
| 23 |
+
from google.api_core.future import base
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class _OperationNotComplete(Exception):
|
| 27 |
+
"""Private exception used for polling via retry."""
|
| 28 |
+
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# DEPRECATED as it conflates RPC retry and polling concepts into one.
|
| 33 |
+
# Use POLLING_PREDICATE instead to configure polling.
|
| 34 |
+
RETRY_PREDICATE = retries.if_exception_type(
|
| 35 |
+
_OperationNotComplete,
|
| 36 |
+
exceptions.TooManyRequests,
|
| 37 |
+
exceptions.InternalServerError,
|
| 38 |
+
exceptions.BadGateway,
|
| 39 |
+
exceptions.ServiceUnavailable,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# DEPRECATED: use DEFAULT_POLLING to configure LRO polling logic. Construct
|
| 43 |
+
# Retry object using its default values as a baseline for any custom retry logic
|
| 44 |
+
# (not to be confused with polling logic).
|
| 45 |
+
DEFAULT_RETRY = retries.Retry(predicate=RETRY_PREDICATE)
|
| 46 |
+
|
| 47 |
+
# POLLING_PREDICATE is supposed to poll only on _OperationNotComplete.
|
| 48 |
+
# Any RPC-specific errors (like ServiceUnavailable) will be handled
|
| 49 |
+
# by retry logic (not to be confused with polling logic) which is triggered for
|
| 50 |
+
# every polling RPC independently of polling logic but within its context.
|
| 51 |
+
POLLING_PREDICATE = retries.if_exception_type(
|
| 52 |
+
_OperationNotComplete,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Default polling configuration
|
| 56 |
+
DEFAULT_POLLING = retries.Retry(
|
| 57 |
+
predicate=POLLING_PREDICATE,
|
| 58 |
+
initial=1.0, # seconds
|
| 59 |
+
maximum=20.0, # seconds
|
| 60 |
+
multiplier=1.5,
|
| 61 |
+
timeout=900, # seconds
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class PollingFuture(base.Future):
|
| 66 |
+
"""A Future that needs to poll some service to check its status.
|
| 67 |
+
|
| 68 |
+
The :meth:`done` method should be implemented by subclasses. The polling
|
| 69 |
+
behavior will repeatedly call ``done`` until it returns True.
|
| 70 |
+
|
| 71 |
+
The actual polling logic is encapsulated in :meth:`result` method. See
|
| 72 |
+
documentation for that method for details on how polling works.
|
| 73 |
+
|
| 74 |
+
.. note::
|
| 75 |
+
|
| 76 |
+
Privacy here is intended to prevent the final class from
|
| 77 |
+
overexposing, not to prevent subclasses from accessing methods.
|
| 78 |
+
|
| 79 |
+
Args:
|
| 80 |
+
polling (google.api_core.retry.Retry): The configuration used for polling.
|
| 81 |
+
This parameter controls how often :meth:`done` is polled. If the
|
| 82 |
+
``timeout`` argument is specified in :meth:`result` method it will
|
| 83 |
+
override the ``polling.timeout`` property.
|
| 84 |
+
retry (google.api_core.retry.Retry): DEPRECATED use ``polling`` instead.
|
| 85 |
+
If set, it will override ``polling`` parameter for backward
|
| 86 |
+
compatibility.
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
_DEFAULT_VALUE = object()
|
| 90 |
+
|
| 91 |
+
def __init__(self, polling=DEFAULT_POLLING, **kwargs):
|
| 92 |
+
super(PollingFuture, self).__init__()
|
| 93 |
+
self._polling = kwargs.get("retry", polling)
|
| 94 |
+
self._result = None
|
| 95 |
+
self._exception = None
|
| 96 |
+
self._result_set = False
|
| 97 |
+
"""bool: Set to True when the result has been set via set_result or
|
| 98 |
+
set_exception."""
|
| 99 |
+
self._polling_thread = None
|
| 100 |
+
self._done_callbacks = []
|
| 101 |
+
|
| 102 |
+
@abc.abstractmethod
|
| 103 |
+
def done(self, retry=None):
|
| 104 |
+
"""Checks to see if the operation is complete.
|
| 105 |
+
|
| 106 |
+
Args:
|
| 107 |
+
retry (google.api_core.retry.Retry): (Optional) How to retry the
|
| 108 |
+
polling RPC (to not be confused with polling configuration. See
|
| 109 |
+
the documentation for :meth:`result` for details).
|
| 110 |
+
|
| 111 |
+
Returns:
|
| 112 |
+
bool: True if the operation is complete, False otherwise.
|
| 113 |
+
"""
|
| 114 |
+
# pylint: disable=redundant-returns-doc, missing-raises-doc
|
| 115 |
+
raise NotImplementedError()
|
| 116 |
+
|
| 117 |
+
def _done_or_raise(self, retry=None):
|
| 118 |
+
"""Check if the future is done and raise if it's not."""
|
| 119 |
+
if not self.done(retry=retry):
|
| 120 |
+
raise _OperationNotComplete()
|
| 121 |
+
|
| 122 |
+
def running(self):
|
| 123 |
+
"""True if the operation is currently running."""
|
| 124 |
+
return not self.done()
|
| 125 |
+
|
| 126 |
+
def _blocking_poll(self, timeout=_DEFAULT_VALUE, retry=None, polling=None):
|
| 127 |
+
"""Poll and wait for the Future to be resolved."""
|
| 128 |
+
|
| 129 |
+
if self._result_set:
|
| 130 |
+
return
|
| 131 |
+
|
| 132 |
+
polling = polling or self._polling
|
| 133 |
+
if timeout is not PollingFuture._DEFAULT_VALUE:
|
| 134 |
+
polling = polling.with_timeout(timeout)
|
| 135 |
+
|
| 136 |
+
try:
|
| 137 |
+
polling(self._done_or_raise)(retry=retry)
|
| 138 |
+
except exceptions.RetryError:
|
| 139 |
+
raise concurrent.futures.TimeoutError(
|
| 140 |
+
f"Operation did not complete within the designated timeout of "
|
| 141 |
+
f"{polling.timeout} seconds."
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
def result(self, timeout=_DEFAULT_VALUE, retry=None, polling=None):
|
| 145 |
+
"""Get the result of the operation.
|
| 146 |
+
|
| 147 |
+
This method will poll for operation status periodically, blocking if
|
| 148 |
+
necessary. If you just want to make sure that this method does not block
|
| 149 |
+
for more than X seconds and you do not care about the nitty-gritty of
|
| 150 |
+
how this method operates, just call it with ``result(timeout=X)``. The
|
| 151 |
+
other parameters are for advanced use only.
|
| 152 |
+
|
| 153 |
+
Every call to this method is controlled by the following three
|
| 154 |
+
parameters, each of which has a specific, distinct role, even though all three
|
| 155 |
+
may look very similar: ``timeout``, ``retry`` and ``polling``. In most
|
| 156 |
+
cases users do not need to specify any custom values for any of these
|
| 157 |
+
parameters and may simply rely on default ones instead.
|
| 158 |
+
|
| 159 |
+
If you choose to specify custom parameters, please make sure you've
|
| 160 |
+
read the documentation below carefully.
|
| 161 |
+
|
| 162 |
+
First, please check :class:`google.api_core.retry.Retry`
|
| 163 |
+
class documentation for the proper definition of timeout and deadline
|
| 164 |
+
terms and for the definition the three different types of timeouts.
|
| 165 |
+
This class operates in terms of Retry Timeout and Polling Timeout. It
|
| 166 |
+
does not let customizing RPC timeout and the user is expected to rely on
|
| 167 |
+
default behavior for it.
|
| 168 |
+
|
| 169 |
+
The roles of each argument of this method are as follows:
|
| 170 |
+
|
| 171 |
+
``timeout`` (int): (Optional) The Polling Timeout as defined in
|
| 172 |
+
:class:`google.api_core.retry.Retry`. If the operation does not complete
|
| 173 |
+
within this timeout an exception will be thrown. This parameter affects
|
| 174 |
+
neither Retry Timeout nor RPC Timeout.
|
| 175 |
+
|
| 176 |
+
``retry`` (google.api_core.retry.Retry): (Optional) How to retry the
|
| 177 |
+
polling RPC. The ``retry.timeout`` property of this parameter is the
|
| 178 |
+
Retry Timeout as defined in :class:`google.api_core.retry.Retry`.
|
| 179 |
+
This parameter defines ONLY how the polling RPC call is retried
|
| 180 |
+
(i.e. what to do if the RPC we used for polling returned an error). It
|
| 181 |
+
does NOT define how the polling is done (i.e. how frequently and for
|
| 182 |
+
how long to call the polling RPC); use the ``polling`` parameter for that.
|
| 183 |
+
If a polling RPC throws and error and retrying it fails, the whole
|
| 184 |
+
future fails with the corresponding exception. If you want to tune which
|
| 185 |
+
server response error codes are not fatal for operation polling, use this
|
| 186 |
+
parameter to control that (``retry.predicate`` in particular).
|
| 187 |
+
|
| 188 |
+
``polling`` (google.api_core.retry.Retry): (Optional) How often and
|
| 189 |
+
for how long to call the polling RPC periodically (i.e. what to do if
|
| 190 |
+
a polling rpc returned successfully but its returned result indicates
|
| 191 |
+
that the long running operation is not completed yet, so we need to
|
| 192 |
+
check it again at some point in future). This parameter does NOT define
|
| 193 |
+
how to retry each individual polling RPC in case of an error; use the
|
| 194 |
+
``retry`` parameter for that. The ``polling.timeout`` of this parameter
|
| 195 |
+
is Polling Timeout as defined in as defined in
|
| 196 |
+
:class:`google.api_core.retry.Retry`.
|
| 197 |
+
|
| 198 |
+
For each of the arguments, there are also default values in place, which
|
| 199 |
+
will be used if a user does not specify their own. The default values
|
| 200 |
+
for the three parameters are not to be confused with the default values
|
| 201 |
+
for the corresponding arguments in this method (those serve as "not set"
|
| 202 |
+
markers for the resolution logic).
|
| 203 |
+
|
| 204 |
+
If ``timeout`` is provided (i.e.``timeout is not _DEFAULT VALUE``; note
|
| 205 |
+
the ``None`` value means "infinite timeout"), it will be used to control
|
| 206 |
+
the actual Polling Timeout. Otherwise, the ``polling.timeout`` value
|
| 207 |
+
will be used instead (see below for how the ``polling`` config itself
|
| 208 |
+
gets resolved). In other words, this parameter effectively overrides
|
| 209 |
+
the ``polling.timeout`` value if specified. This is so to preserve
|
| 210 |
+
backward compatibility.
|
| 211 |
+
|
| 212 |
+
If ``retry`` is provided (i.e. ``retry is not None``) it will be used to
|
| 213 |
+
control retry behavior for the polling RPC and the ``retry.timeout``
|
| 214 |
+
will determine the Retry Timeout. If not provided, the
|
| 215 |
+
polling RPC will be called with whichever default retry config was
|
| 216 |
+
specified for the polling RPC at the moment of the construction of the
|
| 217 |
+
polling RPC's client. For example, if the polling RPC is
|
| 218 |
+
``operations_client.get_operation()``, the ``retry`` parameter will be
|
| 219 |
+
controlling its retry behavior (not polling behavior) and, if not
|
| 220 |
+
specified, that specific method (``operations_client.get_operation()``)
|
| 221 |
+
will be retried according to the default retry config provided during
|
| 222 |
+
creation of ``operations_client`` client instead. This argument exists
|
| 223 |
+
mainly for backward compatibility; users are very unlikely to ever need
|
| 224 |
+
to set this parameter explicitly.
|
| 225 |
+
|
| 226 |
+
If ``polling`` is provided (i.e. ``polling is not None``), it will be used
|
| 227 |
+
to control the overall polling behavior and ``polling.timeout`` will
|
| 228 |
+
control Polling Timeout unless it is overridden by ``timeout`` parameter
|
| 229 |
+
as described above. If not provided, the``polling`` parameter specified
|
| 230 |
+
during construction of this future (the ``polling`` argument in the
|
| 231 |
+
constructor) will be used instead. Note: since the ``timeout`` argument may
|
| 232 |
+
override ``polling.timeout`` value, this parameter should be viewed as
|
| 233 |
+
coupled with the ``timeout`` parameter as described above.
|
| 234 |
+
|
| 235 |
+
Args:
|
| 236 |
+
timeout (int): (Optional) How long (in seconds) to wait for the
|
| 237 |
+
operation to complete. If None, wait indefinitely.
|
| 238 |
+
retry (google.api_core.retry.Retry): (Optional) How to retry the
|
| 239 |
+
polling RPC. This defines ONLY how the polling RPC call is
|
| 240 |
+
retried (i.e. what to do if the RPC we used for polling returned
|
| 241 |
+
an error). It does NOT define how the polling is done (i.e. how
|
| 242 |
+
frequently and for how long to call the polling RPC).
|
| 243 |
+
polling (google.api_core.retry.Retry): (Optional) How often and
|
| 244 |
+
for how long to call polling RPC periodically. This parameter
|
| 245 |
+
does NOT define how to retry each individual polling RPC call
|
| 246 |
+
(use the ``retry`` parameter for that).
|
| 247 |
+
|
| 248 |
+
Returns:
|
| 249 |
+
google.protobuf.Message: The Operation's result.
|
| 250 |
+
|
| 251 |
+
Raises:
|
| 252 |
+
google.api_core.GoogleAPICallError: If the operation errors or if
|
| 253 |
+
the timeout is reached before the operation completes.
|
| 254 |
+
"""
|
| 255 |
+
|
| 256 |
+
self._blocking_poll(timeout=timeout, retry=retry, polling=polling)
|
| 257 |
+
|
| 258 |
+
if self._exception is not None:
|
| 259 |
+
# pylint: disable=raising-bad-type
|
| 260 |
+
# Pylint doesn't recognize that this is valid in this case.
|
| 261 |
+
raise self._exception
|
| 262 |
+
|
| 263 |
+
return self._result
|
| 264 |
+
|
| 265 |
+
def exception(self, timeout=_DEFAULT_VALUE):
|
| 266 |
+
"""Get the exception from the operation, blocking if necessary.
|
| 267 |
+
|
| 268 |
+
See the documentation for the :meth:`result` method for details on how
|
| 269 |
+
this method operates, as both ``result`` and this method rely on the
|
| 270 |
+
exact same polling logic. The only difference is that this method does
|
| 271 |
+
not accept ``retry`` and ``polling`` arguments but relies on the default ones
|
| 272 |
+
instead.
|
| 273 |
+
|
| 274 |
+
Args:
|
| 275 |
+
timeout (int): How long to wait for the operation to complete.
|
| 276 |
+
If None, wait indefinitely.
|
| 277 |
+
|
| 278 |
+
Returns:
|
| 279 |
+
Optional[google.api_core.GoogleAPICallError]: The operation's
|
| 280 |
+
error.
|
| 281 |
+
"""
|
| 282 |
+
self._blocking_poll(timeout=timeout)
|
| 283 |
+
return self._exception
|
| 284 |
+
|
| 285 |
+
def add_done_callback(self, fn):
|
| 286 |
+
"""Add a callback to be executed when the operation is complete.
|
| 287 |
+
|
| 288 |
+
If the operation is not already complete, this will start a helper
|
| 289 |
+
thread to poll for the status of the operation in the background.
|
| 290 |
+
|
| 291 |
+
Args:
|
| 292 |
+
fn (Callable[Future]): The callback to execute when the operation
|
| 293 |
+
is complete.
|
| 294 |
+
"""
|
| 295 |
+
if self._result_set:
|
| 296 |
+
_helpers.safe_invoke_callback(fn, self)
|
| 297 |
+
return
|
| 298 |
+
|
| 299 |
+
self._done_callbacks.append(fn)
|
| 300 |
+
|
| 301 |
+
if self._polling_thread is None:
|
| 302 |
+
# The polling thread will exit on its own as soon as the operation
|
| 303 |
+
# is done.
|
| 304 |
+
self._polling_thread = _helpers.start_daemon_thread(
|
| 305 |
+
target=self._blocking_poll
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
def _invoke_callbacks(self, *args, **kwargs):
|
| 309 |
+
"""Invoke all done callbacks."""
|
| 310 |
+
for callback in self._done_callbacks:
|
| 311 |
+
_helpers.safe_invoke_callback(callback, *args, **kwargs)
|
| 312 |
+
|
| 313 |
+
def set_result(self, result):
|
| 314 |
+
"""Set the Future's result."""
|
| 315 |
+
self._result = result
|
| 316 |
+
self._result_set = True
|
| 317 |
+
self._invoke_callbacks(self)
|
| 318 |
+
|
| 319 |
+
def set_exception(self, exception):
|
| 320 |
+
"""Set the Future's exception."""
|
| 321 |
+
self._exception = exception
|
| 322 |
+
self._result_set = True
|
| 323 |
+
self._invoke_callbacks(self)
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from google.api_core.gapic_v1 import client_info
|
| 16 |
+
from google.api_core.gapic_v1 import config
|
| 17 |
+
from google.api_core.gapic_v1 import config_async
|
| 18 |
+
from google.api_core.gapic_v1 import method
|
| 19 |
+
from google.api_core.gapic_v1 import method_async
|
| 20 |
+
from google.api_core.gapic_v1 import routing_header
|
| 21 |
+
|
| 22 |
+
__all__ = [
|
| 23 |
+
"client_info",
|
| 24 |
+
"config",
|
| 25 |
+
"config_async",
|
| 26 |
+
"method",
|
| 27 |
+
"method_async",
|
| 28 |
+
"routing_header",
|
| 29 |
+
]
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (582 Bytes). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/client_info.cpython-311.pyc
ADDED
|
Binary file (2.38 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/config.cpython-311.pyc
ADDED
|
Binary file (6.96 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/config_async.cpython-311.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/method.cpython-311.pyc
ADDED
|
Binary file (9.57 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/method_async.cpython-311.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/__pycache__/routing_header.cpython-311.pyc
ADDED
|
Binary file (3.38 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/client_info.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Helpers for providing client information.
|
| 16 |
+
|
| 17 |
+
Client information is used to send information about the calling client,
|
| 18 |
+
such as the library and Python version, to API services.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
from google.api_core import client_info
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
METRICS_METADATA_KEY = "x-goog-api-client"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class ClientInfo(client_info.ClientInfo):
|
| 28 |
+
"""Client information used to generate a user-agent for API calls.
|
| 29 |
+
|
| 30 |
+
This user-agent information is sent along with API calls to allow the
|
| 31 |
+
receiving service to do analytics on which versions of Python and Google
|
| 32 |
+
libraries are being used.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
python_version (str): The Python interpreter version, for example,
|
| 36 |
+
``'3.9.6'``.
|
| 37 |
+
grpc_version (Optional[str]): The gRPC library version.
|
| 38 |
+
api_core_version (str): The google-api-core library version.
|
| 39 |
+
gapic_version (Optional[str]): The version of gapic-generated client
|
| 40 |
+
library, if the library was generated by gapic.
|
| 41 |
+
client_library_version (Optional[str]): The version of the client
|
| 42 |
+
library, generally used if the client library was not generated
|
| 43 |
+
by gapic or if additional functionality was built on top of
|
| 44 |
+
a gapic client library.
|
| 45 |
+
user_agent (Optional[str]): Prefix to the user agent header. This is
|
| 46 |
+
used to supply information such as application name or partner tool.
|
| 47 |
+
Recommended format: ``application-or-tool-ID/major.minor.version``.
|
| 48 |
+
rest_version (Optional[str]): A string with labeled versions of the
|
| 49 |
+
dependencies used for REST transport.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def to_grpc_metadata(self):
|
| 53 |
+
"""Returns the gRPC metadata for this client info."""
|
| 54 |
+
return (METRICS_METADATA_KEY, self.to_user_agent())
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
DEFAULT_CLIENT_INFO = ClientInfo()
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/config.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Helpers for loading gapic configuration data.
|
| 16 |
+
|
| 17 |
+
The Google API generator creates supplementary configuration for each RPC
|
| 18 |
+
method to tell the client library how to deal with retries and timeouts.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import collections
|
| 22 |
+
|
| 23 |
+
import grpc
|
| 24 |
+
|
| 25 |
+
from google.api_core import exceptions
|
| 26 |
+
from google.api_core import retry
|
| 27 |
+
from google.api_core import timeout
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_MILLIS_PER_SECOND = 1000.0
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _exception_class_for_grpc_status_name(name):
|
| 34 |
+
"""Returns the Google API exception class for a gRPC error code name.
|
| 35 |
+
|
| 36 |
+
DEPRECATED: use ``exceptions.exception_class_for_grpc_status`` method
|
| 37 |
+
directly instead.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
name (str): The name of the gRPC status code, for example,
|
| 41 |
+
``UNAVAILABLE``.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
:func:`type`: The appropriate subclass of
|
| 45 |
+
:class:`google.api_core.exceptions.GoogleAPICallError`.
|
| 46 |
+
"""
|
| 47 |
+
return exceptions.exception_class_for_grpc_status(getattr(grpc.StatusCode, name))
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _retry_from_retry_config(retry_params, retry_codes, retry_impl=retry.Retry):
|
| 51 |
+
"""Creates a Retry object given a gapic retry configuration.
|
| 52 |
+
|
| 53 |
+
DEPRECATED: instantiate retry and timeout classes directly instead.
|
| 54 |
+
|
| 55 |
+
Args:
|
| 56 |
+
retry_params (dict): The retry parameter values, for example::
|
| 57 |
+
|
| 58 |
+
{
|
| 59 |
+
"initial_retry_delay_millis": 1000,
|
| 60 |
+
"retry_delay_multiplier": 2.5,
|
| 61 |
+
"max_retry_delay_millis": 120000,
|
| 62 |
+
"initial_rpc_timeout_millis": 120000,
|
| 63 |
+
"rpc_timeout_multiplier": 1.0,
|
| 64 |
+
"max_rpc_timeout_millis": 120000,
|
| 65 |
+
"total_timeout_millis": 600000
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
retry_codes (sequence[str]): The list of retryable gRPC error code
|
| 69 |
+
names.
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
google.api_core.retry.Retry: The default retry object for the method.
|
| 73 |
+
"""
|
| 74 |
+
exception_classes = [
|
| 75 |
+
_exception_class_for_grpc_status_name(code) for code in retry_codes
|
| 76 |
+
]
|
| 77 |
+
return retry_impl(
|
| 78 |
+
retry.if_exception_type(*exception_classes),
|
| 79 |
+
initial=(retry_params["initial_retry_delay_millis"] / _MILLIS_PER_SECOND),
|
| 80 |
+
maximum=(retry_params["max_retry_delay_millis"] / _MILLIS_PER_SECOND),
|
| 81 |
+
multiplier=retry_params["retry_delay_multiplier"],
|
| 82 |
+
deadline=retry_params["total_timeout_millis"] / _MILLIS_PER_SECOND,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _timeout_from_retry_config(retry_params):
|
| 87 |
+
"""Creates a ExponentialTimeout object given a gapic retry configuration.
|
| 88 |
+
|
| 89 |
+
DEPRECATED: instantiate retry and timeout classes directly instead.
|
| 90 |
+
|
| 91 |
+
Args:
|
| 92 |
+
retry_params (dict): The retry parameter values, for example::
|
| 93 |
+
|
| 94 |
+
{
|
| 95 |
+
"initial_retry_delay_millis": 1000,
|
| 96 |
+
"retry_delay_multiplier": 2.5,
|
| 97 |
+
"max_retry_delay_millis": 120000,
|
| 98 |
+
"initial_rpc_timeout_millis": 120000,
|
| 99 |
+
"rpc_timeout_multiplier": 1.0,
|
| 100 |
+
"max_rpc_timeout_millis": 120000,
|
| 101 |
+
"total_timeout_millis": 600000
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
Returns:
|
| 105 |
+
google.api_core.retry.ExponentialTimeout: The default time object for
|
| 106 |
+
the method.
|
| 107 |
+
"""
|
| 108 |
+
return timeout.ExponentialTimeout(
|
| 109 |
+
initial=(retry_params["initial_rpc_timeout_millis"] / _MILLIS_PER_SECOND),
|
| 110 |
+
maximum=(retry_params["max_rpc_timeout_millis"] / _MILLIS_PER_SECOND),
|
| 111 |
+
multiplier=retry_params["rpc_timeout_multiplier"],
|
| 112 |
+
deadline=(retry_params["total_timeout_millis"] / _MILLIS_PER_SECOND),
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
MethodConfig = collections.namedtuple("MethodConfig", ["retry", "timeout"])
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def parse_method_configs(interface_config, retry_impl=retry.Retry):
|
| 120 |
+
"""Creates default retry and timeout objects for each method in a gapic
|
| 121 |
+
interface config.
|
| 122 |
+
|
| 123 |
+
DEPRECATED: instantiate retry and timeout classes directly instead.
|
| 124 |
+
|
| 125 |
+
Args:
|
| 126 |
+
interface_config (Mapping): The interface config section of the full
|
| 127 |
+
gapic library config. For example, If the full configuration has
|
| 128 |
+
an interface named ``google.example.v1.ExampleService`` you would
|
| 129 |
+
pass in just that interface's configuration, for example
|
| 130 |
+
``gapic_config['interfaces']['google.example.v1.ExampleService']``.
|
| 131 |
+
retry_impl (Callable): The constructor that creates a retry decorator
|
| 132 |
+
that will be applied to the method based on method configs.
|
| 133 |
+
|
| 134 |
+
Returns:
|
| 135 |
+
Mapping[str, MethodConfig]: A mapping of RPC method names to their
|
| 136 |
+
configuration.
|
| 137 |
+
"""
|
| 138 |
+
# Grab all the retry codes
|
| 139 |
+
retry_codes_map = {
|
| 140 |
+
name: retry_codes
|
| 141 |
+
for name, retry_codes in interface_config.get("retry_codes", {}).items()
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
# Grab all of the retry params
|
| 145 |
+
retry_params_map = {
|
| 146 |
+
name: retry_params
|
| 147 |
+
for name, retry_params in interface_config.get("retry_params", {}).items()
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
# Iterate through all the API methods and create a flat MethodConfig
|
| 151 |
+
# instance for each one.
|
| 152 |
+
method_configs = {}
|
| 153 |
+
|
| 154 |
+
for method_name, method_params in interface_config.get("methods", {}).items():
|
| 155 |
+
retry_params_name = method_params.get("retry_params_name")
|
| 156 |
+
|
| 157 |
+
if retry_params_name is not None:
|
| 158 |
+
retry_params = retry_params_map[retry_params_name]
|
| 159 |
+
retry_ = _retry_from_retry_config(
|
| 160 |
+
retry_params,
|
| 161 |
+
retry_codes_map[method_params["retry_codes_name"]],
|
| 162 |
+
retry_impl,
|
| 163 |
+
)
|
| 164 |
+
timeout_ = _timeout_from_retry_config(retry_params)
|
| 165 |
+
|
| 166 |
+
# No retry config, so this is a non-retryable method.
|
| 167 |
+
else:
|
| 168 |
+
retry_ = None
|
| 169 |
+
timeout_ = timeout.ConstantTimeout(
|
| 170 |
+
method_params["timeout_millis"] / _MILLIS_PER_SECOND
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
method_configs[method_name] = MethodConfig(retry=retry_, timeout=timeout_)
|
| 174 |
+
|
| 175 |
+
return method_configs
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/config_async.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""AsyncIO helpers for loading gapic configuration data.
|
| 15 |
+
|
| 16 |
+
The Google API generator creates supplementary configuration for each RPC
|
| 17 |
+
method to tell the client library how to deal with retries and timeouts.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
from google.api_core import retry_async
|
| 21 |
+
from google.api_core.gapic_v1 import config
|
| 22 |
+
from google.api_core.gapic_v1.config import MethodConfig # noqa: F401
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parse_method_configs(interface_config):
|
| 26 |
+
"""Creates default retry and timeout objects for each method in a gapic
|
| 27 |
+
interface config with AsyncIO semantics.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
interface_config (Mapping): The interface config section of the full
|
| 31 |
+
gapic library config. For example, If the full configuration has
|
| 32 |
+
an interface named ``google.example.v1.ExampleService`` you would
|
| 33 |
+
pass in just that interface's configuration, for example
|
| 34 |
+
``gapic_config['interfaces']['google.example.v1.ExampleService']``.
|
| 35 |
+
|
| 36 |
+
Returns:
|
| 37 |
+
Mapping[str, MethodConfig]: A mapping of RPC method names to their
|
| 38 |
+
configuration.
|
| 39 |
+
"""
|
| 40 |
+
return config.parse_method_configs(
|
| 41 |
+
interface_config, retry_impl=retry_async.AsyncRetry
|
| 42 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Helpers for wrapping low-level gRPC methods with common functionality.
|
| 16 |
+
|
| 17 |
+
This is used by gapic clients to provide common error mapping, retry, timeout,
|
| 18 |
+
compression, pagination, and long-running operations to gRPC methods.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import enum
|
| 22 |
+
import functools
|
| 23 |
+
|
| 24 |
+
from google.api_core import grpc_helpers
|
| 25 |
+
from google.api_core.gapic_v1 import client_info
|
| 26 |
+
from google.api_core.timeout import TimeToDeadlineTimeout
|
| 27 |
+
|
| 28 |
+
USE_DEFAULT_METADATA = object()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class _MethodDefault(enum.Enum):
|
| 32 |
+
# Uses enum so that pytype/mypy knows that this is the only possible value.
|
| 33 |
+
# https://stackoverflow.com/a/60605919/101923
|
| 34 |
+
#
|
| 35 |
+
# Literal[_DEFAULT_VALUE] is an alternative, but only added in Python 3.8.
|
| 36 |
+
# https://docs.python.org/3/library/typing.html#typing.Literal
|
| 37 |
+
_DEFAULT_VALUE = object()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
DEFAULT = _MethodDefault._DEFAULT_VALUE
|
| 41 |
+
"""Sentinel value indicating that a retry, timeout, or compression argument was unspecified,
|
| 42 |
+
so the default should be used."""
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _is_not_none_or_false(value):
|
| 46 |
+
return value is not None and value is not False
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _apply_decorators(func, decorators):
|
| 50 |
+
"""Apply a list of decorators to a given function.
|
| 51 |
+
|
| 52 |
+
``decorators`` may contain items that are ``None`` or ``False`` which will
|
| 53 |
+
be ignored.
|
| 54 |
+
"""
|
| 55 |
+
filtered_decorators = filter(_is_not_none_or_false, reversed(decorators))
|
| 56 |
+
|
| 57 |
+
for decorator in filtered_decorators:
|
| 58 |
+
func = decorator(func)
|
| 59 |
+
|
| 60 |
+
return func
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class _GapicCallable(object):
|
| 64 |
+
"""Callable that applies retry, timeout, and metadata logic.
|
| 65 |
+
|
| 66 |
+
Args:
|
| 67 |
+
target (Callable): The low-level RPC method.
|
| 68 |
+
retry (google.api_core.retry.Retry): The default retry for the
|
| 69 |
+
callable. If ``None``, this callable will not retry by default
|
| 70 |
+
timeout (google.api_core.timeout.Timeout): The default timeout for the
|
| 71 |
+
callable (i.e. duration of time within which an RPC must terminate
|
| 72 |
+
after its start, not to be confused with deadline). If ``None``,
|
| 73 |
+
this callable will not specify a timeout argument to the low-level
|
| 74 |
+
RPC method.
|
| 75 |
+
compression (grpc.Compression): The default compression for the callable.
|
| 76 |
+
If ``None``, this callable will not specify a compression argument
|
| 77 |
+
to the low-level RPC method.
|
| 78 |
+
metadata (Sequence[Tuple[str, str]]): Additional metadata that is
|
| 79 |
+
provided to the RPC method on every invocation. This is merged with
|
| 80 |
+
any metadata specified during invocation. If ``None``, no
|
| 81 |
+
additional metadata will be passed to the RPC method.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def __init__(
|
| 85 |
+
self,
|
| 86 |
+
target,
|
| 87 |
+
retry,
|
| 88 |
+
timeout,
|
| 89 |
+
compression,
|
| 90 |
+
metadata=None,
|
| 91 |
+
):
|
| 92 |
+
self._target = target
|
| 93 |
+
self._retry = retry
|
| 94 |
+
self._timeout = timeout
|
| 95 |
+
self._compression = compression
|
| 96 |
+
self._metadata = metadata
|
| 97 |
+
|
| 98 |
+
def __call__(
|
| 99 |
+
self, *args, timeout=DEFAULT, retry=DEFAULT, compression=DEFAULT, **kwargs
|
| 100 |
+
):
|
| 101 |
+
"""Invoke the low-level RPC with retry, timeout, compression, and metadata."""
|
| 102 |
+
|
| 103 |
+
if retry is DEFAULT:
|
| 104 |
+
retry = self._retry
|
| 105 |
+
|
| 106 |
+
if timeout is DEFAULT:
|
| 107 |
+
timeout = self._timeout
|
| 108 |
+
|
| 109 |
+
if compression is DEFAULT:
|
| 110 |
+
compression = self._compression
|
| 111 |
+
|
| 112 |
+
if isinstance(timeout, (int, float)):
|
| 113 |
+
timeout = TimeToDeadlineTimeout(timeout=timeout)
|
| 114 |
+
|
| 115 |
+
# Apply all applicable decorators.
|
| 116 |
+
wrapped_func = _apply_decorators(self._target, [retry, timeout])
|
| 117 |
+
|
| 118 |
+
# Add the user agent metadata to the call.
|
| 119 |
+
if self._metadata is not None:
|
| 120 |
+
metadata = kwargs.get("metadata", [])
|
| 121 |
+
# Due to the nature of invocation, None should be treated the same
|
| 122 |
+
# as not specified.
|
| 123 |
+
if metadata is None:
|
| 124 |
+
metadata = []
|
| 125 |
+
metadata = list(metadata)
|
| 126 |
+
metadata.extend(self._metadata)
|
| 127 |
+
kwargs["metadata"] = metadata
|
| 128 |
+
if self._compression is not None:
|
| 129 |
+
kwargs["compression"] = compression
|
| 130 |
+
|
| 131 |
+
return wrapped_func(*args, **kwargs)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def wrap_method(
|
| 135 |
+
func,
|
| 136 |
+
default_retry=None,
|
| 137 |
+
default_timeout=None,
|
| 138 |
+
default_compression=None,
|
| 139 |
+
client_info=client_info.DEFAULT_CLIENT_INFO,
|
| 140 |
+
*,
|
| 141 |
+
with_call=False,
|
| 142 |
+
):
|
| 143 |
+
"""Wrap an RPC method with common behavior.
|
| 144 |
+
|
| 145 |
+
This applies common error wrapping, retry, timeout, and compression behavior to a function.
|
| 146 |
+
The wrapped function will take optional ``retry``, ``timeout``, and ``compression``
|
| 147 |
+
arguments.
|
| 148 |
+
|
| 149 |
+
For example::
|
| 150 |
+
|
| 151 |
+
import google.api_core.gapic_v1.method
|
| 152 |
+
from google.api_core import retry
|
| 153 |
+
from google.api_core import timeout
|
| 154 |
+
from grpc import Compression
|
| 155 |
+
|
| 156 |
+
# The original RPC method.
|
| 157 |
+
def get_topic(name, timeout=None):
|
| 158 |
+
request = publisher_v2.GetTopicRequest(name=name)
|
| 159 |
+
return publisher_stub.GetTopic(request, timeout=timeout)
|
| 160 |
+
|
| 161 |
+
default_retry = retry.Retry(deadline=60)
|
| 162 |
+
default_timeout = timeout.Timeout(deadline=60)
|
| 163 |
+
default_compression = Compression.NoCompression
|
| 164 |
+
wrapped_get_topic = google.api_core.gapic_v1.method.wrap_method(
|
| 165 |
+
get_topic, default_retry)
|
| 166 |
+
|
| 167 |
+
# Execute get_topic with default retry and timeout:
|
| 168 |
+
response = wrapped_get_topic()
|
| 169 |
+
|
| 170 |
+
# Execute get_topic without doing any retying but with the default
|
| 171 |
+
# timeout:
|
| 172 |
+
response = wrapped_get_topic(retry=None)
|
| 173 |
+
|
| 174 |
+
# Execute get_topic but only retry on 5xx errors:
|
| 175 |
+
my_retry = retry.Retry(retry.if_exception_type(
|
| 176 |
+
exceptions.InternalServerError))
|
| 177 |
+
response = wrapped_get_topic(retry=my_retry)
|
| 178 |
+
|
| 179 |
+
The way this works is by late-wrapping the given function with the retry
|
| 180 |
+
and timeout decorators. Essentially, when ``wrapped_get_topic()`` is
|
| 181 |
+
called:
|
| 182 |
+
|
| 183 |
+
* ``get_topic()`` is first wrapped with the ``timeout`` into
|
| 184 |
+
``get_topic_with_timeout``.
|
| 185 |
+
* ``get_topic_with_timeout`` is wrapped with the ``retry`` into
|
| 186 |
+
``get_topic_with_timeout_and_retry()``.
|
| 187 |
+
* The final ``get_topic_with_timeout_and_retry`` is called passing through
|
| 188 |
+
the ``args`` and ``kwargs``.
|
| 189 |
+
|
| 190 |
+
The callstack is therefore::
|
| 191 |
+
|
| 192 |
+
method.__call__() ->
|
| 193 |
+
Retry.__call__() ->
|
| 194 |
+
Timeout.__call__() ->
|
| 195 |
+
wrap_errors() ->
|
| 196 |
+
get_topic()
|
| 197 |
+
|
| 198 |
+
Note that if ``timeout`` or ``retry`` is ``None``, then they are not
|
| 199 |
+
applied to the function. For example,
|
| 200 |
+
``wrapped_get_topic(timeout=None, retry=None)`` is more or less
|
| 201 |
+
equivalent to just calling ``get_topic`` but with error re-mapping.
|
| 202 |
+
|
| 203 |
+
Args:
|
| 204 |
+
func (Callable[Any]): The function to wrap. It should accept an
|
| 205 |
+
optional ``timeout`` argument. If ``metadata`` is not ``None``, it
|
| 206 |
+
should accept a ``metadata`` argument.
|
| 207 |
+
default_retry (Optional[google.api_core.Retry]): The default retry
|
| 208 |
+
strategy. If ``None``, the method will not retry by default.
|
| 209 |
+
default_timeout (Optional[google.api_core.Timeout]): The default
|
| 210 |
+
timeout strategy. Can also be specified as an int or float. If
|
| 211 |
+
``None``, the method will not have timeout specified by default.
|
| 212 |
+
default_compression (Optional[grpc.Compression]): The default
|
| 213 |
+
grpc.Compression. If ``None``, the method will not have
|
| 214 |
+
compression specified by default.
|
| 215 |
+
client_info
|
| 216 |
+
(Optional[google.api_core.gapic_v1.client_info.ClientInfo]):
|
| 217 |
+
Client information used to create a user-agent string that's
|
| 218 |
+
passed as gRPC metadata to the method. If unspecified, then
|
| 219 |
+
a sane default will be used. If ``None``, then no user agent
|
| 220 |
+
metadata will be provided to the RPC method.
|
| 221 |
+
with_call (bool): If True, wrapped grpc.UnaryUnaryMulticallables will
|
| 222 |
+
return a tuple of (response, grpc.Call) instead of just the response.
|
| 223 |
+
This is useful for extracting trailing metadata from unary calls.
|
| 224 |
+
Defaults to False.
|
| 225 |
+
|
| 226 |
+
Returns:
|
| 227 |
+
Callable: A new callable that takes optional ``retry``, ``timeout``,
|
| 228 |
+
and ``compression``
|
| 229 |
+
arguments and applies the common error mapping, retry, timeout, compression,
|
| 230 |
+
and metadata behavior to the low-level RPC method.
|
| 231 |
+
"""
|
| 232 |
+
if with_call:
|
| 233 |
+
try:
|
| 234 |
+
func = func.with_call
|
| 235 |
+
except AttributeError as exc:
|
| 236 |
+
raise ValueError(
|
| 237 |
+
"with_call=True is only supported for unary calls."
|
| 238 |
+
) from exc
|
| 239 |
+
func = grpc_helpers.wrap_errors(func)
|
| 240 |
+
if client_info is not None:
|
| 241 |
+
user_agent_metadata = [client_info.to_grpc_metadata()]
|
| 242 |
+
else:
|
| 243 |
+
user_agent_metadata = None
|
| 244 |
+
|
| 245 |
+
return functools.wraps(func)(
|
| 246 |
+
_GapicCallable(
|
| 247 |
+
func,
|
| 248 |
+
default_retry,
|
| 249 |
+
default_timeout,
|
| 250 |
+
default_compression,
|
| 251 |
+
metadata=user_agent_metadata,
|
| 252 |
+
)
|
| 253 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/method_async.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""AsyncIO helpers for wrapping gRPC methods with common functionality.
|
| 15 |
+
|
| 16 |
+
This is used by gapic clients to provide common error mapping, retry, timeout,
|
| 17 |
+
compression, pagination, and long-running operations to gRPC methods.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import functools
|
| 21 |
+
|
| 22 |
+
from google.api_core import grpc_helpers_async
|
| 23 |
+
from google.api_core.gapic_v1 import client_info
|
| 24 |
+
from google.api_core.gapic_v1.method import _GapicCallable
|
| 25 |
+
from google.api_core.gapic_v1.method import DEFAULT # noqa: F401
|
| 26 |
+
from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401
|
| 27 |
+
|
| 28 |
+
_DEFAULT_ASYNC_TRANSPORT_KIND = "grpc_asyncio"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def wrap_method(
|
| 32 |
+
func,
|
| 33 |
+
default_retry=None,
|
| 34 |
+
default_timeout=None,
|
| 35 |
+
default_compression=None,
|
| 36 |
+
client_info=client_info.DEFAULT_CLIENT_INFO,
|
| 37 |
+
kind=_DEFAULT_ASYNC_TRANSPORT_KIND,
|
| 38 |
+
):
|
| 39 |
+
"""Wrap an async RPC method with common behavior.
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
Callable: A new callable that takes optional ``retry``, ``timeout``,
|
| 43 |
+
and ``compression`` arguments and applies the common error mapping,
|
| 44 |
+
retry, timeout, metadata, and compression behavior to the low-level RPC method.
|
| 45 |
+
"""
|
| 46 |
+
if kind == _DEFAULT_ASYNC_TRANSPORT_KIND:
|
| 47 |
+
func = grpc_helpers_async.wrap_errors(func)
|
| 48 |
+
|
| 49 |
+
metadata = [client_info.to_grpc_metadata()] if client_info is not None else None
|
| 50 |
+
|
| 51 |
+
return functools.wraps(func)(
|
| 52 |
+
_GapicCallable(
|
| 53 |
+
func,
|
| 54 |
+
default_retry,
|
| 55 |
+
default_timeout,
|
| 56 |
+
default_compression,
|
| 57 |
+
metadata=metadata,
|
| 58 |
+
)
|
| 59 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/gapic_v1/routing_header.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Helpers for constructing routing headers.
|
| 16 |
+
|
| 17 |
+
These headers are used by Google infrastructure to determine how to route
|
| 18 |
+
requests, especially for services that are regional.
|
| 19 |
+
|
| 20 |
+
Generally, these headers are specified as gRPC metadata.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
import functools
|
| 24 |
+
from enum import Enum
|
| 25 |
+
from urllib.parse import urlencode
|
| 26 |
+
|
| 27 |
+
ROUTING_METADATA_KEY = "x-goog-request-params"
|
| 28 |
+
# This is the value for the `maxsize` argument of @functools.lru_cache
|
| 29 |
+
# https://docs.python.org/3/library/functools.html#functools.lru_cache
|
| 30 |
+
# This represents the number of recent function calls to store.
|
| 31 |
+
ROUTING_PARAM_CACHE_SIZE = 32
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def to_routing_header(params, qualified_enums=True):
|
| 35 |
+
"""Returns a routing header string for the given request parameters.
|
| 36 |
+
|
| 37 |
+
Args:
|
| 38 |
+
params (Mapping[str, str | bytes | Enum]): A dictionary containing the request
|
| 39 |
+
parameters used for routing.
|
| 40 |
+
qualified_enums (bool): Whether to represent enum values
|
| 41 |
+
as their type-qualified symbol names instead of as their
|
| 42 |
+
unqualified symbol names.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
str: The routing header string.
|
| 46 |
+
"""
|
| 47 |
+
tuples = params.items() if isinstance(params, dict) else params
|
| 48 |
+
if not qualified_enums:
|
| 49 |
+
tuples = [(x[0], x[1].name) if isinstance(x[1], Enum) else x for x in tuples]
|
| 50 |
+
return "&".join([_urlencode_param(*t) for t in tuples])
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def to_grpc_metadata(params, qualified_enums=True):
|
| 54 |
+
"""Returns the gRPC metadata containing the routing headers for the given
|
| 55 |
+
request parameters.
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
params (Mapping[str, str | bytes | Enum]): A dictionary containing the request
|
| 59 |
+
parameters used for routing.
|
| 60 |
+
qualified_enums (bool): Whether to represent enum values
|
| 61 |
+
as their type-qualified symbol names instead of as their
|
| 62 |
+
unqualified symbol names.
|
| 63 |
+
|
| 64 |
+
Returns:
|
| 65 |
+
Tuple(str, str): The gRPC metadata containing the routing header key
|
| 66 |
+
and value.
|
| 67 |
+
"""
|
| 68 |
+
return (ROUTING_METADATA_KEY, to_routing_header(params, qualified_enums))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# use caching to avoid repeated computation
|
| 72 |
+
@functools.lru_cache(maxsize=ROUTING_PARAM_CACHE_SIZE)
|
| 73 |
+
def _urlencode_param(key, value):
|
| 74 |
+
"""Cacheable wrapper over urlencode
|
| 75 |
+
|
| 76 |
+
Args:
|
| 77 |
+
key (str): The key of the parameter to encode.
|
| 78 |
+
value (str | bytes | Enum): The value of the parameter to encode.
|
| 79 |
+
|
| 80 |
+
Returns:
|
| 81 |
+
str: The encoded parameter.
|
| 82 |
+
"""
|
| 83 |
+
return urlencode(
|
| 84 |
+
{key: value},
|
| 85 |
+
# Per Google API policy (go/api-url-encoding), / is not encoded.
|
| 86 |
+
safe="/",
|
| 87 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.19 kB). View file
|
|
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/abstract_operations_client.py
ADDED
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2020 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 |
+
#
|
| 16 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 17 |
+
|
| 18 |
+
from google.api_core import client_options as client_options_lib # type: ignore
|
| 19 |
+
from google.api_core import gapic_v1 # type: ignore
|
| 20 |
+
from google.api_core import retry as retries # type: ignore
|
| 21 |
+
from google.api_core.operations_v1 import pagers
|
| 22 |
+
from google.api_core.operations_v1.transports.base import (
|
| 23 |
+
DEFAULT_CLIENT_INFO,
|
| 24 |
+
OperationsTransport,
|
| 25 |
+
)
|
| 26 |
+
from google.api_core.operations_v1.abstract_operations_base_client import (
|
| 27 |
+
AbstractOperationsBaseClient,
|
| 28 |
+
)
|
| 29 |
+
from google.auth import credentials as ga_credentials # type: ignore
|
| 30 |
+
from google.longrunning import operations_pb2
|
| 31 |
+
from google.oauth2 import service_account # type: ignore
|
| 32 |
+
import grpc
|
| 33 |
+
|
| 34 |
+
OptionalRetry = Union[retries.Retry, object]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class AbstractOperationsClient(AbstractOperationsBaseClient):
|
| 38 |
+
"""Manages long-running operations with an API service.
|
| 39 |
+
|
| 40 |
+
When an API method normally takes long time to complete, it can be
|
| 41 |
+
designed to return [Operation][google.api_core.operations_v1.Operation] to the
|
| 42 |
+
client, and the client can use this interface to receive the real
|
| 43 |
+
response asynchronously by polling the operation resource, or pass
|
| 44 |
+
the operation resource to another API (such as Google Cloud Pub/Sub
|
| 45 |
+
API) to receive the response. Any API service that returns
|
| 46 |
+
long-running operations should implement the ``Operations``
|
| 47 |
+
interface so developers can have a consistent client experience.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
def __init__(
|
| 51 |
+
self,
|
| 52 |
+
*,
|
| 53 |
+
credentials: Optional[ga_credentials.Credentials] = None,
|
| 54 |
+
transport: Union[str, OperationsTransport, None] = None,
|
| 55 |
+
client_options: Optional[client_options_lib.ClientOptions] = None,
|
| 56 |
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
| 57 |
+
) -> None:
|
| 58 |
+
"""Instantiates the operations client.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
| 62 |
+
authorization credentials to attach to requests. These
|
| 63 |
+
credentials identify the application to the service; if none
|
| 64 |
+
are specified, the client will attempt to ascertain the
|
| 65 |
+
credentials from the environment.
|
| 66 |
+
transport (Union[str, OperationsTransport]): The
|
| 67 |
+
transport to use. If set to None, a transport is chosen
|
| 68 |
+
automatically.
|
| 69 |
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
| 70 |
+
client. It won't take effect if a ``transport`` instance is provided.
|
| 71 |
+
(1) The ``api_endpoint`` property can be used to override the
|
| 72 |
+
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
|
| 73 |
+
environment variable can also be used to override the endpoint:
|
| 74 |
+
"always" (always use the default mTLS endpoint), "never" (always
|
| 75 |
+
use the default regular endpoint) and "auto" (auto switch to the
|
| 76 |
+
default mTLS endpoint if client certificate is present, this is
|
| 77 |
+
the default value). However, the ``api_endpoint`` property takes
|
| 78 |
+
precedence if provided.
|
| 79 |
+
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
| 80 |
+
is "true", then the ``client_cert_source`` property can be used
|
| 81 |
+
to provide client certificate for mutual TLS transport. If
|
| 82 |
+
not provided, the default SSL client certificate will be used if
|
| 83 |
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
| 84 |
+
set, no client certificate will be used.
|
| 85 |
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
| 86 |
+
The client info used to send a user-agent string along with
|
| 87 |
+
API requests. If ``None``, then default info will be used.
|
| 88 |
+
Generally, you only need to set this if you're developing
|
| 89 |
+
your own client library.
|
| 90 |
+
|
| 91 |
+
Raises:
|
| 92 |
+
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
|
| 93 |
+
creation failed for any reason.
|
| 94 |
+
"""
|
| 95 |
+
super().__init__(
|
| 96 |
+
credentials=credentials,
|
| 97 |
+
transport=transport,
|
| 98 |
+
client_options=client_options,
|
| 99 |
+
client_info=client_info,
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
@classmethod
|
| 103 |
+
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
| 104 |
+
"""Creates an instance of this client using the provided credentials
|
| 105 |
+
info.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
info (dict): The service account private key info.
|
| 109 |
+
args: Additional arguments to pass to the constructor.
|
| 110 |
+
kwargs: Additional arguments to pass to the constructor.
|
| 111 |
+
|
| 112 |
+
Returns:
|
| 113 |
+
AbstractOperationsClient: The constructed client.
|
| 114 |
+
"""
|
| 115 |
+
credentials = service_account.Credentials.from_service_account_info(info)
|
| 116 |
+
kwargs["credentials"] = credentials
|
| 117 |
+
return cls(*args, **kwargs)
|
| 118 |
+
|
| 119 |
+
@classmethod
|
| 120 |
+
def from_service_account_file(cls, filename: str, *args, **kwargs):
|
| 121 |
+
"""Creates an instance of this client using the provided credentials
|
| 122 |
+
file.
|
| 123 |
+
|
| 124 |
+
Args:
|
| 125 |
+
filename (str): The path to the service account private key json
|
| 126 |
+
file.
|
| 127 |
+
args: Additional arguments to pass to the constructor.
|
| 128 |
+
kwargs: Additional arguments to pass to the constructor.
|
| 129 |
+
|
| 130 |
+
Returns:
|
| 131 |
+
AbstractOperationsClient: The constructed client.
|
| 132 |
+
"""
|
| 133 |
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
| 134 |
+
kwargs["credentials"] = credentials
|
| 135 |
+
return cls(*args, **kwargs)
|
| 136 |
+
|
| 137 |
+
from_service_account_json = from_service_account_file
|
| 138 |
+
|
| 139 |
+
def list_operations(
|
| 140 |
+
self,
|
| 141 |
+
name: str,
|
| 142 |
+
filter_: Optional[str] = None,
|
| 143 |
+
*,
|
| 144 |
+
page_size: Optional[int] = None,
|
| 145 |
+
page_token: Optional[str] = None,
|
| 146 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 147 |
+
timeout: Optional[float] = None,
|
| 148 |
+
compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT,
|
| 149 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 150 |
+
) -> pagers.ListOperationsPager:
|
| 151 |
+
r"""Lists operations that match the specified filter in the request.
|
| 152 |
+
If the server doesn't support this method, it returns
|
| 153 |
+
``UNIMPLEMENTED``.
|
| 154 |
+
|
| 155 |
+
NOTE: the ``name`` binding allows API services to override the
|
| 156 |
+
binding to use different resource name schemes, such as
|
| 157 |
+
``users/*/operations``. To override the binding, API services
|
| 158 |
+
can add a binding such as ``"/v1/{name=users/*}/operations"`` to
|
| 159 |
+
their service configuration. For backwards compatibility, the
|
| 160 |
+
default name includes the operations collection id, however
|
| 161 |
+
overriding users must ensure the name binding is the parent
|
| 162 |
+
resource, without the operations collection id.
|
| 163 |
+
|
| 164 |
+
Args:
|
| 165 |
+
name (str):
|
| 166 |
+
The name of the operation's parent
|
| 167 |
+
resource.
|
| 168 |
+
filter_ (str):
|
| 169 |
+
The standard list filter.
|
| 170 |
+
This corresponds to the ``filter`` field
|
| 171 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 172 |
+
should not be set.
|
| 173 |
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
| 174 |
+
should be retried.
|
| 175 |
+
timeout (float): The timeout for this request.
|
| 176 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 177 |
+
sent along with the request as metadata.
|
| 178 |
+
|
| 179 |
+
Returns:
|
| 180 |
+
google.api_core.operations_v1.pagers.ListOperationsPager:
|
| 181 |
+
The response message for
|
| 182 |
+
[Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations].
|
| 183 |
+
|
| 184 |
+
Iterating over this object will yield results and
|
| 185 |
+
resolve additional pages automatically.
|
| 186 |
+
|
| 187 |
+
"""
|
| 188 |
+
# Create a protobuf request object.
|
| 189 |
+
request = operations_pb2.ListOperationsRequest(name=name, filter=filter_)
|
| 190 |
+
if page_size is not None:
|
| 191 |
+
request.page_size = page_size
|
| 192 |
+
if page_token is not None:
|
| 193 |
+
request.page_token = page_token
|
| 194 |
+
|
| 195 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 196 |
+
# and friendly error handling.
|
| 197 |
+
rpc = self._transport._wrapped_methods[self._transport.list_operations]
|
| 198 |
+
|
| 199 |
+
# Certain fields should be provided within the metadata header;
|
| 200 |
+
# add these here.
|
| 201 |
+
metadata = tuple(metadata or ()) + (
|
| 202 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
# Send the request.
|
| 206 |
+
response = rpc(
|
| 207 |
+
request,
|
| 208 |
+
retry=retry,
|
| 209 |
+
timeout=timeout,
|
| 210 |
+
compression=compression,
|
| 211 |
+
metadata=metadata,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
# This method is paged; wrap the response in a pager, which provides
|
| 215 |
+
# an `__iter__` convenience method.
|
| 216 |
+
response = pagers.ListOperationsPager(
|
| 217 |
+
method=rpc,
|
| 218 |
+
request=request,
|
| 219 |
+
response=response,
|
| 220 |
+
metadata=metadata,
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
# Done; return the response.
|
| 224 |
+
return response
|
| 225 |
+
|
| 226 |
+
def get_operation(
|
| 227 |
+
self,
|
| 228 |
+
name: str,
|
| 229 |
+
*,
|
| 230 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 231 |
+
timeout: Optional[float] = None,
|
| 232 |
+
compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT,
|
| 233 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 234 |
+
) -> operations_pb2.Operation:
|
| 235 |
+
r"""Gets the latest state of a long-running operation.
|
| 236 |
+
Clients can use this method to poll the operation result
|
| 237 |
+
at intervals as recommended by the API service.
|
| 238 |
+
|
| 239 |
+
Args:
|
| 240 |
+
name (str):
|
| 241 |
+
The name of the operation resource.
|
| 242 |
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
| 243 |
+
should be retried.
|
| 244 |
+
timeout (float): The timeout for this request.
|
| 245 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 246 |
+
sent along with the request as metadata.
|
| 247 |
+
|
| 248 |
+
Returns:
|
| 249 |
+
google.longrunning.operations_pb2.Operation:
|
| 250 |
+
This resource represents a long-
|
| 251 |
+
running operation that is the result of a
|
| 252 |
+
network API call.
|
| 253 |
+
|
| 254 |
+
"""
|
| 255 |
+
|
| 256 |
+
request = operations_pb2.GetOperationRequest(name=name)
|
| 257 |
+
|
| 258 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 259 |
+
# and friendly error handling.
|
| 260 |
+
rpc = self._transport._wrapped_methods[self._transport.get_operation]
|
| 261 |
+
|
| 262 |
+
# Certain fields should be provided within the metadata header;
|
| 263 |
+
# add these here.
|
| 264 |
+
metadata = tuple(metadata or ()) + (
|
| 265 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
# Send the request.
|
| 269 |
+
response = rpc(
|
| 270 |
+
request,
|
| 271 |
+
retry=retry,
|
| 272 |
+
timeout=timeout,
|
| 273 |
+
compression=compression,
|
| 274 |
+
metadata=metadata,
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
# Done; return the response.
|
| 278 |
+
return response
|
| 279 |
+
|
| 280 |
+
def delete_operation(
|
| 281 |
+
self,
|
| 282 |
+
name: str,
|
| 283 |
+
*,
|
| 284 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 285 |
+
timeout: Optional[float] = None,
|
| 286 |
+
compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT,
|
| 287 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 288 |
+
) -> None:
|
| 289 |
+
r"""Deletes a long-running operation. This method indicates that the
|
| 290 |
+
client is no longer interested in the operation result. It does
|
| 291 |
+
not cancel the operation. If the server doesn't support this
|
| 292 |
+
method, it returns ``google.rpc.Code.UNIMPLEMENTED``.
|
| 293 |
+
|
| 294 |
+
Args:
|
| 295 |
+
name (str):
|
| 296 |
+
The name of the operation resource to
|
| 297 |
+
be deleted.
|
| 298 |
+
|
| 299 |
+
This corresponds to the ``name`` field
|
| 300 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 301 |
+
should not be set.
|
| 302 |
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
| 303 |
+
should be retried.
|
| 304 |
+
timeout (float): The timeout for this request.
|
| 305 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 306 |
+
sent along with the request as metadata.
|
| 307 |
+
"""
|
| 308 |
+
# Create the request object.
|
| 309 |
+
request = operations_pb2.DeleteOperationRequest(name=name)
|
| 310 |
+
|
| 311 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 312 |
+
# and friendly error handling.
|
| 313 |
+
rpc = self._transport._wrapped_methods[self._transport.delete_operation]
|
| 314 |
+
|
| 315 |
+
# Certain fields should be provided within the metadata header;
|
| 316 |
+
# add these here.
|
| 317 |
+
metadata = tuple(metadata or ()) + (
|
| 318 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
# Send the request.
|
| 322 |
+
rpc(
|
| 323 |
+
request,
|
| 324 |
+
retry=retry,
|
| 325 |
+
timeout=timeout,
|
| 326 |
+
compression=compression,
|
| 327 |
+
metadata=metadata,
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
def cancel_operation(
|
| 331 |
+
self,
|
| 332 |
+
name: Optional[str] = None,
|
| 333 |
+
*,
|
| 334 |
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
| 335 |
+
timeout: Optional[float] = None,
|
| 336 |
+
compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT,
|
| 337 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 338 |
+
) -> None:
|
| 339 |
+
r"""Starts asynchronous cancellation on a long-running operation.
|
| 340 |
+
The server makes a best effort to cancel the operation, but
|
| 341 |
+
success is not guaranteed. If the server doesn't support this
|
| 342 |
+
method, it returns ``google.rpc.Code.UNIMPLEMENTED``. Clients
|
| 343 |
+
can use
|
| 344 |
+
[Operations.GetOperation][google.api_core.operations_v1.Operations.GetOperation]
|
| 345 |
+
or other methods to check whether the cancellation succeeded or
|
| 346 |
+
whether the operation completed despite cancellation. On
|
| 347 |
+
successful cancellation, the operation is not deleted; instead,
|
| 348 |
+
it becomes an operation with an
|
| 349 |
+
[Operation.error][google.api_core.operations_v1.Operation.error] value with
|
| 350 |
+
a [google.rpc.Status.code][google.rpc.Status.code] of 1,
|
| 351 |
+
corresponding to ``Code.CANCELLED``.
|
| 352 |
+
|
| 353 |
+
Args:
|
| 354 |
+
name (str):
|
| 355 |
+
The name of the operation resource to
|
| 356 |
+
be cancelled.
|
| 357 |
+
|
| 358 |
+
This corresponds to the ``name`` field
|
| 359 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 360 |
+
should not be set.
|
| 361 |
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
| 362 |
+
should be retried.
|
| 363 |
+
timeout (float): The timeout for this request.
|
| 364 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 365 |
+
sent along with the request as metadata.
|
| 366 |
+
"""
|
| 367 |
+
# Create the request object.
|
| 368 |
+
request = operations_pb2.CancelOperationRequest(name=name)
|
| 369 |
+
|
| 370 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 371 |
+
# and friendly error handling.
|
| 372 |
+
rpc = self._transport._wrapped_methods[self._transport.cancel_operation]
|
| 373 |
+
|
| 374 |
+
# Certain fields should be provided within the metadata header;
|
| 375 |
+
# add these here.
|
| 376 |
+
metadata = tuple(metadata or ()) + (
|
| 377 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
# Send the request.
|
| 381 |
+
rpc(
|
| 382 |
+
request,
|
| 383 |
+
retry=retry,
|
| 384 |
+
timeout=timeout,
|
| 385 |
+
compression=compression,
|
| 386 |
+
metadata=metadata,
|
| 387 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_async_client.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""An async client for the google.longrunning.operations meta-API.
|
| 16 |
+
|
| 17 |
+
.. _Google API Style Guide:
|
| 18 |
+
https://cloud.google.com/apis/design/design_pattern
|
| 19 |
+
s#long_running_operations
|
| 20 |
+
.. _google/longrunning/operations.proto:
|
| 21 |
+
https://github.com/googleapis/googleapis/blob/master/google/longrunning
|
| 22 |
+
/operations.proto
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
import functools
|
| 26 |
+
|
| 27 |
+
from google.api_core import exceptions as core_exceptions
|
| 28 |
+
from google.api_core import gapic_v1, page_iterator_async
|
| 29 |
+
from google.api_core import retry_async as retries
|
| 30 |
+
from google.api_core import timeout as timeouts
|
| 31 |
+
from google.longrunning import operations_pb2
|
| 32 |
+
from grpc import Compression
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class OperationsAsyncClient:
|
| 36 |
+
"""Async client for interacting with long-running operations.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
channel (aio.Channel): The gRPC AsyncIO channel associated with the
|
| 40 |
+
service that implements the ``google.longrunning.operations``
|
| 41 |
+
interface.
|
| 42 |
+
client_config (dict):
|
| 43 |
+
A dictionary of call options for each method. If not specified
|
| 44 |
+
the default configuration is used.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
def __init__(self, channel, client_config=None):
|
| 48 |
+
# Create the gRPC client stub with gRPC AsyncIO channel.
|
| 49 |
+
self.operations_stub = operations_pb2.OperationsStub(channel)
|
| 50 |
+
|
| 51 |
+
default_retry = retries.AsyncRetry(
|
| 52 |
+
initial=0.1, # seconds
|
| 53 |
+
maximum=60.0, # seconds
|
| 54 |
+
multiplier=1.3,
|
| 55 |
+
predicate=retries.if_exception_type(
|
| 56 |
+
core_exceptions.DeadlineExceeded,
|
| 57 |
+
core_exceptions.ServiceUnavailable,
|
| 58 |
+
),
|
| 59 |
+
timeout=600.0, # seconds
|
| 60 |
+
)
|
| 61 |
+
default_timeout = timeouts.TimeToDeadlineTimeout(timeout=600.0)
|
| 62 |
+
|
| 63 |
+
default_compression = Compression.NoCompression
|
| 64 |
+
|
| 65 |
+
self._get_operation = gapic_v1.method_async.wrap_method(
|
| 66 |
+
self.operations_stub.GetOperation,
|
| 67 |
+
default_retry=default_retry,
|
| 68 |
+
default_timeout=default_timeout,
|
| 69 |
+
default_compression=default_compression,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
self._list_operations = gapic_v1.method_async.wrap_method(
|
| 73 |
+
self.operations_stub.ListOperations,
|
| 74 |
+
default_retry=default_retry,
|
| 75 |
+
default_timeout=default_timeout,
|
| 76 |
+
default_compression=default_compression,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
self._cancel_operation = gapic_v1.method_async.wrap_method(
|
| 80 |
+
self.operations_stub.CancelOperation,
|
| 81 |
+
default_retry=default_retry,
|
| 82 |
+
default_timeout=default_timeout,
|
| 83 |
+
default_compression=default_compression,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
self._delete_operation = gapic_v1.method_async.wrap_method(
|
| 87 |
+
self.operations_stub.DeleteOperation,
|
| 88 |
+
default_retry=default_retry,
|
| 89 |
+
default_timeout=default_timeout,
|
| 90 |
+
default_compression=default_compression,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
async def get_operation(
|
| 94 |
+
self,
|
| 95 |
+
name,
|
| 96 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 97 |
+
timeout=gapic_v1.method_async.DEFAULT,
|
| 98 |
+
compression=gapic_v1.method_async.DEFAULT,
|
| 99 |
+
metadata=None,
|
| 100 |
+
):
|
| 101 |
+
"""Gets the latest state of a long-running operation.
|
| 102 |
+
|
| 103 |
+
Clients can use this method to poll the operation result at intervals
|
| 104 |
+
as recommended by the API service.
|
| 105 |
+
|
| 106 |
+
Example:
|
| 107 |
+
>>> from google.api_core import operations_v1
|
| 108 |
+
>>> api = operations_v1.OperationsClient()
|
| 109 |
+
>>> name = ''
|
| 110 |
+
>>> response = await api.get_operation(name)
|
| 111 |
+
|
| 112 |
+
Args:
|
| 113 |
+
name (str): The name of the operation resource.
|
| 114 |
+
retry (google.api_core.retry.Retry): The retry strategy to use
|
| 115 |
+
when invoking the RPC. If unspecified, the default retry from
|
| 116 |
+
the client configuration will be used. If ``None``, then this
|
| 117 |
+
method will not retry the RPC at all.
|
| 118 |
+
timeout (float): The amount of time in seconds to wait for the RPC
|
| 119 |
+
to complete. Note that if ``retry`` is used, this timeout
|
| 120 |
+
applies to each individual attempt and the overall time it
|
| 121 |
+
takes for this method to complete may be longer. If
|
| 122 |
+
unspecified, the the default timeout in the client
|
| 123 |
+
configuration is used. If ``None``, then the RPC method will
|
| 124 |
+
not time out.
|
| 125 |
+
compression (grpc.Compression): An element of grpc.compression
|
| 126 |
+
e.g. grpc.compression.Gzip.
|
| 127 |
+
metadata (Optional[List[Tuple[str, str]]]):
|
| 128 |
+
Additional gRPC metadata.
|
| 129 |
+
|
| 130 |
+
Returns:
|
| 131 |
+
google.longrunning.operations_pb2.Operation: The state of the
|
| 132 |
+
operation.
|
| 133 |
+
|
| 134 |
+
Raises:
|
| 135 |
+
google.api_core.exceptions.GoogleAPICallError: If an error occurred
|
| 136 |
+
while invoking the RPC, the appropriate ``GoogleAPICallError``
|
| 137 |
+
subclass will be raised.
|
| 138 |
+
"""
|
| 139 |
+
request = operations_pb2.GetOperationRequest(name=name)
|
| 140 |
+
|
| 141 |
+
# Add routing header
|
| 142 |
+
metadata = metadata or []
|
| 143 |
+
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
|
| 144 |
+
|
| 145 |
+
return await self._get_operation(
|
| 146 |
+
request,
|
| 147 |
+
retry=retry,
|
| 148 |
+
timeout=timeout,
|
| 149 |
+
compression=compression,
|
| 150 |
+
metadata=metadata,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
async def list_operations(
|
| 154 |
+
self,
|
| 155 |
+
name,
|
| 156 |
+
filter_,
|
| 157 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 158 |
+
timeout=gapic_v1.method_async.DEFAULT,
|
| 159 |
+
compression=gapic_v1.method_async.DEFAULT,
|
| 160 |
+
metadata=None,
|
| 161 |
+
):
|
| 162 |
+
"""
|
| 163 |
+
Lists operations that match the specified filter in the request.
|
| 164 |
+
|
| 165 |
+
Example:
|
| 166 |
+
>>> from google.api_core import operations_v1
|
| 167 |
+
>>> api = operations_v1.OperationsClient()
|
| 168 |
+
>>> name = ''
|
| 169 |
+
>>>
|
| 170 |
+
>>> # Iterate over all results
|
| 171 |
+
>>> for operation in await api.list_operations(name):
|
| 172 |
+
>>> # process operation
|
| 173 |
+
>>> pass
|
| 174 |
+
>>>
|
| 175 |
+
>>> # Or iterate over results one page at a time
|
| 176 |
+
>>> iter = await api.list_operations(name)
|
| 177 |
+
>>> for page in iter.pages:
|
| 178 |
+
>>> for operation in page:
|
| 179 |
+
>>> # process operation
|
| 180 |
+
>>> pass
|
| 181 |
+
|
| 182 |
+
Args:
|
| 183 |
+
name (str): The name of the operation collection.
|
| 184 |
+
filter_ (str): The standard list filter.
|
| 185 |
+
retry (google.api_core.retry.Retry): The retry strategy to use
|
| 186 |
+
when invoking the RPC. If unspecified, the default retry from
|
| 187 |
+
the client configuration will be used. If ``None``, then this
|
| 188 |
+
method will not retry the RPC at all.
|
| 189 |
+
timeout (float): The amount of time in seconds to wait for the RPC
|
| 190 |
+
to complete. Note that if ``retry`` is used, this timeout
|
| 191 |
+
applies to each individual attempt and the overall time it
|
| 192 |
+
takes for this method to complete may be longer. If
|
| 193 |
+
unspecified, the the default timeout in the client
|
| 194 |
+
configuration is used. If ``None``, then the RPC method will
|
| 195 |
+
not time out.
|
| 196 |
+
compression (grpc.Compression): An element of grpc.compression
|
| 197 |
+
e.g. grpc.compression.Gzip.
|
| 198 |
+
metadata (Optional[List[Tuple[str, str]]]): Additional gRPC
|
| 199 |
+
metadata.
|
| 200 |
+
|
| 201 |
+
Returns:
|
| 202 |
+
google.api_core.page_iterator.Iterator: An iterator that yields
|
| 203 |
+
:class:`google.longrunning.operations_pb2.Operation` instances.
|
| 204 |
+
|
| 205 |
+
Raises:
|
| 206 |
+
google.api_core.exceptions.MethodNotImplemented: If the server
|
| 207 |
+
does not support this method. Services are not required to
|
| 208 |
+
implement this method.
|
| 209 |
+
google.api_core.exceptions.GoogleAPICallError: If an error occurred
|
| 210 |
+
while invoking the RPC, the appropriate ``GoogleAPICallError``
|
| 211 |
+
subclass will be raised.
|
| 212 |
+
"""
|
| 213 |
+
# Create the request object.
|
| 214 |
+
request = operations_pb2.ListOperationsRequest(name=name, filter=filter_)
|
| 215 |
+
|
| 216 |
+
# Add routing header
|
| 217 |
+
metadata = metadata or []
|
| 218 |
+
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
|
| 219 |
+
|
| 220 |
+
# Create the method used to fetch pages
|
| 221 |
+
method = functools.partial(
|
| 222 |
+
self._list_operations,
|
| 223 |
+
retry=retry,
|
| 224 |
+
timeout=timeout,
|
| 225 |
+
compression=compression,
|
| 226 |
+
metadata=metadata,
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
iterator = page_iterator_async.AsyncGRPCIterator(
|
| 230 |
+
client=None,
|
| 231 |
+
method=method,
|
| 232 |
+
request=request,
|
| 233 |
+
items_field="operations",
|
| 234 |
+
request_token_field="page_token",
|
| 235 |
+
response_token_field="next_page_token",
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
return iterator
|
| 239 |
+
|
| 240 |
+
async def cancel_operation(
|
| 241 |
+
self,
|
| 242 |
+
name,
|
| 243 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 244 |
+
timeout=gapic_v1.method_async.DEFAULT,
|
| 245 |
+
compression=gapic_v1.method_async.DEFAULT,
|
| 246 |
+
metadata=None,
|
| 247 |
+
):
|
| 248 |
+
"""Starts asynchronous cancellation on a long-running operation.
|
| 249 |
+
|
| 250 |
+
The server makes a best effort to cancel the operation, but success is
|
| 251 |
+
not guaranteed. Clients can use :meth:`get_operation` or service-
|
| 252 |
+
specific methods to check whether the cancellation succeeded or whether
|
| 253 |
+
the operation completed despite cancellation. On successful
|
| 254 |
+
cancellation, the operation is not deleted; instead, it becomes an
|
| 255 |
+
operation with an ``Operation.error`` value with a
|
| 256 |
+
``google.rpc.Status.code`` of ``1``, corresponding to
|
| 257 |
+
``Code.CANCELLED``.
|
| 258 |
+
|
| 259 |
+
Example:
|
| 260 |
+
>>> from google.api_core import operations_v1
|
| 261 |
+
>>> api = operations_v1.OperationsClient()
|
| 262 |
+
>>> name = ''
|
| 263 |
+
>>> api.cancel_operation(name)
|
| 264 |
+
|
| 265 |
+
Args:
|
| 266 |
+
name (str): The name of the operation resource to be cancelled.
|
| 267 |
+
retry (google.api_core.retry.Retry): The retry strategy to use
|
| 268 |
+
when invoking the RPC. If unspecified, the default retry from
|
| 269 |
+
the client configuration will be used. If ``None``, then this
|
| 270 |
+
method will not retry the RPC at all.
|
| 271 |
+
timeout (float): The amount of time in seconds to wait for the RPC
|
| 272 |
+
to complete. Note that if ``retry`` is used, this timeout
|
| 273 |
+
applies to each individual attempt and the overall time it
|
| 274 |
+
takes for this method to complete may be longer. If
|
| 275 |
+
unspecified, the the default timeout in the client
|
| 276 |
+
configuration is used. If ``None``, then the RPC method will
|
| 277 |
+
not time out.
|
| 278 |
+
|
| 279 |
+
Raises:
|
| 280 |
+
google.api_core.exceptions.MethodNotImplemented: If the server
|
| 281 |
+
does not support this method. Services are not required to
|
| 282 |
+
implement this method.
|
| 283 |
+
google.api_core.exceptions.GoogleAPICallError: If an error occurred
|
| 284 |
+
while invoking the RPC, the appropriate ``GoogleAPICallError``
|
| 285 |
+
subclass will be raised.
|
| 286 |
+
compression (grpc.Compression): An element of grpc.compression
|
| 287 |
+
e.g. grpc.compression.Gzip.
|
| 288 |
+
metadata (Optional[List[Tuple[str, str]]]): Additional gRPC
|
| 289 |
+
metadata.
|
| 290 |
+
"""
|
| 291 |
+
# Create the request object.
|
| 292 |
+
request = operations_pb2.CancelOperationRequest(name=name)
|
| 293 |
+
|
| 294 |
+
# Add routing header
|
| 295 |
+
metadata = metadata or []
|
| 296 |
+
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
|
| 297 |
+
|
| 298 |
+
await self._cancel_operation(
|
| 299 |
+
request,
|
| 300 |
+
retry=retry,
|
| 301 |
+
timeout=timeout,
|
| 302 |
+
compression=compression,
|
| 303 |
+
metadata=metadata,
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
async def delete_operation(
|
| 307 |
+
self,
|
| 308 |
+
name,
|
| 309 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 310 |
+
timeout=gapic_v1.method_async.DEFAULT,
|
| 311 |
+
compression=gapic_v1.method_async.DEFAULT,
|
| 312 |
+
metadata=None,
|
| 313 |
+
):
|
| 314 |
+
"""Deletes a long-running operation.
|
| 315 |
+
|
| 316 |
+
This method indicates that the client is no longer interested in the
|
| 317 |
+
operation result. It does not cancel the operation.
|
| 318 |
+
|
| 319 |
+
Example:
|
| 320 |
+
>>> from google.api_core import operations_v1
|
| 321 |
+
>>> api = operations_v1.OperationsClient()
|
| 322 |
+
>>> name = ''
|
| 323 |
+
>>> api.delete_operation(name)
|
| 324 |
+
|
| 325 |
+
Args:
|
| 326 |
+
name (str): The name of the operation resource to be deleted.
|
| 327 |
+
retry (google.api_core.retry.Retry): The retry strategy to use
|
| 328 |
+
when invoking the RPC. If unspecified, the default retry from
|
| 329 |
+
the client configuration will be used. If ``None``, then this
|
| 330 |
+
method will not retry the RPC at all.
|
| 331 |
+
timeout (float): The amount of time in seconds to wait for the RPC
|
| 332 |
+
to complete. Note that if ``retry`` is used, this timeout
|
| 333 |
+
applies to each individual attempt and the overall time it
|
| 334 |
+
takes for this method to complete may be longer. If
|
| 335 |
+
unspecified, the the default timeout in the client
|
| 336 |
+
configuration is used. If ``None``, then the RPC method will
|
| 337 |
+
not time out.
|
| 338 |
+
compression (grpc.Compression): An element of grpc.compression
|
| 339 |
+
e.g. grpc.compression.Gzip.
|
| 340 |
+
metadata (Optional[List[Tuple[str, str]]]): Additional gRPC
|
| 341 |
+
metadata.
|
| 342 |
+
|
| 343 |
+
Raises:
|
| 344 |
+
google.api_core.exceptions.MethodNotImplemented: If the server
|
| 345 |
+
does not support this method. Services are not required to
|
| 346 |
+
implement this method.
|
| 347 |
+
google.api_core.exceptions.GoogleAPICallError: If an error occurred
|
| 348 |
+
while invoking the RPC, the appropriate ``GoogleAPICallError``
|
| 349 |
+
subclass will be raised.
|
| 350 |
+
"""
|
| 351 |
+
# Create the request object.
|
| 352 |
+
request = operations_pb2.DeleteOperationRequest(name=name)
|
| 353 |
+
|
| 354 |
+
# Add routing header
|
| 355 |
+
metadata = metadata or []
|
| 356 |
+
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
|
| 357 |
+
|
| 358 |
+
await self._delete_operation(
|
| 359 |
+
request,
|
| 360 |
+
retry=retry,
|
| 361 |
+
timeout=timeout,
|
| 362 |
+
compression=compression,
|
| 363 |
+
metadata=metadata,
|
| 364 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_client_config.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""gapic configuration for the google.longrunning.operations client."""
|
| 16 |
+
|
| 17 |
+
# DEPRECATED: retry and timeout classes are instantiated directly
|
| 18 |
+
config = {
|
| 19 |
+
"interfaces": {
|
| 20 |
+
"google.longrunning.Operations": {
|
| 21 |
+
"retry_codes": {
|
| 22 |
+
"idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"],
|
| 23 |
+
"non_idempotent": [],
|
| 24 |
+
},
|
| 25 |
+
"retry_params": {
|
| 26 |
+
"default": {
|
| 27 |
+
"initial_retry_delay_millis": 100,
|
| 28 |
+
"retry_delay_multiplier": 1.3,
|
| 29 |
+
"max_retry_delay_millis": 60000,
|
| 30 |
+
"initial_rpc_timeout_millis": 20000,
|
| 31 |
+
"rpc_timeout_multiplier": 1.0,
|
| 32 |
+
"max_rpc_timeout_millis": 600000,
|
| 33 |
+
"total_timeout_millis": 600000,
|
| 34 |
+
}
|
| 35 |
+
},
|
| 36 |
+
"methods": {
|
| 37 |
+
"GetOperation": {
|
| 38 |
+
"timeout_millis": 60000,
|
| 39 |
+
"retry_codes_name": "idempotent",
|
| 40 |
+
"retry_params_name": "default",
|
| 41 |
+
},
|
| 42 |
+
"ListOperations": {
|
| 43 |
+
"timeout_millis": 60000,
|
| 44 |
+
"retry_codes_name": "idempotent",
|
| 45 |
+
"retry_params_name": "default",
|
| 46 |
+
},
|
| 47 |
+
"CancelOperation": {
|
| 48 |
+
"timeout_millis": 60000,
|
| 49 |
+
"retry_codes_name": "idempotent",
|
| 50 |
+
"retry_params_name": "default",
|
| 51 |
+
},
|
| 52 |
+
"DeleteOperation": {
|
| 53 |
+
"timeout_millis": 60000,
|
| 54 |
+
"retry_codes_name": "idempotent",
|
| 55 |
+
"retry_params_name": "default",
|
| 56 |
+
},
|
| 57 |
+
},
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/operations_rest_client_async.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#
|
| 16 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 17 |
+
|
| 18 |
+
from google.api_core import client_options as client_options_lib # type: ignore
|
| 19 |
+
from google.api_core import gapic_v1 # type: ignore
|
| 20 |
+
from google.api_core.operations_v1 import pagers_async as pagers
|
| 21 |
+
from google.api_core.operations_v1.transports.base import (
|
| 22 |
+
DEFAULT_CLIENT_INFO,
|
| 23 |
+
OperationsTransport,
|
| 24 |
+
)
|
| 25 |
+
from google.api_core.operations_v1.abstract_operations_base_client import (
|
| 26 |
+
AbstractOperationsBaseClient,
|
| 27 |
+
)
|
| 28 |
+
from google.longrunning import operations_pb2
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
from google.auth.aio import credentials as ga_credentials # type: ignore
|
| 32 |
+
except ImportError as e: # pragma: NO COVER
|
| 33 |
+
raise ImportError(
|
| 34 |
+
"The `async_rest` extra of `google-api-core` is required to use long-running operations. Install it by running "
|
| 35 |
+
"`pip install google-api-core[async_rest]`."
|
| 36 |
+
) from e
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class AsyncOperationsRestClient(AbstractOperationsBaseClient):
|
| 40 |
+
"""Manages long-running operations with a REST API service for the asynchronous client.
|
| 41 |
+
|
| 42 |
+
When an API method normally takes long time to complete, it can be
|
| 43 |
+
designed to return [Operation][google.api_core.operations_v1.Operation] to the
|
| 44 |
+
client, and the client can use this interface to receive the real
|
| 45 |
+
response asynchronously by polling the operation resource, or pass
|
| 46 |
+
the operation resource to another API (such as Google Cloud Pub/Sub
|
| 47 |
+
API) to receive the response. Any API service that returns
|
| 48 |
+
long-running operations should implement the ``Operations``
|
| 49 |
+
interface so developers can have a consistent client experience.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(
|
| 53 |
+
self,
|
| 54 |
+
*,
|
| 55 |
+
credentials: Optional[ga_credentials.Credentials] = None,
|
| 56 |
+
transport: Union[str, OperationsTransport, None] = None,
|
| 57 |
+
client_options: Optional[client_options_lib.ClientOptions] = None,
|
| 58 |
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
| 59 |
+
) -> None:
|
| 60 |
+
"""Instantiates the operations client.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
credentials (Optional[google.auth.aio.credentials.Credentials]): The
|
| 64 |
+
authorization credentials to attach to requests. These
|
| 65 |
+
credentials identify the application to the service; if none
|
| 66 |
+
are specified, the client will attempt to ascertain the
|
| 67 |
+
credentials from the environment.
|
| 68 |
+
transport (Union[str, OperationsTransport]): The
|
| 69 |
+
transport to use. If set to None, this defaults to 'rest_asyncio'.
|
| 70 |
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
| 71 |
+
client. It won't take effect if a ``transport`` instance is provided.
|
| 72 |
+
(1) The ``api_endpoint`` property can be used to override the
|
| 73 |
+
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
|
| 74 |
+
environment variable can also be used to override the endpoint:
|
| 75 |
+
"always" (always use the default mTLS endpoint), "never" (always
|
| 76 |
+
use the default regular endpoint) and "auto" (auto switch to the
|
| 77 |
+
default mTLS endpoint if client certificate is present, this is
|
| 78 |
+
the default value). However, the ``api_endpoint`` property takes
|
| 79 |
+
precedence if provided.
|
| 80 |
+
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
| 81 |
+
is "true", then the ``client_cert_source`` property can be used
|
| 82 |
+
to provide client certificate for mutual TLS transport. If
|
| 83 |
+
not provided, the default SSL client certificate will be used if
|
| 84 |
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
| 85 |
+
set, no client certificate will be used.
|
| 86 |
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
| 87 |
+
The client info used to send a user-agent string along with
|
| 88 |
+
API requests. If ``None``, then default info will be used.
|
| 89 |
+
Generally, you only need to set this if you're developing
|
| 90 |
+
your own client library.
|
| 91 |
+
|
| 92 |
+
Raises:
|
| 93 |
+
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
|
| 94 |
+
creation failed for any reason.
|
| 95 |
+
"""
|
| 96 |
+
super().__init__(
|
| 97 |
+
credentials=credentials, # type: ignore
|
| 98 |
+
# NOTE: If a transport is not provided, we force the client to use the async
|
| 99 |
+
# REST transport.
|
| 100 |
+
transport=transport or "rest_asyncio",
|
| 101 |
+
client_options=client_options,
|
| 102 |
+
client_info=client_info,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
async def get_operation(
|
| 106 |
+
self,
|
| 107 |
+
name: str,
|
| 108 |
+
*,
|
| 109 |
+
# TODO(https://github.com/googleapis/python-api-core/issues/722): Leverage `retry`
|
| 110 |
+
# to allow configuring retryable error codes.
|
| 111 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 112 |
+
timeout: Optional[float] = None,
|
| 113 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 114 |
+
) -> operations_pb2.Operation:
|
| 115 |
+
r"""Gets the latest state of a long-running operation.
|
| 116 |
+
Clients can use this method to poll the operation result
|
| 117 |
+
at intervals as recommended by the API service.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
name (str):
|
| 121 |
+
The name of the operation resource.
|
| 122 |
+
timeout (float): The timeout for this request.
|
| 123 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 124 |
+
sent along with the request as metadata.
|
| 125 |
+
|
| 126 |
+
Returns:
|
| 127 |
+
google.longrunning.operations_pb2.Operation:
|
| 128 |
+
This resource represents a long-
|
| 129 |
+
running operation that is the result of a
|
| 130 |
+
network API call.
|
| 131 |
+
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
request = operations_pb2.GetOperationRequest(name=name)
|
| 135 |
+
|
| 136 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 137 |
+
# and friendly error handling.
|
| 138 |
+
rpc = self._transport._wrapped_methods[self._transport.get_operation]
|
| 139 |
+
|
| 140 |
+
# Certain fields should be provided within the metadata header;
|
| 141 |
+
# add these here.
|
| 142 |
+
metadata = tuple(metadata or ()) + (
|
| 143 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
# Send the request.
|
| 147 |
+
response = await rpc(
|
| 148 |
+
request,
|
| 149 |
+
retry=retry,
|
| 150 |
+
timeout=timeout,
|
| 151 |
+
metadata=metadata,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
# Done; return the response.
|
| 155 |
+
return response
|
| 156 |
+
|
| 157 |
+
async def list_operations(
|
| 158 |
+
self,
|
| 159 |
+
name: str,
|
| 160 |
+
filter_: Optional[str] = None,
|
| 161 |
+
*,
|
| 162 |
+
page_size: Optional[int] = None,
|
| 163 |
+
page_token: Optional[str] = None,
|
| 164 |
+
# TODO(https://github.com/googleapis/python-api-core/issues/722): Leverage `retry`
|
| 165 |
+
# to allow configuring retryable error codes.
|
| 166 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 167 |
+
timeout: Optional[float] = None,
|
| 168 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 169 |
+
) -> pagers.ListOperationsAsyncPager:
|
| 170 |
+
r"""Lists operations that match the specified filter in the request.
|
| 171 |
+
If the server doesn't support this method, it returns
|
| 172 |
+
``UNIMPLEMENTED``.
|
| 173 |
+
|
| 174 |
+
NOTE: the ``name`` binding allows API services to override the
|
| 175 |
+
binding to use different resource name schemes, such as
|
| 176 |
+
``users/*/operations``. To override the binding, API services
|
| 177 |
+
can add a binding such as ``"/v1/{name=users/*}/operations"`` to
|
| 178 |
+
their service configuration. For backwards compatibility, the
|
| 179 |
+
default name includes the operations collection id, however
|
| 180 |
+
overriding users must ensure the name binding is the parent
|
| 181 |
+
resource, without the operations collection id.
|
| 182 |
+
|
| 183 |
+
Args:
|
| 184 |
+
name (str):
|
| 185 |
+
The name of the operation's parent
|
| 186 |
+
resource.
|
| 187 |
+
filter_ (str):
|
| 188 |
+
The standard list filter.
|
| 189 |
+
This corresponds to the ``filter`` field
|
| 190 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 191 |
+
should not be set.
|
| 192 |
+
timeout (float): The timeout for this request.
|
| 193 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 194 |
+
sent along with the request as metadata.
|
| 195 |
+
|
| 196 |
+
Returns:
|
| 197 |
+
google.api_core.operations_v1.pagers.ListOperationsPager:
|
| 198 |
+
The response message for
|
| 199 |
+
[Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations].
|
| 200 |
+
|
| 201 |
+
Iterating over this object will yield results and
|
| 202 |
+
resolve additional pages automatically.
|
| 203 |
+
|
| 204 |
+
"""
|
| 205 |
+
# Create a protobuf request object.
|
| 206 |
+
request = operations_pb2.ListOperationsRequest(name=name, filter=filter_)
|
| 207 |
+
if page_size is not None:
|
| 208 |
+
request.page_size = page_size
|
| 209 |
+
if page_token is not None:
|
| 210 |
+
request.page_token = page_token
|
| 211 |
+
|
| 212 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 213 |
+
# and friendly error handling.
|
| 214 |
+
rpc = self._transport._wrapped_methods[self._transport.list_operations]
|
| 215 |
+
|
| 216 |
+
# Certain fields should be provided within the metadata header;
|
| 217 |
+
# add these here.
|
| 218 |
+
metadata = tuple(metadata or ()) + (
|
| 219 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# Send the request.
|
| 223 |
+
response = await rpc(
|
| 224 |
+
request,
|
| 225 |
+
retry=retry,
|
| 226 |
+
timeout=timeout,
|
| 227 |
+
metadata=metadata,
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
# This method is paged; wrap the response in a pager, which provides
|
| 231 |
+
# an `__iter__` convenience method.
|
| 232 |
+
response = pagers.ListOperationsAsyncPager(
|
| 233 |
+
method=rpc,
|
| 234 |
+
request=request,
|
| 235 |
+
response=response,
|
| 236 |
+
metadata=metadata,
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
# Done; return the response.
|
| 240 |
+
return response
|
| 241 |
+
|
| 242 |
+
async def delete_operation(
|
| 243 |
+
self,
|
| 244 |
+
name: str,
|
| 245 |
+
*,
|
| 246 |
+
# TODO(https://github.com/googleapis/python-api-core/issues/722): Leverage `retry`
|
| 247 |
+
# to allow configuring retryable error codes.
|
| 248 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 249 |
+
timeout: Optional[float] = None,
|
| 250 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 251 |
+
) -> None:
|
| 252 |
+
r"""Deletes a long-running operation. This method indicates that the
|
| 253 |
+
client is no longer interested in the operation result. It does
|
| 254 |
+
not cancel the operation. If the server doesn't support this
|
| 255 |
+
method, it returns ``google.rpc.Code.UNIMPLEMENTED``.
|
| 256 |
+
|
| 257 |
+
Args:
|
| 258 |
+
name (str):
|
| 259 |
+
The name of the operation resource to
|
| 260 |
+
be deleted.
|
| 261 |
+
|
| 262 |
+
This corresponds to the ``name`` field
|
| 263 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 264 |
+
should not be set.
|
| 265 |
+
timeout (float): The timeout for this request.
|
| 266 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 267 |
+
sent along with the request as metadata.
|
| 268 |
+
"""
|
| 269 |
+
# Create the request object.
|
| 270 |
+
request = operations_pb2.DeleteOperationRequest(name=name)
|
| 271 |
+
|
| 272 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 273 |
+
# and friendly error handling.
|
| 274 |
+
rpc = self._transport._wrapped_methods[self._transport.delete_operation]
|
| 275 |
+
|
| 276 |
+
# Certain fields should be provided within the metadata header;
|
| 277 |
+
# add these here.
|
| 278 |
+
metadata = tuple(metadata or ()) + (
|
| 279 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
# Send the request.
|
| 283 |
+
await rpc(
|
| 284 |
+
request,
|
| 285 |
+
retry=retry,
|
| 286 |
+
timeout=timeout,
|
| 287 |
+
metadata=metadata,
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
async def cancel_operation(
|
| 291 |
+
self,
|
| 292 |
+
name: Optional[str] = None,
|
| 293 |
+
*,
|
| 294 |
+
# TODO(https://github.com/googleapis/python-api-core/issues/722): Leverage `retry`
|
| 295 |
+
# to allow configuring retryable error codes.
|
| 296 |
+
retry=gapic_v1.method_async.DEFAULT,
|
| 297 |
+
timeout: Optional[float] = None,
|
| 298 |
+
metadata: Sequence[Tuple[str, str]] = (),
|
| 299 |
+
) -> None:
|
| 300 |
+
r"""Starts asynchronous cancellation on a long-running operation.
|
| 301 |
+
The server makes a best effort to cancel the operation, but
|
| 302 |
+
success is not guaranteed. If the server doesn't support this
|
| 303 |
+
method, it returns ``google.rpc.Code.UNIMPLEMENTED``. Clients
|
| 304 |
+
can use
|
| 305 |
+
[Operations.GetOperation][google.api_core.operations_v1.Operations.GetOperation]
|
| 306 |
+
or other methods to check whether the cancellation succeeded or
|
| 307 |
+
whether the operation completed despite cancellation. On
|
| 308 |
+
successful cancellation, the operation is not deleted; instead,
|
| 309 |
+
it becomes an operation with an
|
| 310 |
+
[Operation.error][google.api_core.operations_v1.Operation.error] value with
|
| 311 |
+
a [google.rpc.Status.code][google.rpc.Status.code] of 1,
|
| 312 |
+
corresponding to ``Code.CANCELLED``.
|
| 313 |
+
|
| 314 |
+
Args:
|
| 315 |
+
name (str):
|
| 316 |
+
The name of the operation resource to
|
| 317 |
+
be cancelled.
|
| 318 |
+
|
| 319 |
+
This corresponds to the ``name`` field
|
| 320 |
+
on the ``request`` instance; if ``request`` is provided, this
|
| 321 |
+
should not be set.
|
| 322 |
+
timeout (float): The timeout for this request.
|
| 323 |
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
| 324 |
+
sent along with the request as metadata.
|
| 325 |
+
"""
|
| 326 |
+
# Create the request object.
|
| 327 |
+
request = operations_pb2.CancelOperationRequest(name=name)
|
| 328 |
+
|
| 329 |
+
# Wrap the RPC method; this adds retry and timeout information,
|
| 330 |
+
# and friendly error handling.
|
| 331 |
+
rpc = self._transport._wrapped_methods[self._transport.cancel_operation]
|
| 332 |
+
|
| 333 |
+
# Certain fields should be provided within the metadata header;
|
| 334 |
+
# add these here.
|
| 335 |
+
metadata = tuple(metadata or ()) + (
|
| 336 |
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
# Send the request.
|
| 340 |
+
await rpc(
|
| 341 |
+
request,
|
| 342 |
+
retry=retry,
|
| 343 |
+
timeout=timeout,
|
| 344 |
+
metadata=metadata,
|
| 345 |
+
)
|
.venv/lib/python3.11/site-packages/google/api_core/operations_v1/pagers.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
# Copyright 2020 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 |
+
#
|
| 16 |
+
from typing import (
|
| 17 |
+
Callable,
|
| 18 |
+
Iterator,
|
| 19 |
+
Sequence,
|
| 20 |
+
Tuple,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from google.longrunning import operations_pb2
|
| 24 |
+
from google.api_core.operations_v1.pagers_base import ListOperationsPagerBase
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class ListOperationsPager(ListOperationsPagerBase):
|
| 28 |
+
"""A pager for iterating through ``list_operations`` requests.
|
| 29 |
+
|
| 30 |
+
This class thinly wraps an initial
|
| 31 |
+
:class:`google.longrunning.operations_pb2.ListOperationsResponse` object, and
|
| 32 |
+
provides an ``__iter__`` method to iterate through its
|
| 33 |
+
``operations`` field.
|
| 34 |
+
|
| 35 |
+
If there are more pages, the ``__iter__`` method will make additional
|
| 36 |
+
``ListOperations`` requests and continue to iterate
|
| 37 |
+
through the ``operations`` field on the
|
| 38 |
+
corresponding responses.
|
| 39 |
+
|
| 40 |
+
All the usual :class:`google.longrunning.operations_pb2.ListOperationsResponse`
|
| 41 |
+
attributes are available on the pager. If multiple requests are made, only
|
| 42 |
+
the most recent response is retained, and thus used for attribute lookup.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(
|
| 46 |
+
self,
|
| 47 |
+
method: Callable[..., operations_pb2.ListOperationsResponse],
|
| 48 |
+
request: operations_pb2.ListOperationsRequest,
|
| 49 |
+
response: operations_pb2.ListOperationsResponse,
|
| 50 |
+
*,
|
| 51 |
+
metadata: Sequence[Tuple[str, str]] = ()
|
| 52 |
+
):
|
| 53 |
+
super().__init__(
|
| 54 |
+
method=method, request=request, response=response, metadata=metadata
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def pages(self) -> Iterator[operations_pb2.ListOperationsResponse]:
|
| 59 |
+
yield self._response
|
| 60 |
+
while self._response.next_page_token:
|
| 61 |
+
self._request.page_token = self._response.next_page_token
|
| 62 |
+
self._response = self._method(self._request, metadata=self._metadata)
|
| 63 |
+
yield self._response
|
| 64 |
+
|
| 65 |
+
def __iter__(self) -> Iterator[operations_pb2.Operation]:
|
| 66 |
+
for page in self.pages:
|
| 67 |
+
yield from page.operations
|