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

feat: add context manager support in client #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -406,6 +406,12 @@ async def repair_application(
# 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/appengine_admin_v1/services/applications/client.py
Expand Up @@ -330,10 +330,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 get_application(
Expand Down Expand Up @@ -587,6 +584,19 @@ def repair_application(
# 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 @@ -175,6 +175,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 @@ -373,5 +373,8 @@ def repair_application(
)
return self._stubs["repair_application"]

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


__all__ = ("ApplicationsGrpcTransport",)
Expand Up @@ -386,5 +386,8 @@ def repair_application(
)
return self._stubs["repair_application"]

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


__all__ = ("ApplicationsGrpcAsyncIOTransport",)
Expand Up @@ -429,6 +429,12 @@ async def delete_authorized_certificate(
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
Expand Up @@ -335,10 +335,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_authorized_certificates(
Expand Down Expand Up @@ -618,6 +615,19 @@ def delete_authorized_certificate(
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 @@ -187,6 +187,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_authorized_certificates(
self,
Expand Down
Expand Up @@ -382,5 +382,8 @@ def delete_authorized_certificate(
)
return self._stubs["delete_authorized_certificate"]

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


__all__ = ("AuthorizedCertificatesGrpcTransport",)
Expand Up @@ -388,5 +388,8 @@ def delete_authorized_certificate(
)
return self._stubs["delete_authorized_certificate"]

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


__all__ = ("AuthorizedCertificatesGrpcAsyncIOTransport",)
Expand Up @@ -222,6 +222,12 @@ async def list_authorized_domains(
# 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
Expand Up @@ -334,10 +334,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_authorized_domains(
Expand Down Expand Up @@ -400,6 +397,19 @@ def list_authorized_domains(
# 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_authorized_domains(
self,
Expand Down
Expand Up @@ -257,5 +257,8 @@ def list_authorized_domains(
)
return self._stubs["list_authorized_domains"]

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


__all__ = ("AuthorizedDomainsGrpcTransport",)
Expand Up @@ -260,5 +260,8 @@ def list_authorized_domains(
)
return self._stubs["list_authorized_domains"]

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


__all__ = ("AuthorizedDomainsGrpcAsyncIOTransport",)
Expand Up @@ -469,6 +469,12 @@ async def delete_domain_mapping(
# 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/appengine_admin_v1/services/domain_mappings/client.py
Expand Up @@ -333,10 +333,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_domain_mappings(
Expand Down Expand Up @@ -649,6 +646,19 @@ def delete_domain_mapping(
# 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 @@ -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 operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -384,5 +384,8 @@ def delete_domain_mapping(
)
return self._stubs["delete_domain_mapping"]

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


__all__ = ("DomainMappingsGrpcTransport",)
Expand Up @@ -398,5 +398,8 @@ def delete_domain_mapping(
)
return self._stubs["delete_domain_mapping"]

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


__all__ = ("DomainMappingsGrpcAsyncIOTransport",)
Expand Up @@ -468,6 +468,12 @@ async def delete_ingress_rule(
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/appengine_admin_v1/services/firewall/client.py
Expand Up @@ -338,10 +338,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_ingress_rules(
Expand Down Expand Up @@ -657,6 +654,19 @@ def delete_ingress_rule(
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 @@ -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_ingress_rules(
self,
Expand Down
Expand Up @@ -404,5 +404,8 @@ def delete_ingress_rule(
)
return self._stubs["delete_ingress_rule"]

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


__all__ = ("FirewallGrpcTransport",)
Expand Up @@ -412,5 +412,8 @@ def delete_ingress_rule(
)
return self._stubs["delete_ingress_rule"]

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


__all__ = ("FirewallGrpcAsyncIOTransport",)