Skip to content
Permalink
Browse files
feat: add context manager support in client (#268)
- [ ] Regenerate this pull request now.

chore: fix docstring for first attribute of protos

committer: @busunkim96
PiperOrigin-RevId: 401271153

Source-Link: googleapis/googleapis@787f8c9

Source-Link: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 7, 2021
1 parent ab60c96 commit a5e200515c621695c8c8ed76f739e0b744f32382
Show file tree
Hide file tree
Showing 22 changed files with 278 additions and 12 deletions.
@@ -460,6 +460,12 @@ def streaming_recognize(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -329,10 +329,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def recognize(
@@ -610,6 +607,19 @@ def streaming_recognize(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -191,6 +191,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
@@ -331,5 +331,8 @@ def streaming_recognize(
)
return self._stubs["streaming_recognize"]

def close(self):
self.grpc_channel.close()


__all__ = ("SpeechGrpcTransport",)
@@ -340,5 +340,8 @@ def streaming_recognize(
)
return self._stubs["streaming_recognize"]

def close(self):
return self.grpc_channel.close()


__all__ = ("SpeechGrpcAsyncIOTransport",)
@@ -381,6 +381,7 @@ class AudioEncoding(proto.Enum):

class SpeakerDiarizationConfig(proto.Message):
r"""Config to enable speaker diarization.
Attributes:
enable_speaker_diarization (bool):
If 'true', enables speaker detection for each recognized
@@ -410,6 +411,7 @@ class SpeakerDiarizationConfig(proto.Message):

class RecognitionMetadata(proto.Message):
r"""Description of audio data to be recognized.
Attributes:
interaction_type (google.cloud.speech_v1.types.RecognitionMetadata.InteractionType):
The use case most closely describing the
@@ -793,6 +795,7 @@ class SpeechRecognitionResult(proto.Message):

class SpeechRecognitionAlternative(proto.Message):
r"""Alternative hypotheses (a.k.a. n-best list).
Attributes:
transcript (str):
Transcript text representing the words that
@@ -819,6 +822,7 @@ class SpeechRecognitionAlternative(proto.Message):

class WordInfo(proto.Message):
r"""Word-specific information for recognized words.
Attributes:
start_time (google.protobuf.duration_pb2.Duration):
Time offset relative to the beginning of the audio, and
@@ -971,6 +971,12 @@ async def delete_custom_class(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -360,10 +360,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def create_phrase_set(
@@ -1178,6 +1175,19 @@ def delete_custom_class(
request, retry=retry, timeout=timeout, metadata=metadata,
)

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -186,6 +186,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def create_phrase_set(
self,
@@ -502,5 +502,8 @@ def delete_custom_class(
)
return self._stubs["delete_custom_class"]

def close(self):
self.grpc_channel.close()


__all__ = ("AdaptationGrpcTransport",)
@@ -517,5 +517,8 @@ def delete_custom_class(
)
return self._stubs["delete_custom_class"]

def close(self):
return self.grpc_channel.close()


__all__ = ("AdaptationGrpcAsyncIOTransport",)
@@ -464,6 +464,12 @@ def streaming_recognize(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -361,10 +361,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def recognize(
@@ -642,6 +639,19 @@ def streaming_recognize(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -191,6 +191,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
@@ -331,5 +331,8 @@ def streaming_recognize(
)
return self._stubs["streaming_recognize"]

def close(self):
self.grpc_channel.close()


__all__ = ("SpeechGrpcTransport",)
@@ -340,5 +340,8 @@ def streaming_recognize(
)
return self._stubs["streaming_recognize"]

def close(self):
return self.grpc_channel.close()


__all__ = ("SpeechGrpcAsyncIOTransport",)
@@ -461,6 +461,7 @@ class AudioEncoding(proto.Enum):

class SpeakerDiarizationConfig(proto.Message):
r"""Config to enable speaker diarization.
Attributes:
enable_speaker_diarization (bool):
If 'true', enables speaker detection for each recognized
@@ -490,6 +491,7 @@ class SpeakerDiarizationConfig(proto.Message):

class RecognitionMetadata(proto.Message):
r"""Description of audio data to be recognized.
Attributes:
interaction_type (google.cloud.speech_v1p1beta1.types.RecognitionMetadata.InteractionType):
The use case most closely describing the
@@ -914,6 +916,7 @@ class SpeechRecognitionResult(proto.Message):

class SpeechRecognitionAlternative(proto.Message):
r"""Alternative hypotheses (a.k.a. n-best list).
Attributes:
transcript (str):
Transcript text representing the words that
@@ -940,6 +943,7 @@ class SpeechRecognitionAlternative(proto.Message):

class WordInfo(proto.Message):
r"""Word-specific information for recognized words.
Attributes:
start_time (google.protobuf.duration_pb2.Duration):
Time offset relative to the beginning of the audio, and
@@ -40,6 +40,7 @@

class CreatePhraseSetRequest(proto.Message):
r"""Message sent by the client for the ``CreatePhraseSet`` method.
Attributes:
parent (str):
Required. The parent resource where this phrase set will be
@@ -63,6 +64,7 @@ class CreatePhraseSetRequest(proto.Message):

class UpdatePhraseSetRequest(proto.Message):
r"""Message sent by the client for the ``UpdatePhraseSet`` method.
Attributes:
phrase_set (google.cloud.speech_v1p1beta1.types.PhraseSet):
Required. The phrase set to update.
@@ -82,6 +84,7 @@ class UpdatePhraseSetRequest(proto.Message):

class GetPhraseSetRequest(proto.Message):
r"""Message sent by the client for the ``GetPhraseSet`` method.
Attributes:
name (str):
Required. The name of the phrase set to retrieve. Format:
@@ -93,6 +96,7 @@ class GetPhraseSetRequest(proto.Message):

class ListPhraseSetRequest(proto.Message):
r"""Message sent by the client for the ``ListPhraseSet`` method.
Attributes:
parent (str):
Required. The parent, which owns this
@@ -120,6 +124,7 @@ class ListPhraseSetRequest(proto.Message):

class ListPhraseSetResponse(proto.Message):
r"""Message returned to the client by the ``ListPhraseSet`` method.
Attributes:
phrase_sets (Sequence[google.cloud.speech_v1p1beta1.types.PhraseSet]):
The phrase set.
@@ -141,6 +146,7 @@ def raw_page(self):

class DeletePhraseSetRequest(proto.Message):
r"""Message sent by the client for the ``DeletePhraseSet`` method.
Attributes:
name (str):
Required. The name of the phrase set to delete. Format:
@@ -152,6 +158,7 @@ class DeletePhraseSetRequest(proto.Message):

class CreateCustomClassRequest(proto.Message):
r"""Message sent by the client for the ``CreateCustomClass`` method.
Attributes:
parent (str):
Required. The parent resource where this custom class will
@@ -175,6 +182,7 @@ class CreateCustomClassRequest(proto.Message):

class UpdateCustomClassRequest(proto.Message):
r"""Message sent by the client for the ``UpdateCustomClass`` method.
Attributes:
custom_class (google.cloud.speech_v1p1beta1.types.CustomClass):
Required. The custom class to update.
@@ -194,6 +202,7 @@ class UpdateCustomClassRequest(proto.Message):

class GetCustomClassRequest(proto.Message):
r"""Message sent by the client for the ``GetCustomClass`` method.
Attributes:
name (str):
Required. The name of the custom class to retrieve. Format:
@@ -205,6 +214,7 @@ class GetCustomClassRequest(proto.Message):

class ListCustomClassesRequest(proto.Message):
r"""Message sent by the client for the ``ListCustomClasses`` method.
Attributes:
parent (str):
Required. The parent, which owns this collection of custom
@@ -232,6 +242,7 @@ class ListCustomClassesRequest(proto.Message):

class ListCustomClassesResponse(proto.Message):
r"""Message returned to the client by the ``ListCustomClasses`` method.
Attributes:
custom_classes (Sequence[google.cloud.speech_v1p1beta1.types.CustomClass]):
The custom classes.
@@ -253,6 +264,7 @@ def raw_page(self):

class DeleteCustomClassRequest(proto.Message):
r"""Message sent by the client for the ``DeleteCustomClass`` method.
Attributes:
name (str):
Required. The name of the custom class to delete. Format:

0 comments on commit a5e2005

Please sign in to comment.