@@ -137,6 +137,8 @@ def wrap_method(
137
137
default_timeout = None ,
138
138
default_compression = None ,
139
139
client_info = client_info .DEFAULT_CLIENT_INFO ,
140
+ * ,
141
+ with_call = False ,
140
142
):
141
143
"""Wrap an RPC method with common behavior.
142
144
@@ -216,13 +218,24 @@ def get_topic(name, timeout=None):
216
218
passed as gRPC metadata to the method. If unspecified, then
217
219
a sane default will be used. If ``None``, then no user agent
218
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.
219
225
220
226
Returns:
221
227
Callable: A new callable that takes optional ``retry``, ``timeout``,
222
228
and ``compression``
223
229
arguments and applies the common error mapping, retry, timeout, compression,
224
230
and metadata behavior to the low-level RPC method.
225
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
226
239
func = grpc_helpers .wrap_errors (func )
227
240
if client_info is not None :
228
241
user_agent_metadata = [client_info .to_grpc_metadata ()]
0 commit comments