Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit f1559b6

Browse files
feat: add context manager support in client (#146)
- [ ] 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: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 5a38fc1 commit f1559b6

8 files changed

Lines changed: 187 additions & 4 deletions

File tree

google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6240,6 +6240,12 @@ async def update_data_retention_settings(
62406240
# Done; return the response.
62416241
return response
62426242

6243+
async def __aenter__(self):
6244+
return self
6245+
6246+
async def __aexit__(self, exc_type, exc, tb):
6247+
await self.transport.close()
6248+
62436249

62446250
try:
62456251
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/analytics/admin_v1alpha/services/analytics_admin_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,7 @@ def __init__(
621621
client_cert_source_for_mtls=client_cert_source_func,
622622
quota_project_id=client_options.quota_project_id,
623623
client_info=client_info,
624-
always_use_jwt_access=(
625-
Transport == type(self).get_transport_class("grpc")
626-
or Transport == type(self).get_transport_class("grpc_asyncio")
627-
),
624+
always_use_jwt_access=True,
628625
)
629626

630627
def get_account(
@@ -6745,6 +6742,19 @@ def update_data_retention_settings(
67456742
# Done; return the response.
67466743
return response
67476744

6745+
def __enter__(self):
6746+
return self
6747+
6748+
def __exit__(self, type, value, traceback):
6749+
"""Releases underlying transport's resources.
6750+
6751+
.. warning::
6752+
ONLY use as a context manager if the transport is NOT shared
6753+
with other clients! Exiting the with block will CLOSE the transport
6754+
and may cause errors in other clients!
6755+
"""
6756+
self.transport.close()
6757+
67486758

67496759
try:
67506760
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ def _prep_wrapped_messages(self, client_info):
521521
),
522522
}
523523

524+
def close(self):
525+
"""Closes resources associated with the transport.
526+
527+
.. warning::
528+
Only call this method if the transport is NOT shared
529+
with other clients - this may cause errors in other clients!
530+
"""
531+
raise NotImplementedError()
532+
524533
@property
525534
def get_account(
526535
self,

google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,5 +2615,8 @@ def update_data_retention_settings(
26152615
)
26162616
return self._stubs["update_data_retention_settings"]
26172617

2618+
def close(self):
2619+
self.grpc_channel.close()
2620+
26182621

26192622
__all__ = ("AnalyticsAdminServiceGrpcTransport",)

google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,5 +2673,8 @@ def update_data_retention_settings(
26732673
)
26742674
return self._stubs["update_data_retention_settings"]
26752675

2676+
def close(self):
2677+
return self.grpc_channel.close()
2678+
26762679

26772680
__all__ = ("AnalyticsAdminServiceGrpcAsyncIOTransport",)

0 commit comments

Comments
 (0)