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.3.2, created at 2023-12-08 06:45 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:45 +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,
17compression, pagination, 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 default_compression=None,
34 client_info=client_info.DEFAULT_CLIENT_INFO,
35):
36 """Wrap an async RPC method with common behavior.
38 Returns:
39 Callable: A new callable that takes optional ``retry``, ``timeout``,
40 and ``compression`` arguments and applies the common error mapping,
41 retry, timeout, metadata, and compression behavior to the low-level RPC method.
42 """
43 func = grpc_helpers_async.wrap_errors(func)
45 metadata = [client_info.to_grpc_metadata()] if client_info is not None else None
47 return functools.wraps(func)(
48 _GapicCallable(
49 func,
50 default_retry,
51 default_timeout,
52 default_compression,
53 metadata=metadata,
54 )
55 )