Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
feat: add context manager support in client (#187)
Browse files Browse the repository at this point in the history
- [ ] 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 8, 2021
1 parent 470d389 commit 70d4776
Show file tree
Hide file tree
Showing 216 changed files with 2,696 additions and 126 deletions.
6 changes: 6 additions & 0 deletions google/cloud/dialogflowcx_v3/services/agents/async_client.py
Expand Up @@ -881,6 +881,12 @@ async def get_agent_validation_result(
# 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(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/dialogflowcx_v3/services/agents/client.py
Expand Up @@ -436,10 +436,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 list_agents(
Expand Down Expand Up @@ -1151,6 +1148,19 @@ def get_agent_validation_result(
# 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(
Expand Down
Expand Up @@ -192,6 +192,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."""
Expand Down
Expand Up @@ -515,5 +515,8 @@ def get_agent_validation_result(
)
return self._stubs["get_agent_validation_result"]

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


__all__ = ("AgentsGrpcTransport",)
Expand Up @@ -524,5 +524,8 @@ def get_agent_validation_result(
)
return self._stubs["get_agent_validation_result"]

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


__all__ = ("AgentsGrpcAsyncIOTransport",)
Expand Up @@ -330,6 +330,12 @@ async def get_deployment(
# 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(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/dialogflowcx_v3/services/deployments/client.py
Expand Up @@ -413,10 +413,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 list_deployments(
Expand Down Expand Up @@ -581,6 +578,19 @@ def get_deployment(
# 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(
Expand Down
Expand Up @@ -165,6 +165,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 list_deployments(
self,
Expand Down
Expand Up @@ -282,5 +282,8 @@ def get_deployment(
)
return self._stubs["get_deployment"]

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


__all__ = ("DeploymentsGrpcTransport",)
Expand Up @@ -286,5 +286,8 @@ def get_deployment(
)
return self._stubs["get_deployment"]

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


__all__ = ("DeploymentsGrpcAsyncIOTransport",)
Expand Up @@ -646,6 +646,12 @@ async def delete_entity_type(
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(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/dialogflowcx_v3/services/entity_types/client.py
Expand Up @@ -348,10 +348,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 list_entity_types(
Expand Down Expand Up @@ -839,6 +836,19 @@ def delete_entity_type(
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(
Expand Down
Expand Up @@ -176,6 +176,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 list_entity_types(
self,
Expand Down
Expand Up @@ -377,5 +377,8 @@ def delete_entity_type(
)
return self._stubs["delete_entity_type"]

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


__all__ = ("EntityTypesGrpcTransport",)
Expand Up @@ -385,5 +385,8 @@ def delete_entity_type(
)
return self._stubs["delete_entity_type"]

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


__all__ = ("EntityTypesGrpcAsyncIOTransport",)
Expand Up @@ -952,6 +952,12 @@ async def deploy_flow(
# 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(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/dialogflowcx_v3/services/environments/client.py
Expand Up @@ -434,10 +434,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 list_environments(
Expand Down Expand Up @@ -1219,6 +1216,19 @@ def deploy_flow(
# 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(
Expand Down
Expand Up @@ -194,6 +194,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."""
Expand Down
Expand Up @@ -541,5 +541,8 @@ def deploy_flow(
)
return self._stubs["deploy_flow"]

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


__all__ = ("EnvironmentsGrpcTransport",)
Expand Up @@ -551,5 +551,8 @@ def deploy_flow(
)
return self._stubs["deploy_flow"]

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


__all__ = ("EnvironmentsGrpcAsyncIOTransport",)
Expand Up @@ -705,6 +705,12 @@ async def stop_experiment(
# 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(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/dialogflowcx_v3/services/experiments/client.py
Expand Up @@ -372,10 +372,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 list_experiments(
Expand Down Expand Up @@ -918,6 +915,19 @@ def stop_experiment(
# 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(
Expand Down
Expand Up @@ -182,6 +182,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 list_experiments(
self,
Expand Down
Expand Up @@ -427,5 +427,8 @@ def stop_experiment(
)
return self._stubs["stop_experiment"]

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


__all__ = ("ExperimentsGrpcTransport",)
Expand Up @@ -433,5 +433,8 @@ def stop_experiment(
)
return self._stubs["stop_experiment"]

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


__all__ = ("ExperimentsGrpcAsyncIOTransport",)

0 comments on commit 70d4776

Please sign in to comment.