Skip to content

Commit

Permalink
Merge pull request #4 from pachyderm/remove-generated-servicer
Browse files Browse the repository at this point in the history
remove servicer code from the template
  • Loading branch information
bbonenfant authored Feb 21, 2024
2 parents 549f723 + 4547713 commit e45f6ad
Showing 1 changed file with 0 additions and 61 deletions.
61 changes: 0 additions & 61 deletions src/betterproto/templates/template.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -171,64 +171,3 @@ class {{ service.py_name }}Stub:
{% endif %}
{% endfor %}
{% endfor %}

{% for service in output_file.services %}
class {{ service.py_name }}Base:
{% if service.comment %}
{{ service.comment }}

{% endif %}

{% for method in service.methods %}
def {{ method.py_name }}(self
{%- if not method.client_streaming -%}
{%- if method.py_input_message and method.py_input_message.fields -%},
{%- for field in method.py_input_message.fields -%}
{{ field.py_name }}: {% if field.py_name in method.mutable_default_args and not field.annotation.startswith("Optional[") -%}
Optional[{{ field.annotation }}]
{%- else -%}
{{ field.annotation }}
{%- endif -%}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{# Client streaming: need a request iterator instead #}
, request_iterator: Iterator["{{ method.py_input_message_type }}"]
{%- endif -%}
, context: "grpc.ServicerContext"
) -> {% if method.server_streaming %}Iterator["{{ method.py_output_message_type }}"]{% else %}"{{ method.py_output_message_type }}"{% endif %}:
{% if method.comment %}
{{ method.comment }}

{% endif %}
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

{% endfor %}

__proto_path__ = "{{ service.proto_path }}"

@property
def __rpc_methods__(self):
return {
{% for method in service.methods %}
"{{ method.proto_name }}":
{% if not method.client_streaming and not method.server_streaming %}
grpc.unary_unary_rpc_method_handler(
{% elif method.client_streaming and method.server_streaming %}
grpc.stream_stream_rpc_method_handler(
{% elif method.client_streaming %}
grpc.stream_unary_rpc_method_handler(
{% else %}
grpc.unary_stream_rpc_method_handler(
{% endif %}
self.{{ method.py_name }},
request_deserializer={{ method.py_input_message_type }}.FromString,
response_serializer={{ method.py_input_message_type }}.SerializeToString,
),
{% endfor %}
}

{% endfor %}

0 comments on commit e45f6ad

Please sign in to comment.