Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/api_core/gapic_v1/method_async.py: 73%
11 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 07:30 +0000
1# 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.
16This is used by gapic clients to provide common error mapping, retry, timeout,
17pagination, and long-running operations to gRPC methods.
18"""
20import functools
22from google.api_core import grpc_helpers_async
23from google.api_core.gapic_v1 import client_info
24from google.api_core.gapic_v1.method import _GapicCallable
25from google.api_core.gapic_v1.method import DEFAULT # noqa: F401
26from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401
29def wrap_method(
30 func,
31 default_retry=None,
32 default_timeout=None,
33 client_info=client_info.DEFAULT_CLIENT_INFO,
34):
35 """Wrap an async RPC method with common behavior.
37 Returns:
38 Callable: A new callable that takes optional ``retry`` and ``timeout``
39 arguments and applies the common error mapping, retry, timeout,
40 and metadata behavior to the low-level RPC method.
41 """
42 func = grpc_helpers_async.wrap_errors(func)
44 metadata = [client_info.to_grpc_metadata()] if client_info is not None else None
46 return functools.wraps(func)(
47 _GapicCallable(func, default_retry, default_timeout, metadata=metadata)
48 )