-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add support for async rest streaming methods #2146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ from google.api_core import exceptions as core_exceptions | |
| from google.api_core import gapic_v1 | ||
| from google.api_core import retry_async as retries | ||
| from google.api_core import rest_helpers | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2137): raise an import error if an older version of google.api.core is installed. #} | ||
| from google.api_core import rest_streaming_async # type: ignore | ||
|
|
||
| try: | ||
| from google.api_core import rest_streaming_async # type: ignore | ||
|
|
@@ -128,30 +130,27 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): | |
| def __hash__(self): | ||
| return hash("Async{{service.name}}RestTransport.{{method.name}}") | ||
|
|
||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2168): Implement server streaming method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2169): Implement client streaming method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2170): Implement long running operation method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2171): Implement pager method. #} | ||
| {% if method.http_options and not method.client_streaming and not method.server_streaming and not method.lro and not method.extended_lro and not method.paged_result_field %} | ||
| {% if method.http_options and not method.client_streaming and not method.lro and not method.extended_lro and not method.paged_result_field %} | ||
| {% set body_spec = method.http_options[0].body %} | ||
| {{ shared_macros.response_method(body_spec, is_async=True)|indent(8) }} | ||
|
|
||
| {% endif %}{# method.http_options and not method.client_streaming and not method.server_streaming and not method.lro and not method.extended_lro and not method.paged_result_field #} | ||
| {% endif %}{# method.http_options and not method.client_streaming and not method.lro and not method.extended_lro and not method.paged_result_field #} | ||
| async def __call__(self, | ||
| request: {{method.input.ident}}, *, | ||
| retry: OptionalRetry=gapic_v1.method.DEFAULT, | ||
| timeout: Optional[float]=None, | ||
| metadata: Sequence[Tuple[str, str]]=(), | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2168): Update return type for server streaming method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2169): Update return type for client streaming method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2170): Update the return type for long running operation method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2171): Update the return type for pager method. #} | ||
| ){% if not method.void %} -> {% if not method.server_streaming %}{{method.output.ident}}{% else %}None{% endif %}{% endif %}: | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2168): Implement server streaming method. #} | ||
| ){% if not method.void %} -> {% if not method.server_streaming %}{{method.output.ident}}{% else %}rest_streaming_async.AsyncResponseIterator{% endif %}{% endif %}: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this present in any of the golden files? A search in this PR for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes can be seen here: #2188 |
||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2169): Implement client streaming method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2170): Implement long running operation method. #} | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2171): Implement pager method. #} | ||
| {% if method.http_options and not method.client_streaming and not method.server_streaming and not method.lro and not method.extended_lro and not method.paged_result_field %} | ||
| {% if method.http_options and not method.client_streaming and not method.lro and not method.extended_lro and not method.paged_result_field %} | ||
| r"""Call the {{- ' ' -}} | ||
| {{ (method.name|snake_case).replace('_',' ')|wrap( | ||
| width=70, offset=45, indent=8) }} | ||
|
|
@@ -178,14 +177,19 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): | |
|
|
||
| {% if not method.void %} | ||
| # Return the response | ||
| {% if method.server_streaming %} | ||
| resp = rest_streaming_async.AsyncResponseIterator(response, {{method.output.ident}}) | ||
| {% else %} | ||
| resp = {{method.output.ident}}() | ||
| {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2189): Investigate if the proto-plus conversion below is needed for a streaming response. #} | ||
| {% if method.output.ident.is_proto_plus_type %} | ||
| pb_resp = {{method.output.ident}}.pb(resp) | ||
| {% else %} | ||
| pb_resp = resp | ||
| {% endif %} | ||
| {% endif %}{# if method.output.ident.is_proto_plus_type #} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One question: we handle proto_plus explicitly in the non-streaming case here. But what about in streaming results? Looking at api-core's
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've filed https://github.com/googleapis/gapic-generator-python/issues/2189 to Investigate this later. |
||
| content = await response.read() | ||
| json_format.Parse(content, pb_resp, ignore_unknown_fields=True) | ||
| {% endif %}{# if method.server_streaming #} | ||
| return resp | ||
|
|
||
| {% endif %}{# method.void #} | ||
|
|
@@ -194,7 +198,7 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): | |
| raise NotImplementedError( | ||
| "Method {{ method.name }} is not available over REST transport" | ||
| ) | ||
| {% endif %}{# method.http_options and not method.client_streaming and not method.server_streaming and not method.lro and not method.extended_lro and not method.paged_result_field #} | ||
| {% endif %}{# method.http_options and not method.client_streaming and not method.lro and not method.extended_lro and not method.paged_result_field #} | ||
|
|
||
| {% endfor %} | ||
| {% for method in service.methods.values()|sort(attribute="name") %} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.