Skip to content
Permalink
Browse files
feat: add context manager support in client (#224)
- [ ] 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
  • Loading branch information
gcf-owl-bot[bot] committed Oct 8, 2021
1 parent 63a8d7c commit 8b6565236ec9c8f598efb55bd85937789c70fe3f
Showing with 348 additions and 16 deletions.
  1. +6 −0 google/cloud/documentai_v1/services/document_processor_service/async_client.py
  2. +14 −4 google/cloud/documentai_v1/services/document_processor_service/client.py
  3. +9 −0 google/cloud/documentai_v1/services/document_processor_service/transports/base.py
  4. +3 −0 google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py
  5. +3 −0 google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py
  6. +15 −0 google/cloud/documentai_v1/types/document.py
  7. +4 −0 google/cloud/documentai_v1/types/document_io.py
  8. +9 −1 google/cloud/documentai_v1/types/document_processor_service.py
  9. +1 −0 google/cloud/documentai_v1/types/geometry.py
  10. +1 −0 google/cloud/documentai_v1/types/operation_metadata.py
  11. +6 −0 google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py
  12. +14 −4 google/cloud/documentai_v1beta2/services/document_understanding_service/client.py
  13. +9 −0 google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py
  14. +3 −0 google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py
  15. +3 −0 google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py
  16. +10 −0 google/cloud/documentai_v1beta2/types/document.py
  17. +10 −0 google/cloud/documentai_v1beta2/types/document_understanding.py
  18. +1 −0 google/cloud/documentai_v1beta2/types/geometry.py
  19. +6 −0 google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py
  20. +14 −4 google/cloud/documentai_v1beta3/services/document_processor_service/client.py
  21. +9 −0 google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py
  22. +3 −0 google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py
  23. +3 −0 google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py
  24. +15 −0 google/cloud/documentai_v1beta3/types/document.py
  25. +4 −0 google/cloud/documentai_v1beta3/types/document_io.py
  26. +21 −3 google/cloud/documentai_v1beta3/types/document_processor_service.py
  27. +1 −0 google/cloud/documentai_v1beta3/types/geometry.py
  28. +1 −0 google/cloud/documentai_v1beta3/types/operation_metadata.py
  29. +50 −0 tests/unit/gapic/documentai_v1/test_document_processor_service.py
  30. +50 −0 tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py
  31. +50 −0 tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py
@@ -451,6 +451,12 @@ async def review_document(
# 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(
@@ -369,10 +369,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 process_document(
@@ -615,6 +612,19 @@ def review_document(
# 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(
@@ -203,6 +203,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."""
@@ -333,5 +333,8 @@ def review_document(
)
return self._stubs["review_document"]

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


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

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


__all__ = ("DocumentProcessorServiceGrpcAsyncIOTransport",)
@@ -135,6 +135,7 @@ class Style(proto.Message):

class FontSize(proto.Message):
r"""Font size with unit.
Attributes:
size (float):
Font size for the text.
@@ -162,6 +163,7 @@ class FontSize(proto.Message):

class Page(proto.Message):
r"""A page in a [Document][google.cloud.documentai.v1.Document].
Attributes:
page_number (int):
1-based index for current
@@ -218,6 +220,7 @@ class Page(proto.Message):

class Dimension(proto.Message):
r"""Dimension for the page.
Attributes:
width (float):
Page width.
@@ -233,6 +236,7 @@ class Dimension(proto.Message):

class Image(proto.Message):
r"""Rendered image contents for this page.
Attributes:
content (bytes):
Raw byte content of the image.
@@ -275,6 +279,7 @@ class Matrix(proto.Message):

class Layout(proto.Message):
r"""Visual element describing a layout unit on a page.
Attributes:
text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor):
Text anchor indexing into the
@@ -391,6 +396,7 @@ class Line(proto.Message):

class Token(proto.Message):
r"""A detected token.
Attributes:
layout (google.cloud.documentai_v1.types.Document.Page.Layout):
[Layout][google.cloud.documentai.v1.Document.Page.Layout]
@@ -465,6 +471,7 @@ class VisualElement(proto.Message):

class Table(proto.Message):
r"""A table representation similar to HTML table structure.
Attributes:
layout (google.cloud.documentai_v1.types.Document.Page.Layout):
[Layout][google.cloud.documentai.v1.Document.Page.Layout]
@@ -480,6 +487,7 @@ class Table(proto.Message):

class TableRow(proto.Message):
r"""A row of table cells.
Attributes:
cells (Sequence[google.cloud.documentai_v1.types.Document.Page.Table.TableCell]):
Cells that make up this row.
@@ -491,6 +499,7 @@ class TableRow(proto.Message):

class TableCell(proto.Message):
r"""A cell representation inside the table.
Attributes:
layout (google.cloud.documentai_v1.types.Document.Page.Layout):
[Layout][google.cloud.documentai.v1.Document.Page.Layout]
@@ -529,6 +538,7 @@ class TableCell(proto.Message):

class FormField(proto.Message):
r"""A form field detected on the page.
Attributes:
field_name (google.cloud.documentai_v1.types.Document.Page.Layout):
[Layout][google.cloud.documentai.v1.Document.Page.Layout]
@@ -577,6 +587,7 @@ class FormField(proto.Message):

class DetectedLanguage(proto.Message):
r"""Detected language for a structural component.
Attributes:
language_code (str):
The BCP-47 language code, such as "en-US" or "sr-Latn". For
@@ -671,6 +682,7 @@ class Entity(proto.Message):

class NormalizedValue(proto.Message):
r"""Parsed and normalized entity value.
Attributes:
money_value (google.type.money_pb2.Money):
Money value. See also:
@@ -934,6 +946,7 @@ class Parent(proto.Message):

class Revision(proto.Message):
r"""Contains past or forward revisions of this document.
Attributes:
agent (str):
If the change was made by a person specify
@@ -956,6 +969,7 @@ class Revision(proto.Message):

class HumanReview(proto.Message):
r"""Human Review information of the document.
Attributes:
state (str):
Human review state. e.g. ``requested``, ``succeeded``,
@@ -982,6 +996,7 @@ class HumanReview(proto.Message):

class TextChange(proto.Message):
r"""This message is used for text changes aka. OCR corrections.
Attributes:
text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor):
Provenance of the correction. Text anchor indexing into the
@@ -31,6 +31,7 @@

class RawDocument(proto.Message):
r"""Payload message of raw document content (bytes).
Attributes:
content (bytes):
Inline document content.
@@ -45,6 +46,7 @@ class RawDocument(proto.Message):

class GcsDocument(proto.Message):
r"""Specifies a document stored on Cloud Storage.
Attributes:
gcs_uri (str):
The Cloud Storage object uri.
@@ -58,6 +60,7 @@ class GcsDocument(proto.Message):

class GcsDocuments(proto.Message):
r"""Specifies a set of documents on Cloud Storage.
Attributes:
documents (Sequence[google.cloud.documentai_v1.types.GcsDocument]):
The list of documents.
@@ -111,6 +114,7 @@ class DocumentOutputConfig(proto.Message):

class GcsOutputConfig(proto.Message):
r"""The configuration used when outputting documents.
Attributes:
gcs_uri (str):
The Cloud Storage uri (a directory) of the
@@ -40,6 +40,7 @@

class ProcessRequest(proto.Message):
r"""Request message for the process document method.
Attributes:
inline_document (google.cloud.documentai_v1.types.Document):
An inline document proto.
@@ -64,6 +65,7 @@ class ProcessRequest(proto.Message):

class HumanReviewStatus(proto.Message):
r"""The status of human review on a processed document.
Attributes:
state (google.cloud.documentai_v1.types.HumanReviewStatus.State):
The state of human review on the processing
@@ -94,6 +96,7 @@ class State(proto.Enum):

class ProcessResponse(proto.Message):
r"""Response message for the process document method.
Attributes:
document (google.cloud.documentai_v1.types.Document):
The document payload, will populate fields
@@ -111,6 +114,7 @@ class ProcessResponse(proto.Message):

class BatchProcessRequest(proto.Message):
r"""Request message for batch process document method.
Attributes:
name (str):
Required. The processor resource name.
@@ -134,11 +138,13 @@ class BatchProcessRequest(proto.Message):


class BatchProcessResponse(proto.Message):
r"""Response message for batch process document method. """
r"""Response message for batch process document method.
"""


class BatchProcessMetadata(proto.Message):
r"""The long running operation metadata for batch process method.
Attributes:
state (google.cloud.documentai_v1.types.BatchProcessMetadata.State):
The state of the current batch processing.
@@ -205,6 +211,7 @@ class IndividualProcessStatus(proto.Message):

class ReviewDocumentRequest(proto.Message):
r"""Request message for review document method.
Attributes:
inline_document (google.cloud.documentai_v1.types.Document):
An inline document proto.
@@ -234,6 +241,7 @@ class Priority(proto.Enum):

class ReviewDocumentResponse(proto.Message):
r"""Response message for review document method.
Attributes:
gcs_destination (str):
The Cloud Storage uri for the human reviewed
@@ -58,6 +58,7 @@ class NormalizedVertex(proto.Message):

class BoundingPoly(proto.Message):
r"""A bounding polygon for the detected image annotation.
Attributes:
vertices (Sequence[google.cloud.documentai_v1.types.Vertex]):
The bounding polygon vertices.
@@ -25,6 +25,7 @@

class CommonOperationMetadata(proto.Message):
r"""The common metadata for long running operations.
Attributes:
state (google.cloud.documentai_v1.types.CommonOperationMetadata.State):
The state of the operation.
@@ -328,6 +328,12 @@ async def process_document(
# 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(
@@ -340,10 +340,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 batch_process_documents(
@@ -485,6 +482,19 @@ def process_document(
# 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(
@@ -189,6 +189,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."""
@@ -300,5 +300,8 @@ def process_document(
)
return self._stubs["process_document"]

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


__all__ = ("DocumentUnderstandingServiceGrpcTransport",)
@@ -310,5 +310,8 @@ def process_document(
)
return self._stubs["process_document"]

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


__all__ = ("DocumentUnderstandingServiceGrpcAsyncIOTransport",)

0 comments on commit 8b65652

Please sign in to comment.