forked from ni/nimi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialization_method.py.mako
More file actions
29 lines (26 loc) · 1.38 KB
/
initialization_method.py.mako
File metadata and controls
29 lines (26 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<%page args="f, config, method_template, grpc_types_var, grpc_client_var"/>\
<%
'''Renders a GrpcStubInterpreter initialization method, adding proto-specific fields to the passed-in function metadata.'''
import build.helper as helper
full_func_name = f['interpreter_name'] + method_template['method_python_name_suffix']
method_decl_params = helper.get_params_snippet(f, helper.ParameterUsageOptions.INTERPRETER_METHOD_DECLARATION)
grpc_name = f.get('grpc_name', f['name'])
grpc_request_args = helper.get_params_snippet(f, helper.ParameterUsageOptions.GRPC_REQUEST_PARAMETERS)
return_statement = helper.get_grpc_interpreter_method_return_snippet(f['parameters'], config)
if return_statement == 'return':
return_statement = None
capture_response = 'response = ' if return_statement else ''
%>\
def ${full_func_name}(${method_decl_params}): # noqa: N802
metadata = (
('ni-api-key', self._grpc_options.api_key),
)
${capture_response}self._invoke(
self._client.${grpc_name},
grpc_types.${grpc_name}Request(${grpc_request_args}, session_name=self._grpc_options.session_name, initialization_behavior=self._grpc_options.initialization_behavior),
metadata=metadata,
)
self._close_on_exit = response.new_session_initialized
% if return_statement:
${return_statement}
% endif