@@ -70,103 +70,11 @@ class {{ message.py_name }}(betterproto2.Message):
70
70
{% endif %}
71
71
72
72
{% endfor %}
73
- {% for _ , service in output_file .services |dictsort (by ="key" ) %}
74
- class {{ service.py_name }}Stub(betterproto2.ServiceStub):
75
- {% if service .comment %}
76
- """
77
- {{ service.comment | indent(4) }}
78
- """
79
- {% elif not service .methods %}
80
- pass
81
- {% endif %}
82
-
83
- {% for method in service .methods %}
84
- async def {{ method.py_name }}(self
85
- {% - if not method .client_streaming -%}
86
- , {{ method.py_input_message_param }}:
87
- {% - if method .is_input_msg_empty -%}
88
- "{{ method.py_input_message_type }} | None" = None
89
- {% - else -%}
90
- "{{ method.py_input_message_type }}"
91
- {% - endif -%}
92
- {% - else -%}
93
- {# Client streaming: need a request iterator instead #}
94
- , {{ method.py_input_message_param }}_iterator: "{{ output_file.typing_compiler.union(output_file.typing_compiler.async_iterable(method.py_input_message_type), output_file.typing_compiler.iterable(method.py_input_message_type)) }}"
95
- {% - endif -%}
96
- ,
97
- *
98
- , timeout: {{ output_file.typing_compiler.optional("float") }} = None
99
- , deadline: "{{ output_file.typing_compiler.optional("Deadline") }}" = None
100
- , metadata: "{{ output_file.typing_compiler.optional("MetadataLike") }}" = None
101
- ) -> "{% if method .server_streaming %} {{ output_file.typing_compiler.async_iterator(method.py_output_message_type ) }}{% else %} {{ method.py_output_message_type }}{% endif %} ":
102
- {% if method .comment %}
103
- """
104
- {{ method.comment | indent(8) }}
105
- """
106
- {% endif %}
107
-
108
- {% if method .proto_obj .options and method .proto_obj .options .deprecated %}
109
- warnings.warn("{{ service.py_name }}.{{ method.py_name }} is deprecated", DeprecationWarning)
110
- {% endif %}
111
-
112
- {% if method .server_streaming %}
113
- {% if method .client_streaming %}
114
- async for response in self._stream_stream(
115
- "{{ method.route }}",
116
- {{ method.py_input_message_param }}_iterator,
117
- {{ method.py_input_message_type }},
118
- {{ method.py_output_message_type }},
119
- timeout=timeout,
120
- deadline=deadline,
121
- metadata=metadata,
122
- ):
123
- yield response
124
- {% else %} {# i.e. not client streaming #}
125
- {% if method .is_input_msg_empty %}
126
- if {{ method.py_input_message_param }} is None:
127
- {{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
128
-
129
- {% endif %}
130
- async for response in self._unary_stream(
131
- "{{ method.route }}",
132
- {{ method.py_input_message_param }},
133
- {{ method.py_output_message_type }},
134
- timeout=timeout,
135
- deadline=deadline,
136
- metadata=metadata,
137
- ):
138
- yield response
139
-
140
- {% endif %} {# if client streaming #}
141
- {% else %} {# i.e. not server streaming #}
142
- {% if method .client_streaming %}
143
- return await self._stream_unary(
144
- "{{ method.route }}",
145
- {{ method.py_input_message_param }}_iterator,
146
- {{ method.py_input_message_type }},
147
- {{ method.py_output_message_type }},
148
- timeout=timeout,
149
- deadline=deadline,
150
- metadata=metadata,
151
- )
152
- {% else %} {# i.e. not client streaming #}
153
- {% if method .is_input_msg_empty %}
154
- if {{ method.py_input_message_param }} is None:
155
- {{ method.py_input_message_param }} = {{ method.py_input_message_type }}()
156
73
157
- {% endif %}
158
- return await self._unary_unary(
159
- "{{ method.route }}",
160
- {{ method.py_input_message_param }},
161
- {{ method.py_output_message_type }},
162
- timeout=timeout,
163
- deadline=deadline,
164
- metadata=metadata,
165
- )
166
- {% endif %} {# client streaming #}
167
- {% endif %}
74
+ {% for _ , service in output_file .services |dictsort (by ="key" ) %}
75
+ {% include "service_stub_async.py.j2" %}
168
76
169
- {% endfor %}
77
+ {% include "service_stub_sync.py.j2" %}
170
78
{% endfor %}
171
79
172
80
{% for i in output_file .imports_end %}
0 commit comments