From 1c3619d6d117e85b15aba3c96b0dbdd52a93768b Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 29 Jun 2021 22:20:05 +0000 Subject: [PATCH 1/6] chore: use gapic-generator-python 0.50.3 fix: disable always_use_jwt_access Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: https://github.com/googleapis/googleapis/commit/513440fda515f3c799c22a30e3906dcda325004e Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0 --- owl-bot-staging/v1/.coveragerc | 17 + owl-bot-staging/v1/MANIFEST.in | 2 + owl-bot-staging/v1/README.rst | 49 + owl-bot-staging/v1/docs/conf.py | 376 ++ .../document_processor_service.rst | 6 + .../v1/docs/documentai_v1/services.rst | 6 + .../v1/docs/documentai_v1/types.rst | 7 + owl-bot-staging/v1/docs/index.rst | 7 + .../v1/google/cloud/documentai/__init__.py | 63 + .../v1/google/cloud/documentai/py.typed | 2 + .../v1/google/cloud/documentai_v1/__init__.py | 64 + .../cloud/documentai_v1/gapic_metadata.json | 53 + .../v1/google/cloud/documentai_v1/py.typed | 2 + .../cloud/documentai_v1/services/__init__.py | 15 + .../document_processor_service/__init__.py | 22 + .../async_client.py | 443 +++ .../document_processor_service/client.py | 618 ++++ .../transports/__init__.py | 33 + .../transports/base.py | 224 ++ .../transports/grpc.py | 329 ++ .../transports/grpc_asyncio.py | 333 ++ .../cloud/documentai_v1/types/__init__.py | 68 + .../cloud/documentai_v1/types/document.py | 1369 +++++++ .../cloud/documentai_v1/types/document_io.py | 158 + .../types/document_processor_service.py | 343 ++ .../cloud/documentai_v1/types/geometry.py | 96 + .../documentai_v1/types/operation_metadata.py | 72 + owl-bot-staging/v1/mypy.ini | 3 + owl-bot-staging/v1/noxfile.py | 132 + .../scripts/fixup_documentai_v1_keywords.py | 178 + owl-bot-staging/v1/setup.py | 53 + owl-bot-staging/v1/tests/__init__.py | 16 + owl-bot-staging/v1/tests/unit/__init__.py | 16 + .../v1/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/documentai_v1/__init__.py | 16 + .../test_document_processor_service.py | 1695 +++++++++ owl-bot-staging/v1beta2/.coveragerc | 17 + owl-bot-staging/v1beta2/MANIFEST.in | 2 + owl-bot-staging/v1beta2/README.rst | 49 + owl-bot-staging/v1beta2/docs/conf.py | 376 ++ .../document_understanding_service.rst | 6 + .../docs/documentai_v1beta2/services.rst | 6 + .../v1beta2/docs/documentai_v1beta2/types.rst | 7 + owl-bot-staging/v1beta2/docs/index.rst | 7 + .../google/cloud/documentai/__init__.py | 63 + .../v1beta2/google/cloud/documentai/py.typed | 2 + .../cloud/documentai_v1beta2/__init__.py | 64 + .../documentai_v1beta2/gapic_metadata.json | 43 + .../google/cloud/documentai_v1beta2/py.typed | 2 + .../documentai_v1beta2/services/__init__.py | 15 + .../__init__.py | 22 + .../async_client.py | 327 ++ .../document_understanding_service/client.py | 492 +++ .../transports/__init__.py | 33 + .../transports/base.py | 204 ++ .../transports/grpc.py | 301 ++ .../transports/grpc_asyncio.py | 305 ++ .../documentai_v1beta2/types/__init__.py | 64 + .../documentai_v1beta2/types/document.py | 993 ++++++ .../types/document_understanding.py | 546 +++ .../documentai_v1beta2/types/geometry.py | 94 + owl-bot-staging/v1beta2/mypy.ini | 3 + owl-bot-staging/v1beta2/noxfile.py | 132 + .../fixup_documentai_v1beta2_keywords.py | 177 + owl-bot-staging/v1beta2/setup.py | 53 + owl-bot-staging/v1beta2/tests/__init__.py | 16 + .../v1beta2/tests/unit/__init__.py | 16 + .../v1beta2/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/documentai_v1beta2/__init__.py | 16 + .../test_document_understanding_service.py | 1342 +++++++ owl-bot-staging/v1beta3/.coveragerc | 17 + owl-bot-staging/v1beta3/MANIFEST.in | 2 + owl-bot-staging/v1beta3/README.rst | 49 + owl-bot-staging/v1beta3/docs/conf.py | 376 ++ .../document_processor_service.rst | 10 + .../docs/documentai_v1beta3/services.rst | 6 + .../v1beta3/docs/documentai_v1beta3/types.rst | 7 + owl-bot-staging/v1beta3/docs/index.rst | 7 + .../google/cloud/documentai/__init__.py | 93 + .../v1beta3/google/cloud/documentai/py.typed | 2 + .../cloud/documentai_v1beta3/__init__.py | 94 + .../documentai_v1beta3/gapic_metadata.json | 113 + .../google/cloud/documentai_v1beta3/py.typed | 2 + .../documentai_v1beta3/services/__init__.py | 15 + .../document_processor_service/__init__.py | 22 + .../async_client.py | 939 +++++ .../document_processor_service/client.py | 1125 ++++++ .../document_processor_service/pagers.py | 141 + .../transports/__init__.py | 33 + .../transports/base.py | 309 ++ .../transports/grpc.py | 490 +++ .../transports/grpc_asyncio.py | 494 +++ .../documentai_v1beta3/types/__init__.py | 102 + .../documentai_v1beta3/types/document.py | 1373 +++++++ .../documentai_v1beta3/types/document_io.py | 158 + .../types/document_processor_service.py | 698 ++++ .../documentai_v1beta3/types/geometry.py | 96 + .../types/operation_metadata.py | 72 + .../documentai_v1beta3/types/processor.py | 104 + .../types/processor_type.py | 85 + owl-bot-staging/v1beta3/mypy.ini | 3 + owl-bot-staging/v1beta3/noxfile.py | 132 + .../fixup_documentai_v1beta3_keywords.py | 184 + owl-bot-staging/v1beta3/setup.py | 53 + owl-bot-staging/v1beta3/tests/__init__.py | 16 + .../v1beta3/tests/unit/__init__.py | 16 + .../v1beta3/tests/unit/gapic/__init__.py | 16 + .../unit/gapic/documentai_v1beta3/__init__.py | 16 + .../test_document_processor_service.py | 3158 +++++++++++++++++ 109 files changed, 23341 insertions(+) create mode 100644 owl-bot-staging/v1/.coveragerc create mode 100644 owl-bot-staging/v1/MANIFEST.in create mode 100644 owl-bot-staging/v1/README.rst create mode 100644 owl-bot-staging/v1/docs/conf.py create mode 100644 owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst create mode 100644 owl-bot-staging/v1/docs/documentai_v1/services.rst create mode 100644 owl-bot-staging/v1/docs/documentai_v1/types.rst create mode 100644 owl-bot-staging/v1/docs/index.rst create mode 100644 owl-bot-staging/v1/google/cloud/documentai/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai/py.typed create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/py.typed create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py create mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py create mode 100644 owl-bot-staging/v1/mypy.ini create mode 100644 owl-bot-staging/v1/noxfile.py create mode 100644 owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py create mode 100644 owl-bot-staging/v1/setup.py create mode 100644 owl-bot-staging/v1/tests/__init__.py create mode 100644 owl-bot-staging/v1/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py create mode 100644 owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py create mode 100644 owl-bot-staging/v1beta2/.coveragerc create mode 100644 owl-bot-staging/v1beta2/MANIFEST.in create mode 100644 owl-bot-staging/v1beta2/README.rst create mode 100644 owl-bot-staging/v1beta2/docs/conf.py create mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst create mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst create mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst create mode 100644 owl-bot-staging/v1beta2/docs/index.rst create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai/py.typed create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py create mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py create mode 100644 owl-bot-staging/v1beta2/mypy.ini create mode 100644 owl-bot-staging/v1beta2/noxfile.py create mode 100644 owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py create mode 100644 owl-bot-staging/v1beta2/setup.py create mode 100644 owl-bot-staging/v1beta2/tests/__init__.py create mode 100644 owl-bot-staging/v1beta2/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py create mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py create mode 100644 owl-bot-staging/v1beta3/.coveragerc create mode 100644 owl-bot-staging/v1beta3/MANIFEST.in create mode 100644 owl-bot-staging/v1beta3/README.rst create mode 100644 owl-bot-staging/v1beta3/docs/conf.py create mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst create mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst create mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst create mode 100644 owl-bot-staging/v1beta3/docs/index.rst create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai/py.typed create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py create mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py create mode 100644 owl-bot-staging/v1beta3/mypy.ini create mode 100644 owl-bot-staging/v1beta3/noxfile.py create mode 100644 owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py create mode 100644 owl-bot-staging/v1beta3/setup.py create mode 100644 owl-bot-staging/v1beta3/tests/__init__.py create mode 100644 owl-bot-staging/v1beta3/tests/unit/__init__.py create mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py create mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py diff --git a/owl-bot-staging/v1/.coveragerc b/owl-bot-staging/v1/.coveragerc new file mode 100644 index 00000000..ef619357 --- /dev/null +++ b/owl-bot-staging/v1/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/documentai/__init__.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ + # Ignore pkg_resources exceptions. + # This is added at the module level as a safeguard for if someone + # generates the code and tries to run it without pip installing. This + # makes it virtually impossible to test properly. + except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1/MANIFEST.in b/owl-bot-staging/v1/MANIFEST.in new file mode 100644 index 00000000..b804f157 --- /dev/null +++ b/owl-bot-staging/v1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/documentai *.py +recursive-include google/cloud/documentai_v1 *.py diff --git a/owl-bot-staging/v1/README.rst b/owl-bot-staging/v1/README.rst new file mode 100644 index 00000000..484a3c1c --- /dev/null +++ b/owl-bot-staging/v1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Documentai API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Documentai API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1/docs/conf.py b/owl-bot-staging/v1/docs/conf.py new file mode 100644 index 00000000..0788579e --- /dev/null +++ b/owl-bot-staging/v1/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-documentai documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "1.6.3" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = u"google-cloud-documentai" +copyright = u"2020, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-documentai-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + master_doc, + "google-cloud-documentai.tex", + u"google-cloud-documentai Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + master_doc, + "google-cloud-documentai", + u"Google Cloud Documentai Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "google-cloud-documentai", + u"google-cloud-documentai Documentation", + author, + "google-cloud-documentai", + "GAPIC library for Google Cloud Documentai API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst b/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst new file mode 100644 index 00000000..3918355b --- /dev/null +++ b/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst @@ -0,0 +1,6 @@ +DocumentProcessorService +------------------------------------------ + +.. automodule:: google.cloud.documentai_v1.services.document_processor_service + :members: + :inherited-members: diff --git a/owl-bot-staging/v1/docs/documentai_v1/services.rst b/owl-bot-staging/v1/docs/documentai_v1/services.rst new file mode 100644 index 00000000..551bb666 --- /dev/null +++ b/owl-bot-staging/v1/docs/documentai_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Documentai v1 API +=========================================== +.. toctree:: + :maxdepth: 2 + + document_processor_service diff --git a/owl-bot-staging/v1/docs/documentai_v1/types.rst b/owl-bot-staging/v1/docs/documentai_v1/types.rst new file mode 100644 index 00000000..68ac7119 --- /dev/null +++ b/owl-bot-staging/v1/docs/documentai_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Documentai v1 API +======================================== + +.. automodule:: google.cloud.documentai_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1/docs/index.rst b/owl-bot-staging/v1/docs/index.rst new file mode 100644 index 00000000..c907db5b --- /dev/null +++ b/owl-bot-staging/v1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + documentai_v1/services + documentai_v1/types diff --git a/owl-bot-staging/v1/google/cloud/documentai/__init__.py b/owl-bot-staging/v1/google/cloud/documentai/__init__.py new file mode 100644 index 00000000..68d50b9c --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai/__init__.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.cloud.documentai_v1.services.document_processor_service.client import DocumentProcessorServiceClient +from google.cloud.documentai_v1.services.document_processor_service.async_client import DocumentProcessorServiceAsyncClient + +from google.cloud.documentai_v1.types.document import Document +from google.cloud.documentai_v1.types.document_io import BatchDocumentsInputConfig +from google.cloud.documentai_v1.types.document_io import DocumentOutputConfig +from google.cloud.documentai_v1.types.document_io import GcsDocument +from google.cloud.documentai_v1.types.document_io import GcsDocuments +from google.cloud.documentai_v1.types.document_io import GcsPrefix +from google.cloud.documentai_v1.types.document_io import RawDocument +from google.cloud.documentai_v1.types.document_processor_service import BatchProcessMetadata +from google.cloud.documentai_v1.types.document_processor_service import BatchProcessRequest +from google.cloud.documentai_v1.types.document_processor_service import BatchProcessResponse +from google.cloud.documentai_v1.types.document_processor_service import HumanReviewStatus +from google.cloud.documentai_v1.types.document_processor_service import ProcessRequest +from google.cloud.documentai_v1.types.document_processor_service import ProcessResponse +from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentOperationMetadata +from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentRequest +from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentResponse +from google.cloud.documentai_v1.types.geometry import BoundingPoly +from google.cloud.documentai_v1.types.geometry import NormalizedVertex +from google.cloud.documentai_v1.types.geometry import Vertex +from google.cloud.documentai_v1.types.operation_metadata import CommonOperationMetadata + +__all__ = ('DocumentProcessorServiceClient', + 'DocumentProcessorServiceAsyncClient', + 'Document', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'RawDocument', + 'BatchProcessMetadata', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'HumanReviewStatus', + 'ProcessRequest', + 'ProcessResponse', + 'ReviewDocumentOperationMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', + 'CommonOperationMetadata', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai/py.typed b/owl-bot-staging/v1/google/cloud/documentai/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py new file mode 100644 index 00000000..941c1e97 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from .services.document_processor_service import DocumentProcessorServiceClient +from .services.document_processor_service import DocumentProcessorServiceAsyncClient + +from .types.document import Document +from .types.document_io import BatchDocumentsInputConfig +from .types.document_io import DocumentOutputConfig +from .types.document_io import GcsDocument +from .types.document_io import GcsDocuments +from .types.document_io import GcsPrefix +from .types.document_io import RawDocument +from .types.document_processor_service import BatchProcessMetadata +from .types.document_processor_service import BatchProcessRequest +from .types.document_processor_service import BatchProcessResponse +from .types.document_processor_service import HumanReviewStatus +from .types.document_processor_service import ProcessRequest +from .types.document_processor_service import ProcessResponse +from .types.document_processor_service import ReviewDocumentOperationMetadata +from .types.document_processor_service import ReviewDocumentRequest +from .types.document_processor_service import ReviewDocumentResponse +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Vertex +from .types.operation_metadata import CommonOperationMetadata + +__all__ = ( + 'DocumentProcessorServiceAsyncClient', +'BatchDocumentsInputConfig', +'BatchProcessMetadata', +'BatchProcessRequest', +'BatchProcessResponse', +'BoundingPoly', +'CommonOperationMetadata', +'Document', +'DocumentOutputConfig', +'DocumentProcessorServiceClient', +'GcsDocument', +'GcsDocuments', +'GcsPrefix', +'HumanReviewStatus', +'NormalizedVertex', +'ProcessRequest', +'ProcessResponse', +'RawDocument', +'ReviewDocumentOperationMetadata', +'ReviewDocumentRequest', +'ReviewDocumentResponse', +'Vertex', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json b/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json new file mode 100644 index 00000000..0013c0aa --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json @@ -0,0 +1,53 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.documentai_v1", + "protoPackage": "google.cloud.documentai.v1", + "schema": "1.0", + "services": { + "DocumentProcessorService": { + "clients": { + "grpc": { + "libraryClient": "DocumentProcessorServiceClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + }, + "ReviewDocument": { + "methods": [ + "review_document" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DocumentProcessorServiceAsyncClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + }, + "ReviewDocument": { + "methods": [ + "review_document" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed b/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py new file mode 100644 index 00000000..7217ec7c --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import DocumentProcessorServiceClient +from .async_client import DocumentProcessorServiceAsyncClient + +__all__ = ( + 'DocumentProcessorServiceClient', + 'DocumentProcessorServiceAsyncClient', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py new file mode 100644 index 00000000..a7d3b9e5 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -0,0 +1,443 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +import pkg_resources + +import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1.types import document +from google.cloud.documentai_v1.types import document_processor_service +from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport +from .client import DocumentProcessorServiceClient + + +class DocumentProcessorServiceAsyncClient: + """Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + """ + + _client: DocumentProcessorServiceClient + + DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + + human_review_config_path = staticmethod(DocumentProcessorServiceClient.human_review_config_path) + parse_human_review_config_path = staticmethod(DocumentProcessorServiceClient.parse_human_review_config_path) + processor_path = staticmethod(DocumentProcessorServiceClient.processor_path) + parse_processor_path = staticmethod(DocumentProcessorServiceClient.parse_processor_path) + common_billing_account_path = staticmethod(DocumentProcessorServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(DocumentProcessorServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(DocumentProcessorServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(DocumentProcessorServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(DocumentProcessorServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(DocumentProcessorServiceClient.parse_common_organization_path) + common_project_path = staticmethod(DocumentProcessorServiceClient.common_project_path) + parse_common_project_path = staticmethod(DocumentProcessorServiceClient.parse_common_project_path) + common_location_path = staticmethod(DocumentProcessorServiceClient.common_location_path) + parse_common_location_path = staticmethod(DocumentProcessorServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceAsyncClient: The constructed client. + """ + return DocumentProcessorServiceClient.from_service_account_info.__func__(DocumentProcessorServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceAsyncClient: The constructed client. + """ + return DocumentProcessorServiceClient.from_service_account_file.__func__(DocumentProcessorServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentProcessorServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentProcessorServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, DocumentProcessorServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document processor service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.DocumentProcessorServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = DocumentProcessorServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def process_document(self, + request: document_processor_service.ProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.ProcessResponse: + r"""Processes a single document. + + Args: + request (:class:`google.cloud.documentai_v1.types.ProcessRequest`): + The request object. Request message for the process + document method. + name (:class:`str`): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1.types.ProcessResponse: + Response message for the process + document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.ProcessRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_process_documents(self, + request: document_processor_service.BatchProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (:class:`google.cloud.documentai_v1.types.BatchProcessRequest`): + The request object. Request message for batch process + document method. + name (:class:`str`): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1.types.BatchProcessResponse` + Response message for batch process document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.BatchProcessRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.BatchProcessResponse, + metadata_type=document_processor_service.BatchProcessMetadata, + ) + + # Done; return the response. + return response + + async def review_document(self, + request: document_processor_service.ReviewDocumentRequest = None, + *, + human_review_config: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Send a document for Human Review. The input document + should be processed by the specified processor. + + Args: + request (:class:`google.cloud.documentai_v1.types.ReviewDocumentRequest`): + The request object. Request message for review document + method. + human_review_config (:class:`str`): + Required. The resource name of the + HumanReviewConfig that the document will + be reviewed with. + + This corresponds to the ``human_review_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1.types.ReviewDocumentResponse` + Response message for review document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([human_review_config]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.ReviewDocumentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if human_review_config is not None: + request.human_review_config = human_review_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.review_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("human_review_config", request.human_review_config), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.ReviewDocumentResponse, + metadata_type=document_processor_service.ReviewDocumentOperationMetadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentProcessorServiceAsyncClient", +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py new file mode 100644 index 00000000..6e4814ab --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -0,0 +1,618 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from distutils import util +import os +import re +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1.types import document +from google.cloud.documentai_v1.types import document_processor_service +from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import DocumentProcessorServiceGrpcTransport +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + + +class DocumentProcessorServiceClientMeta(type): + """Metaclass for the DocumentProcessorService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] + _transport_registry["grpc"] = DocumentProcessorServiceGrpcTransport + _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[DocumentProcessorServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMeta): + """Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "documentai.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentProcessorServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentProcessorServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def human_review_config_path(project: str,location: str,processor: str,) -> str: + """Returns a fully-qualified human_review_config string.""" + return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) + + @staticmethod + def parse_human_review_config_path(path: str) -> Dict[str,str]: + """Parses a human_review_config path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)/humanReviewConfig$", path) + return m.groupdict() if m else {} + + @staticmethod + def processor_path(project: str,location: str,processor: str,) -> str: + """Returns a fully-qualified processor string.""" + return "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) + + @staticmethod + def parse_processor_path(path: str) -> Dict[str,str]: + """Parses a processor path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, DocumentProcessorServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document processor service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, DocumentProcessorServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) + + client_cert_source_func = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + is_mtls = True + client_cert_source_func = client_options.client_cert_source + else: + is_mtls = mtls.has_default_client_cert_source() + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_mtls_env == "never": + api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, DocumentProcessorServiceTransport): + # transport is a DocumentProcessorServiceTransport instance. + if credentials or client_options.credentials_file: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + ) + + def process_document(self, + request: document_processor_service.ProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.ProcessResponse: + r"""Processes a single document. + + Args: + request (google.cloud.documentai_v1.types.ProcessRequest): + The request object. Request message for the process + document method. + name (str): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1.types.ProcessResponse: + Response message for the process + document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.ProcessRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.ProcessRequest): + request = document_processor_service.ProcessRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.process_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_process_documents(self, + request: document_processor_service.BatchProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (google.cloud.documentai_v1.types.BatchProcessRequest): + The request object. Request message for batch process + document method. + name (str): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1.types.BatchProcessResponse` + Response message for batch process document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.BatchProcessRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.BatchProcessRequest): + request = document_processor_service.BatchProcessRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.BatchProcessResponse, + metadata_type=document_processor_service.BatchProcessMetadata, + ) + + # Done; return the response. + return response + + def review_document(self, + request: document_processor_service.ReviewDocumentRequest = None, + *, + human_review_config: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Send a document for Human Review. The input document + should be processed by the specified processor. + + Args: + request (google.cloud.documentai_v1.types.ReviewDocumentRequest): + The request object. Request message for review document + method. + human_review_config (str): + Required. The resource name of the + HumanReviewConfig that the document will + be reviewed with. + + This corresponds to the ``human_review_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1.types.ReviewDocumentResponse` + Response message for review document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([human_review_config]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.ReviewDocumentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.ReviewDocumentRequest): + request = document_processor_service.ReviewDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if human_review_config is not None: + request.human_review_config = human_review_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.review_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("human_review_config", request.human_review_config), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.ReviewDocumentResponse, + metadata_type=document_processor_service.ReviewDocumentOperationMetadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentProcessorServiceClient", +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py new file mode 100644 index 00000000..38f9c440 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import DocumentProcessorServiceTransport +from .grpc import DocumentProcessorServiceGrpcTransport +from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] +_transport_registry['grpc'] = DocumentProcessorServiceGrpcTransport +_transport_registry['grpc_asyncio'] = DocumentProcessorServiceGrpcAsyncIOTransport + +__all__ = ( + 'DocumentProcessorServiceTransport', + 'DocumentProcessorServiceGrpcTransport', + 'DocumentProcessorServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py new file mode 100644 index 00000000..64112947 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -0,0 +1,224 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version +import pkg_resources + +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.documentai_v1.types import document_processor_service +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-documentai', + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + + +class DocumentProcessorServiceTransport(abc.ABC): + """Abstract transport class for DocumentProcessorService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + ) + + DEFAULT_HOST: str = 'documentai.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + + # If the credentials is service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # TODO(busunkim): This method is in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-auth is increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.process_document: gapic_v1.method.wrap_method( + self.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + self.batch_process_documents: gapic_v1.method.wrap_method( + self.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + self.review_document: gapic_v1.method.wrap_method( + self.review_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + } + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + Union[ + document_processor_service.ProcessResponse, + Awaitable[document_processor_service.ProcessResponse] + ]]: + raise NotImplementedError() + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'DocumentProcessorServiceTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py new file mode 100644 index 00000000..6a11e1a4 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -0,0 +1,329 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.documentai_v1.types import document_processor_service +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + + +class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): + """gRPC backend transport for DocumentProcessorService. + + Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + document_processor_service.ProcessResponse]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessRequest], + ~.ProcessResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/ProcessDocument', + request_serializer=document_processor_service.ProcessRequest.serialize, + response_deserializer=document_processor_service.ProcessResponse.deserialize, + ) + return self._stubs['process_document'] + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + operations_pb2.Operation]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/BatchProcessDocuments', + request_serializer=document_processor_service.BatchProcessRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + operations_pb2.Operation]: + r"""Return a callable for the review document method over gRPC. + + Send a document for Human Review. The input document + should be processed by the specified processor. + + Returns: + Callable[[~.ReviewDocumentRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'review_document' not in self._stubs: + self._stubs['review_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/ReviewDocument', + request_serializer=document_processor_service.ReviewDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['review_document'] + + +__all__ = ( + 'DocumentProcessorServiceGrpcTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py new file mode 100644 index 00000000..b21cb6cc --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -0,0 +1,333 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.documentai_v1.types import document_processor_service +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import DocumentProcessorServiceGrpcTransport + + +class DocumentProcessorServiceGrpcAsyncIOTransport(DocumentProcessorServiceTransport): + """gRPC AsyncIO backend transport for DocumentProcessorService. + + Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + Awaitable[document_processor_service.ProcessResponse]]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessRequest], + Awaitable[~.ProcessResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/ProcessDocument', + request_serializer=document_processor_service.ProcessRequest.serialize, + response_deserializer=document_processor_service.ProcessResponse.deserialize, + ) + return self._stubs['process_document'] + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/BatchProcessDocuments', + request_serializer=document_processor_service.BatchProcessRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the review document method over gRPC. + + Send a document for Human Review. The input document + should be processed by the specified processor. + + Returns: + Callable[[~.ReviewDocumentRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'review_document' not in self._stubs: + self._stubs['review_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1.DocumentProcessorService/ReviewDocument', + request_serializer=document_processor_service.ReviewDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['review_document'] + + +__all__ = ( + 'DocumentProcessorServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py new file mode 100644 index 00000000..5c6e3ea1 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .document import ( + Document, +) +from .document_io import ( + BatchDocumentsInputConfig, + DocumentOutputConfig, + GcsDocument, + GcsDocuments, + GcsPrefix, + RawDocument, +) +from .document_processor_service import ( + BatchProcessMetadata, + BatchProcessRequest, + BatchProcessResponse, + HumanReviewStatus, + ProcessRequest, + ProcessResponse, + ReviewDocumentOperationMetadata, + ReviewDocumentRequest, + ReviewDocumentResponse, +) +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Vertex, +) +from .operation_metadata import ( + CommonOperationMetadata, +) + +__all__ = ( + 'Document', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'RawDocument', + 'BatchProcessMetadata', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'HumanReviewStatus', + 'ProcessRequest', + 'ProcessResponse', + 'ReviewDocumentOperationMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', + 'CommonOperationMetadata', +) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py new file mode 100644 index 00000000..694f1d8b --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py @@ -0,0 +1,1369 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1.types import geometry +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore +from google.type import date_pb2 # type: ignore +from google.type import datetime_pb2 # type: ignore +from google.type import money_pb2 # type: ignore +from google.type import postal_address_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1', + manifest={ + 'Document', + }, +) + + +class Document(proto.Message): + r"""Document represents the canonical document resource in + Document Understanding AI. + It is an interchange format that provides insights into + documents and allows for collaboration between users and + Document Understanding AI to iterate and optimize for quality. + + Attributes: + uri (str): + Optional. Currently supports Google Cloud Storage URI of the + form ``gs://bucket_name/object_name``. Object versioning is + not supported. See `Google Cloud Storage Request + URIs `__ + for more info. + content (bytes): + Optional. Inline document content, represented as a stream + of bytes. Note: As with all ``bytes`` fields, protobuffers + use a pure binary representation, whereas JSON + representations use base64. + mime_type (str): + An IANA published MIME type (also referred to + as media type). For more information, see + https://www.iana.org/assignments/media- + types/media-types.xhtml. + text (str): + Optional. UTF-8 encoded text in reading order + from the document. + text_styles (Sequence[google.cloud.documentai_v1.types.Document.Style]): + Styles for the + [Document.text][google.cloud.documentai.v1.Document.text]. + pages (Sequence[google.cloud.documentai_v1.types.Document.Page]): + Visual page layout for the + [Document][google.cloud.documentai.v1.Document]. + entities (Sequence[google.cloud.documentai_v1.types.Document.Entity]): + A list of entities detected on + [Document.text][google.cloud.documentai.v1.Document.text]. + For document shards, entities in this list may cross shard + boundaries. + entity_relations (Sequence[google.cloud.documentai_v1.types.Document.EntityRelation]): + Relationship among + [Document.entities][google.cloud.documentai.v1.Document.entities]. + text_changes (Sequence[google.cloud.documentai_v1.types.Document.TextChange]): + A list of text corrections made to [Document.text]. This is + usually used for annotating corrections to OCR mistakes. + Text changes for a given revision may not overlap with each + other. + shard_info (google.cloud.documentai_v1.types.Document.ShardInfo): + Information about the sharding if this + document is sharded part of a larger document. + If the document is not sharded, this message is + not specified. + error (google.rpc.status_pb2.Status): + Any error that occurred while processing this + document. + revisions (Sequence[google.cloud.documentai_v1.types.Document.Revision]): + Revision history of this document. + """ + + class ShardInfo(proto.Message): + r"""For a large document, sharding may be performed to produce + several document shards. Each document shard contains this field + to detail which shard it is. + + Attributes: + shard_index (int): + The 0-based index of this shard. + shard_count (int): + Total number of shards. + text_offset (int): + The index of the first character in + [Document.text][google.cloud.documentai.v1.Document.text] in + the overall document global text. + """ + + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) + + class Style(proto.Message): + r"""Annotation for common text style attributes. This adheres to + CSS conventions as much as possible. + + Attributes: + text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor): + Text anchor indexing into the + [Document.text][google.cloud.documentai.v1.Document.text]. + color (google.type.color_pb2.Color): + Text color. + background_color (google.type.color_pb2.Color): + Text background color. + font_weight (str): + Font weight. Possible values are normal, bold, bolder, and + lighter. https://www.w3schools.com/cssref/pr_font_weight.asp + text_style (str): + Text style. Possible values are normal, italic, and oblique. + https://www.w3schools.com/cssref/pr_font_font-style.asp + text_decoration (str): + Text decoration. Follows CSS standard. + https://www.w3schools.com/cssref/pr_text_text-decoration.asp + font_size (google.cloud.documentai_v1.types.Document.Style.FontSize): + Font size. + """ + + class FontSize(proto.Message): + r"""Font size with unit. + Attributes: + size (float): + Font size for the text. + unit (str): + Unit for the font size. Follows CSS naming + (in, px, pt, etc.). + """ + + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, + ) + background_color = proto.Field( + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, + ) + font_size = proto.Field( + proto.MESSAGE, + number=7, + message='Document.Style.FontSize', + ) + + class Page(proto.Message): + r"""A page in a [Document][google.cloud.documentai.v1.Document]. + Attributes: + page_number (int): + 1-based index for current + [Page][google.cloud.documentai.v1.Document.Page] in a parent + [Document][google.cloud.documentai.v1.Document]. Useful when + a page is taken out of a + [Document][google.cloud.documentai.v1.Document] for + individual processing. + image (google.cloud.documentai_v1.types.Document.Page.Image): + Rendered image for this page. This image is + preprocessed to remove any skew, rotation, and + distortions such that the annotation bounding + boxes can be upright and axis-aligned. + transforms (Sequence[google.cloud.documentai_v1.types.Document.Page.Matrix]): + Transformation matrices that were applied to the original + document image to produce + [Page.image][google.cloud.documentai.v1.Document.Page.image]. + dimension (google.cloud.documentai_v1.types.Document.Page.Dimension): + Physical dimension of the page. + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for the page. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + blocks (Sequence[google.cloud.documentai_v1.types.Document.Page.Block]): + A list of visually detected text blocks on + the page. A block has a set of lines (collected + into paragraphs) that have a common line-spacing + and orientation. + paragraphs (Sequence[google.cloud.documentai_v1.types.Document.Page.Paragraph]): + A list of visually detected text paragraphs + on the page. A collection of lines that a human + would perceive as a paragraph. + lines (Sequence[google.cloud.documentai_v1.types.Document.Page.Line]): + A list of visually detected text lines on the + page. A collection of tokens that a human would + perceive as a line. + tokens (Sequence[google.cloud.documentai_v1.types.Document.Page.Token]): + A list of visually detected tokens on the + page. + visual_elements (Sequence[google.cloud.documentai_v1.types.Document.Page.VisualElement]): + A list of detected non-text visual elements + e.g. checkbox, signature etc. on the page. + tables (Sequence[google.cloud.documentai_v1.types.Document.Page.Table]): + A list of visually detected tables on the + page. + form_fields (Sequence[google.cloud.documentai_v1.types.Document.Page.FormField]): + A list of visually detected form fields on + the page. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this page. + """ + + class Dimension(proto.Message): + r"""Dimension for the page. + Attributes: + width (float): + Page width. + height (float): + Page height. + unit (str): + Dimension unit. + """ + + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) + + class Image(proto.Message): + r"""Rendered image contents for this page. + Attributes: + content (bytes): + Raw byte content of the image. + mime_type (str): + Encoding mime type for the image. + width (int): + Width of the image in pixels. + height (int): + Height of the image in pixels. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + width = proto.Field( + proto.INT32, + number=3, + ) + height = proto.Field( + proto.INT32, + number=4, + ) + + class Matrix(proto.Message): + r"""Representation for transformation matrix, intended to be + compatible and used with OpenCV format for image manipulation. + + Attributes: + rows (int): + Number of rows in the matrix. + cols (int): + Number of columns in the matrix. + type_ (int): + This encodes information about what data type the matrix + uses. For example, 0 (CV_8U) is an unsigned 8-bit image. For + the full list of OpenCV primitive data types, please refer + to + https://docs.opencv.org/4.3.0/d1/d1b/group__core__hal__interface.html + data (bytes): + The matrix data. + """ + + rows = proto.Field( + proto.INT32, + number=1, + ) + cols = proto.Field( + proto.INT32, + number=2, + ) + type_ = proto.Field( + proto.INT32, + number=3, + ) + data = proto.Field( + proto.BYTES, + number=4, + ) + + 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 + [Document.text][google.cloud.documentai.v1.Document.text]. + confidence (float): + Confidence of the current + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + within context of the object this layout is for. e.g. + confidence can be for a single token, a table, a visual + element, etc. depending on context. Range [0, 1]. + bounding_poly (google.cloud.documentai_v1.types.BoundingPoly): + The bounding polygon for the + [Layout][google.cloud.documentai.v1.Document.Page.Layout]. + orientation (google.cloud.documentai_v1.types.Document.Page.Layout.Orientation): + Detected orientation for the + [Layout][google.cloud.documentai.v1.Document.Page.Layout]. + """ + class Orientation(proto.Enum): + r"""Detected human reading orientation.""" + ORIENTATION_UNSPECIFIED = 0 + PAGE_UP = 1 + PAGE_RIGHT = 2 + PAGE_DOWN = 3 + PAGE_LEFT = 4 + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + orientation = proto.Field( + proto.ENUM, + number=4, + enum='Document.Page.Layout.Orientation', + ) + + class Block(proto.Message): + r"""A block has a set of lines (collected into paragraphs) that + have a common line-spacing and orientation. + + Attributes: + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for [Block][google.cloud.documentai.v1.Document.Page.Block]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + class Paragraph(proto.Message): + r"""A collection of lines that a human would perceive as a + paragraph. + + Attributes: + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for + [Paragraph][google.cloud.documentai.v1.Document.Page.Paragraph]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + class Line(proto.Message): + r"""A collection of tokens that a human would perceive as a line. + Does not cross column boundaries, can be horizontal, vertical, + etc. + + Attributes: + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for [Line][google.cloud.documentai.v1.Document.Page.Line]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + 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] + for [Token][google.cloud.documentai.v1.Document.Page.Token]. + detected_break (google.cloud.documentai_v1.types.Document.Page.Token.DetectedBreak): + Detected break at the end of a + [Token][google.cloud.documentai.v1.Document.Page.Token]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. + """ + + class DetectedBreak(proto.Message): + r"""Detected break at the end of a + [Token][google.cloud.documentai.v1.Document.Page.Token]. + + Attributes: + type_ (google.cloud.documentai_v1.types.Document.Page.Token.DetectedBreak.Type): + Detected break type. + """ + class Type(proto.Enum): + r"""Enum to denote the type of break found.""" + TYPE_UNSPECIFIED = 0 + SPACE = 1 + WIDE_SPACE = 2 + HYPHEN = 3 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='Document.Page.Token.DetectedBreak.Type', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Token.DetectedBreak', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=4, + message='Document.Provenance', + ) + + class VisualElement(proto.Message): + r"""Detected non-text visual elements e.g. checkbox, signature + etc. on the page. + + Attributes: + layout (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for + [VisualElement][google.cloud.documentai.v1.Document.Page.VisualElement]. + type_ (str): + Type of the + [VisualElement][google.cloud.documentai.v1.Document.Page.VisualElement]. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + + 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] + for [Table][google.cloud.documentai.v1.Document.Page.Table]. + header_rows (Sequence[google.cloud.documentai_v1.types.Document.Page.Table.TableRow]): + Header rows of the table. + body_rows (Sequence[google.cloud.documentai_v1.types.Document.Page.Table.TableRow]): + Body rows of the table. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + 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. + """ + + cells = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.Page.Table.TableCell', + ) + + 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] + for + [TableCell][google.cloud.documentai.v1.Document.Page.Table.TableCell]. + row_span (int): + How many rows this cell spans. + col_span (int): + How many columns this cell spans. + detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + header_rows = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.Table.TableRow', + ) + body_rows = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.Table.TableRow', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + 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] + for the + [FormField][google.cloud.documentai.v1.Document.Page.FormField] + name. e.g. ``Address``, ``Email``, ``Grand total``, + ``Phone number``, etc. + field_value (google.cloud.documentai_v1.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1.Document.Page.Layout] + for the + [FormField][google.cloud.documentai.v1.Document.Page.FormField] + value. + name_detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages for name + together with confidence. + value_detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): + A list of detected languages for value + together with confidence. + value_type (str): + If the value is non-textual, this field represents the type. + Current valid values are: + + - blank (this indicates the field_value is normal text) + - "unfilled_checkbox" + - "filled_checkbox". + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. + """ + + field_name = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + field_value = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Layout', + ) + name_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + value_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + value_type = proto.Field( + proto.STRING, + number=5, + ) + provenance = proto.Field( + proto.MESSAGE, + number=8, + message='Document.Provenance', + ) + + 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 + more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + confidence (float): + Confidence of detected language. Range [0, 1]. + """ + + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + + page_number = proto.Field( + proto.INT32, + number=1, + ) + image = proto.Field( + proto.MESSAGE, + number=13, + message='Document.Page.Image', + ) + transforms = proto.RepeatedField( + proto.MESSAGE, + number=14, + message='Document.Page.Matrix', + ) + dimension = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Dimension', + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='Document.Page.Block', + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=6, + message='Document.Page.Paragraph', + ) + lines = proto.RepeatedField( + proto.MESSAGE, + number=7, + message='Document.Page.Line', + ) + tokens = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='Document.Page.Token', + ) + visual_elements = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Document.Page.VisualElement', + ) + tables = proto.RepeatedField( + proto.MESSAGE, + number=10, + message='Document.Page.Table', + ) + form_fields = proto.RepeatedField( + proto.MESSAGE, + number=11, + message='Document.Page.FormField', + ) + provenance = proto.Field( + proto.MESSAGE, + number=16, + message='Document.Provenance', + ) + + class Entity(proto.Message): + r"""A phrase in the text that is a known entity type, such as a + person, an organization, or location. + + Attributes: + text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor): + Optional. Provenance of the entity. Text anchor indexing + into the + [Document.text][google.cloud.documentai.v1.Document.text]. + type_ (str): + Entity type from a schema e.g. ``Address``. + mention_text (str): + Optional. Text value in the document e.g. + ``1600 Amphitheatre Pkwy``. + mention_id (str): + Optional. Deprecated. Use ``id`` field instead. + confidence (float): + Optional. Confidence of detected Schema entity. Range [0, + 1]. + page_anchor (google.cloud.documentai_v1.types.Document.PageAnchor): + Optional. Represents the provenance of this + entity wrt. the location on the page where it + was found. + id (str): + Optional. Canonical id. This will be a unique + value in the entity list for this document. + normalized_value (google.cloud.documentai_v1.types.Document.Entity.NormalizedValue): + Optional. Normalized entity value. Absent if + the extracted value could not be converted or + the type (e.g. address) is not supported for + certain parsers. This field is also only + populated for certain supported document types. + properties (Sequence[google.cloud.documentai_v1.types.Document.Entity]): + Optional. Entities can be nested to form a + hierarchical data structure representing the + content in the document. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + Optional. The history of this annotation. + redacted (bool): + Optional. Whether the entity will be redacted + for de-identification purposes. + """ + + class NormalizedValue(proto.Message): + r"""Parsed and normalized entity value. + Attributes: + money_value (google.type.money_pb2.Money): + Money value. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/money.proto + date_value (google.type.date_pb2.Date): + Date value. Includes year, month, day. See + also: + https://github.com/googleapis/googleapis/blob/master/google/type/date.proto + datetime_value (google.type.datetime_pb2.DateTime): + DateTime value. Includes date, time, and + timezone. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto + address_value (google.type.postal_address_pb2.PostalAddress): + Postal address. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto + boolean_value (bool): + Boolean value. Can be used for entities with + binary values, or for checkboxes. + text (str): + Required. Normalized entity value stored as a string. This + field is populated for supported document type (e.g. + Invoice). For some entity types, one of respective + 'structured_value' fields may also be populated. + + - Money/Currency type (``money_value``) is in the ISO 4217 + text format. + - Date type (``date_value``) is in the ISO 8601 text + format. + - Datetime type (``datetime_value``) is in the ISO 8601 + text format. + """ + + money_value = proto.Field( + proto.MESSAGE, + number=2, + oneof='structured_value', + message=money_pb2.Money, + ) + date_value = proto.Field( + proto.MESSAGE, + number=3, + oneof='structured_value', + message=date_pb2.Date, + ) + datetime_value = proto.Field( + proto.MESSAGE, + number=4, + oneof='structured_value', + message=datetime_pb2.DateTime, + ) + address_value = proto.Field( + proto.MESSAGE, + number=5, + oneof='structured_value', + message=postal_address_pb2.PostalAddress, + ) + boolean_value = proto.Field( + proto.BOOL, + number=6, + oneof='structured_value', + ) + text = proto.Field( + proto.STRING, + number=1, + ) + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + page_anchor = proto.Field( + proto.MESSAGE, + number=6, + message='Document.PageAnchor', + ) + id = proto.Field( + proto.STRING, + number=7, + ) + normalized_value = proto.Field( + proto.MESSAGE, + number=9, + message='Document.Entity.NormalizedValue', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=10, + message='Document.Entity', + ) + provenance = proto.Field( + proto.MESSAGE, + number=11, + message='Document.Provenance', + ) + redacted = proto.Field( + proto.BOOL, + number=12, + ) + + class EntityRelation(proto.Message): + r"""Relationship between + [Entities][google.cloud.documentai.v1.Document.Entity]. + + Attributes: + subject_id (str): + Subject entity id. + object_id (str): + Object entity id. + relation (str): + Relationship description. + """ + + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) + + class TextAnchor(proto.Message): + r"""Text reference indexing into the + [Document.text][google.cloud.documentai.v1.Document.text]. + + Attributes: + text_segments (Sequence[google.cloud.documentai_v1.types.Document.TextAnchor.TextSegment]): + The text segments from the + [Document.text][google.cloud.documentai.v1.Document.text]. + content (str): + Contains the content of the text span so that users do not + have to look it up in the text_segments. + """ + + class TextSegment(proto.Message): + r"""A text segment in the + [Document.text][google.cloud.documentai.v1.Document.text]. The + indices may be out of bounds which indicate that the text extends + into another document shard for large sharded documents. See + [ShardInfo.text_offset][google.cloud.documentai.v1.Document.ShardInfo.text_offset] + + Attributes: + start_index (int): + [TextSegment][google.cloud.documentai.v1.Document.TextAnchor.TextSegment] + start UTF-8 char index in the + [Document.text][google.cloud.documentai.v1.Document.text]. + end_index (int): + [TextSegment][google.cloud.documentai.v1.Document.TextAnchor.TextSegment] + half open end UTF-8 char index in the + [Document.text][google.cloud.documentai.v1.Document.text]. + """ + + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) + + text_segments = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.TextAnchor.TextSegment', + ) + content = proto.Field( + proto.STRING, + number=2, + ) + + class PageAnchor(proto.Message): + r"""Referencing the visual context of the entity in the + [Document.pages][google.cloud.documentai.v1.Document.pages]. Page + anchors can be cross-page, consist of multiple bounding polygons and + optionally reference specific layout element types. + + Attributes: + page_refs (Sequence[google.cloud.documentai_v1.types.Document.PageAnchor.PageRef]): + One or more references to visual page + elements + """ + + class PageRef(proto.Message): + r"""Represents a weak reference to a page element within a + document. + + Attributes: + page (int): + Required. Index into the + [Document.pages][google.cloud.documentai.v1.Document.pages] + element, for example using [Document.pages][page_refs.page] + to locate the related page element. This field is skipped + when its value is the default 0. See + https://developers.google.com/protocol-buffers/docs/proto3#json. + layout_type (google.cloud.documentai_v1.types.Document.PageAnchor.PageRef.LayoutType): + Optional. The type of the layout element that + is being referenced if any. + layout_id (str): + Optional. Deprecated. Use + [PageRef.bounding_poly][google.cloud.documentai.v1.Document.PageAnchor.PageRef.bounding_poly] + instead. + bounding_poly (google.cloud.documentai_v1.types.BoundingPoly): + Optional. Identifies the bounding polygon of + a layout element on the page. + confidence (float): + Optional. Confidence of detected page element, if + applicable. Range [0, 1]. + """ + class LayoutType(proto.Enum): + r"""The type of layout that is being referenced.""" + LAYOUT_TYPE_UNSPECIFIED = 0 + BLOCK = 1 + PARAGRAPH = 2 + LINE = 3 + TOKEN = 4 + VISUAL_ELEMENT = 5 + TABLE = 6 + FORM_FIELD = 7 + + page = proto.Field( + proto.INT64, + number=1, + ) + layout_type = proto.Field( + proto.ENUM, + number=2, + enum='Document.PageAnchor.PageRef.LayoutType', + ) + layout_id = proto.Field( + proto.STRING, + number=3, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + page_refs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.PageAnchor.PageRef', + ) + + class Provenance(proto.Message): + r"""Structure to identify provenance relationships between + annotations in different revisions. + + Attributes: + revision (int): + The index of the revision that produced this + element. + id (int): + The Id of this operation. Needs to be unique + within the scope of the revision. + parents (Sequence[google.cloud.documentai_v1.types.Document.Provenance.Parent]): + References to the original elements that are + replaced. + type_ (google.cloud.documentai_v1.types.Document.Provenance.OperationType): + The type of provenance operation. + """ + class OperationType(proto.Enum): + r"""If a processor or agent does an explicit operation on + existing elements. + """ + OPERATION_TYPE_UNSPECIFIED = 0 + ADD = 1 + REMOVE = 2 + REPLACE = 3 + EVAL_REQUESTED = 4 + EVAL_APPROVED = 5 + EVAL_SKIPPED = 6 + + class Parent(proto.Message): + r"""Structure for referencing parent provenances. When an + element replaces one of more other elements parent references + identify the elements that are replaced. + + Attributes: + revision (int): + The index of the [Document.revisions] identifying the parent + revision. + index (int): + The index of the parent revisions + corresponding collection of items (eg. list of + entities, properties within entities, etc.) + id (int): + The id of the parent provenance. + """ + + revision = proto.Field( + proto.INT32, + number=1, + ) + index = proto.Field( + proto.INT32, + number=3, + ) + id = proto.Field( + proto.INT32, + number=2, + ) + + revision = proto.Field( + proto.INT32, + number=1, + ) + id = proto.Field( + proto.INT32, + number=2, + ) + parents = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Provenance.Parent', + ) + type_ = proto.Field( + proto.ENUM, + number=4, + enum='Document.Provenance.OperationType', + ) + + 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 + the name or id of that person. + processor (str): + If the annotation was made by processor + identify the processor by its resource name. + id (str): + Id of the revision. Unique within the + context of the document. + parent (Sequence[int]): + The revisions that this revision is based on. This can + include one or more parent (when documents are merged.) This + field represents the index into the ``revisions`` field. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time that the revision was created. + human_review (google.cloud.documentai_v1.types.Document.Revision.HumanReview): + Human Review information of this revision. + """ + + class HumanReview(proto.Message): + r"""Human Review information of the document. + Attributes: + state (str): + Human review state. e.g. ``requested``, ``succeeded``, + ``rejected``. + state_message (str): + A message providing more details about the current state of + processing. For example, the rejection reason when the state + is ``rejected``. + """ + + state = proto.Field( + proto.STRING, + number=1, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + + agent = proto.Field( + proto.STRING, + number=4, + oneof='source', + ) + processor = proto.Field( + proto.STRING, + number=5, + oneof='source', + ) + id = proto.Field( + proto.STRING, + number=1, + ) + parent = proto.RepeatedField( + proto.INT32, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + human_review = proto.Field( + proto.MESSAGE, + number=6, + message='Document.Revision.HumanReview', + ) + + 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 + [Document.text][google.cloud.documentai.v1.Document.text]. + There can only be a single ``TextAnchor.text_segments`` + element. If the start and end index of the text segment are + the same, the text change is inserted before that index. + changed_text (str): + The text that replaces the text identified in the + ``text_anchor``. + provenance (Sequence[google.cloud.documentai_v1.types.Document.Provenance]): + The history of this annotation. + """ + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + changed_text = proto.Field( + proto.STRING, + number=2, + ) + provenance = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + uri = proto.Field( + proto.STRING, + number=1, + oneof='source', + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof='source', + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) + entity_relations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + text_changes = proto.RepeatedField( + proto.MESSAGE, + number=14, + message=TextChange, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + revisions = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=Revision, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py new file mode 100644 index 00000000..fb0abcb7 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1', + manifest={ + 'RawDocument', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + }, +) + + +class RawDocument(proto.Message): + r"""Payload message of raw document content (bytes). + Attributes: + content (bytes): + Inline document content. + mime_type (str): + An IANA MIME type (RFC6838) indicating the nature and format + of the [content]. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class GcsDocument(proto.Message): + r"""Specifies a document stored on Cloud Storage. + Attributes: + gcs_uri (str): + The Cloud Storage object uri. + mime_type (str): + An IANA MIME type (RFC6838) of the content. + """ + + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +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. + """ + + documents = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='GcsDocument', + ) + + +class GcsPrefix(proto.Message): + r"""Specifies all documents on Cloud Storage with a common + prefix. + + Attributes: + gcs_uri_prefix (str): + The URI prefix. + """ + + gcs_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchDocumentsInputConfig(proto.Message): + r"""The common config to specify a set of documents used as + input. + + Attributes: + gcs_prefix (google.cloud.documentai_v1.types.GcsPrefix): + The set of documents that match the specified Cloud Storage + [gcs_prefix]. + gcs_documents (google.cloud.documentai_v1.types.GcsDocuments): + The set of documents individually specified + on Cloud Storage. + """ + + gcs_prefix = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='GcsPrefix', + ) + gcs_documents = proto.Field( + proto.MESSAGE, + number=2, + oneof='source', + message='GcsDocuments', + ) + + +class DocumentOutputConfig(proto.Message): + r"""Config that controls the output of documents. All documents + will be written as a JSON file. + + Attributes: + gcs_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig.GcsOutputConfig): + Output config to write the results to Cloud + Storage. + """ + + class GcsOutputConfig(proto.Message): + r"""The configuration used when outputting documents. + Attributes: + gcs_uri (str): + The Cloud Storage uri (a directory) of the + output. + """ + + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + + gcs_output_config = proto.Field( + proto.MESSAGE, + number=1, + oneof='destination', + message=GcsOutputConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py new file mode 100644 index 00000000..53c58d05 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py @@ -0,0 +1,343 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1.types import document as gcd_document +from google.cloud.documentai_v1.types import document_io +from google.cloud.documentai_v1.types import operation_metadata +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1', + manifest={ + 'ProcessRequest', + 'HumanReviewStatus', + 'ProcessResponse', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'BatchProcessMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'ReviewDocumentOperationMetadata', + }, +) + + +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. + raw_document (google.cloud.documentai_v1.types.RawDocument): + A raw document content (bytes). + name (str): + Required. The processor resource name. + skip_human_review (bool): + Whether Human Review feature should be + skipped for this request. Default to false. + """ + + inline_document = proto.Field( + proto.MESSAGE, + number=4, + oneof='source', + message=gcd_document.Document, + ) + raw_document = proto.Field( + proto.MESSAGE, + number=5, + oneof='source', + message=document_io.RawDocument, + ) + name = proto.Field( + proto.STRING, + number=1, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=3, + ) + + +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 + request. + state_message (str): + A message providing more details about the + human review state. + human_review_operation (str): + The name of the operation triggered by the processed + document. This field is populated only when the [state] is + [HUMAN_REVIEW_IN_PROGRESS]. It has the same response type + and metadata as the long running operation returned by + [ReviewDocument] method. + """ + class State(proto.Enum): + r"""The final state of human review on a processed document.""" + STATE_UNSPECIFIED = 0 + SKIPPED = 1 + VALIDATION_PASSED = 2 + IN_PROGRESS = 3 + ERROR = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + human_review_operation = proto.Field( + proto.STRING, + number=3, + ) + + +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 + based on the processor's behavior. + human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus): + The status of human review on the processed + document. + """ + + document = proto.Field( + proto.MESSAGE, + number=1, + message=gcd_document.Document, + ) + human_review_status = proto.Field( + proto.MESSAGE, + number=3, + message='HumanReviewStatus', + ) + + +class BatchProcessRequest(proto.Message): + r"""Request message for batch process document method. + Attributes: + name (str): + Required. The processor resource name. + input_documents (google.cloud.documentai_v1.types.BatchDocumentsInputConfig): + The input documents for batch process. + document_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig): + The overall output config for batch process. + skip_human_review (bool): + Whether Human Review feature should be + skipped for this request. Default to false. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + input_documents = proto.Field( + proto.MESSAGE, + number=5, + message=document_io.BatchDocumentsInputConfig, + ) + document_output_config = proto.Field( + proto.MESSAGE, + number=6, + message=document_io.DocumentOutputConfig, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=4, + ) + + +class BatchProcessResponse(proto.Message): + 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. + state_message (str): + A message providing more details about the + current state of processing. For example, the + error message if the operation is failed. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + individual_process_statuses (Sequence[google.cloud.documentai_v1.types.BatchProcessMetadata.IndividualProcessStatus]): + The list of response details of each + document. + """ + class State(proto.Enum): + r"""Possible states of the batch processing operation.""" + STATE_UNSPECIFIED = 0 + WAITING = 1 + RUNNING = 2 + SUCCEEDED = 3 + CANCELLING = 4 + CANCELLED = 5 + FAILED = 6 + + class IndividualProcessStatus(proto.Message): + r"""The status of a each individual document in the batch + process. + + Attributes: + input_gcs_source (str): + The source of the document, same as the [input_gcs_source] + field in the request when the batch process started. The + batch process is started by take snapshot of that document, + since a user can move or change that document during the + process. + status (google.rpc.status_pb2.Status): + The status of the processing of the document. + output_gcs_destination (str): + The output_gcs_destination (in the request as + 'output_gcs_destination') of the processed document if it + was successful, otherwise empty. + human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus): + The status of human review on the processed + document. + """ + + input_gcs_source = proto.Field( + proto.STRING, + number=1, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + output_gcs_destination = proto.Field( + proto.STRING, + number=3, + ) + human_review_status = proto.Field( + proto.MESSAGE, + number=5, + message='HumanReviewStatus', + ) + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + individual_process_statuses = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=IndividualProcessStatus, + ) + + +class ReviewDocumentRequest(proto.Message): + r"""Request message for review document method. + Attributes: + inline_document (google.cloud.documentai_v1.types.Document): + An inline document proto. + human_review_config (str): + Required. The resource name of the + HumanReviewConfig that the document will be + reviewed with. + enable_schema_validation (bool): + Whether the validation should be performed on + the ad-hoc review request. + priority (google.cloud.documentai_v1.types.ReviewDocumentRequest.Priority): + The priority of the human review task. + """ + class Priority(proto.Enum): + r"""The priority level of the human review task.""" + DEFAULT = 0 + URGENT = 1 + + inline_document = proto.Field( + proto.MESSAGE, + number=4, + oneof='source', + message=gcd_document.Document, + ) + human_review_config = proto.Field( + proto.STRING, + number=1, + ) + enable_schema_validation = proto.Field( + proto.BOOL, + number=3, + ) + priority = proto.Field( + proto.ENUM, + number=5, + enum=Priority, + ) + + +class ReviewDocumentResponse(proto.Message): + r"""Response message for review document method. + Attributes: + gcs_destination (str): + The Cloud Storage uri for the human reviewed + document. + """ + + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) + + +class ReviewDocumentOperationMetadata(proto.Message): + r"""The long running operation metadata for review document + method. + + Attributes: + common_metadata (google.cloud.documentai_v1.types.CommonOperationMetadata): + The basic metadata of the long running + operation. + """ + + common_metadata = proto.Field( + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py new file mode 100644 index 00000000..d145d2a0 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + }, +) + + +class Vertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the vertex coordinates are in the same scale as the + original image. + + Attributes: + x (int): + X coordinate. + y (int): + Y coordinate (starts from the top of the + image). + """ + + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) + + +class NormalizedVertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the normalized vertex coordinates are relative to the + original image and range from 0 to 1. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate (starts from the top of the + image). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + + +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. + normalized_vertices (Sequence[google.cloud.documentai_v1.types.NormalizedVertex]): + The bounding polygon normalized vertices. + """ + + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Vertex', + ) + normalized_vertices = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='NormalizedVertex', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py new file mode 100644 index 00000000..eec502d1 --- /dev/null +++ b/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1', + manifest={ + 'CommonOperationMetadata', + }, +) + + +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. + state_message (str): + A message providing more details about the + current state of processing. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + """ + class State(proto.Enum): + r"""State of the longrunning operation.""" + STATE_UNSPECIFIED = 0 + RUNNING = 1 + CANCELLING = 2 + SUCCEEDED = 3 + FAILED = 4 + CANCELLED = 5 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/mypy.ini b/owl-bot-staging/v1/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1/noxfile.py b/owl-bot-staging/v1/noxfile.py new file mode 100644 index 00000000..8dd88b2e --- /dev/null +++ b/owl-bot-staging/v1/noxfile.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", +] + +@nox.session(python=['3.6', '3.7', '3.8', '3.9']) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/documentai_v1/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python='3.7') +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=['3.6', '3.7']) +def mypy(session): + """Run the type checker.""" + session.install('mypy', 'types-pkg_resources') + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python='3.6') +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx<3.0.0", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py b/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py new file mode 100644 index 00000000..4ad5f8d7 --- /dev/null +++ b/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py @@ -0,0 +1,178 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class documentaiCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'batch_process_documents': ('name', 'input_documents', 'document_output_config', 'skip_human_review', ), + 'process_document': ('name', 'inline_document', 'raw_document', 'skip_human_review', ), + 'review_document': ('human_review_config', 'inline_document', 'enable_schema_validation', 'priority', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: not a.keyword.value in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=documentaiCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the documentai client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1/setup.py b/owl-bot-staging/v1/setup.py new file mode 100644 index 00000000..90b5b3cf --- /dev/null +++ b/owl-bot-staging/v1/setup.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os +import setuptools # type: ignore + +version = '0.1.0' + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, 'README.rst') +with io.open(readme_filename, encoding='utf-8') as readme_file: + readme = readme_file.read() + +setuptools.setup( + name='google-cloud-documentai', + version=version, + long_description=readme, + packages=setuptools.PEP420PackageFinder.find(), + namespace_packages=('google', 'google.cloud'), + platforms='Posix; MacOS X; Windows', + include_package_data=True, + install_requires=( + 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', + 'libcst >= 0.2.5', + 'proto-plus >= 1.15.0', + 'packaging >= 14.3', ), + python_requires='>=3.6', + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1/tests/__init__.py b/owl-bot-staging/v1/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1/tests/unit/__init__.py b/owl-bot-staging/v1/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py new file mode 100644 index 00000000..da500783 --- /dev/null +++ b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -0,0 +1,1695 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import mock +import packaging.version + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.documentai_v1.services.document_processor_service import DocumentProcessorServiceAsyncClient +from google.cloud.documentai_v1.services.document_processor_service import DocumentProcessorServiceClient +from google.cloud.documentai_v1.services.document_processor_service import transports +from google.cloud.documentai_v1.services.document_processor_service.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.documentai_v1.types import document +from google.cloud.documentai_v1.types import document_io +from google.cloud.documentai_v1.types import document_processor_service +from google.cloud.documentai_v1.types import geometry +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import wrappers_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore +from google.type import date_pb2 # type: ignore +from google.type import datetime_pb2 # type: ignore +from google.type import money_pb2 # type: ignore +from google.type import postal_address_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_from_service_account_info(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'documentai.googleapis.com:443' + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_service_account_always_use_jwt(client_class): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_service_account_always_use_jwt_true(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_from_service_account_file(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'documentai.googleapis.com:443' + + +def test_document_processor_service_client_get_transport_class(): + transport = DocumentProcessorServiceClient.get_transport_class() + available_transports = [ + transports.DocumentProcessorServiceGrpcTransport, + ] + assert transport in available_transports + + transport = DocumentProcessorServiceClient.get_transport_class("grpc") + assert transport == transports.DocumentProcessorServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) +@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) +def test_document_processor_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "true"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "false"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) +@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_document_processor_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_client_options_credentials_file(client_class, transport_class, transport_name): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_document_processor_service_client_client_options_from_dict(): + with mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = DocumentProcessorServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_process_document(transport: str = 'grpc', request_type=document_processor_service.ProcessRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse( + ) + response = client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.ProcessResponse) + + +def test_process_document_from_dict(): + test_process_document(request_type=dict) + + +def test_process_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + client.process_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + +@pytest.mark.asyncio +async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ProcessRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse( + )) + response = await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.ProcessResponse) + + +@pytest.mark.asyncio +async def test_process_document_async_from_dict(): + await test_process_document_async(request_type=dict) + + +def test_process_document_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = document_processor_service.ProcessResponse() + client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_process_document_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) + await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_process_document_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.process_document( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +def test_process_document_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.process_document( + document_processor_service.ProcessRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_process_document_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.process_document( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +@pytest.mark.asyncio +async def test_process_document_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.process_document( + document_processor_service.ProcessRequest(), + name='name_value', + ) + + +def test_batch_process_documents(transport: str = 'grpc', request_type=document_processor_service.BatchProcessRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_batch_process_documents_from_dict(): + test_batch_process_documents(request_type=dict) + + +def test_batch_process_documents_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + client.batch_process_documents() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + +@pytest.mark.asyncio +async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.BatchProcessRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_batch_process_documents_async_from_dict(): + await test_batch_process_documents_async(request_type=dict) + + +def test_batch_process_documents_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.BatchProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_batch_process_documents_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.BatchProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_batch_process_documents_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_process_documents( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +def test_batch_process_documents_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_process_documents( + document_processor_service.BatchProcessRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_process_documents( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_process_documents( + document_processor_service.BatchProcessRequest(), + name='name_value', + ) + + +def test_review_document(transport: str = 'grpc', request_type=document_processor_service.ReviewDocumentRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_review_document_from_dict(): + test_review_document(request_type=dict) + + +def test_review_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + client.review_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + +@pytest.mark.asyncio +async def test_review_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ReviewDocumentRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_review_document_async_from_dict(): + await test_review_document_async(request_type=dict) + + +def test_review_document_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ReviewDocumentRequest() + + request.human_review_config = 'human_review_config/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'human_review_config=human_review_config/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_review_document_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ReviewDocumentRequest() + + request.human_review_config = 'human_review_config/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'human_review_config=human_review_config/value', + ) in kw['metadata'] + + +def test_review_document_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.review_document( + human_review_config='human_review_config_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].human_review_config == 'human_review_config_value' + + +def test_review_document_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.review_document( + document_processor_service.ReviewDocumentRequest(), + human_review_config='human_review_config_value', + ) + + +@pytest.mark.asyncio +async def test_review_document_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.review_document( + human_review_config='human_review_config_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].human_review_config == 'human_review_config_value' + + +@pytest.mark.asyncio +async def test_review_document_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.review_document( + document_processor_service.ReviewDocumentRequest(), + human_review_config='human_review_config_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = DocumentProcessorServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DocumentProcessorServiceGrpcTransport, + ) + +def test_document_processor_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.DocumentProcessorServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_document_processor_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.DocumentProcessorServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'process_document', + 'batch_process_documents', + 'review_document', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + ), + quota_project_id="octopus", + ) + + +def test_document_processor_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentProcessorServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentProcessorServiceClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") + adc.assert_called_once_with(scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_document_processor_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "documentai.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + scopes=["1", "2"], + default_host="documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + + +def test_document_processor_service_host_no_port(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com'), + ) + assert client.transport._host == 'documentai.googleapis.com:443' + + +def test_document_processor_service_host_with_port(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com:8000'), + ) + assert client.transport._host == 'documentai.googleapis.com:8000' + +def test_document_processor_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentProcessorServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_document_processor_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_document_processor_service_grpc_lro_client(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_document_processor_service_grpc_lro_async_client(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc_asyncio', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_human_review_config_path(): + project = "squid" + location = "clam" + processor = "whelk" + expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) + actual = DocumentProcessorServiceClient.human_review_config_path(project, location, processor) + assert expected == actual + + +def test_parse_human_review_config_path(): + expected = { + "project": "octopus", + "location": "oyster", + "processor": "nudibranch", + } + path = DocumentProcessorServiceClient.human_review_config_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_human_review_config_path(path) + assert expected == actual + +def test_processor_path(): + project = "cuttlefish" + location = "mussel" + processor = "winkle" + expected = "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) + actual = DocumentProcessorServiceClient.processor_path(project, location, processor) + assert expected == actual + + +def test_parse_processor_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "processor": "abalone", + } + path = DocumentProcessorServiceClient.processor_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_processor_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = DocumentProcessorServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = DocumentProcessorServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = DocumentProcessorServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = DocumentProcessorServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = DocumentProcessorServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = DocumentProcessorServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = DocumentProcessorServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = DocumentProcessorServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = DocumentProcessorServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = DocumentProcessorServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = DocumentProcessorServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) diff --git a/owl-bot-staging/v1beta2/.coveragerc b/owl-bot-staging/v1beta2/.coveragerc new file mode 100644 index 00000000..ef619357 --- /dev/null +++ b/owl-bot-staging/v1beta2/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/documentai/__init__.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ + # Ignore pkg_resources exceptions. + # This is added at the module level as a safeguard for if someone + # generates the code and tries to run it without pip installing. This + # makes it virtually impossible to test properly. + except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1beta2/MANIFEST.in b/owl-bot-staging/v1beta2/MANIFEST.in new file mode 100644 index 00000000..cd0fd7a8 --- /dev/null +++ b/owl-bot-staging/v1beta2/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/documentai *.py +recursive-include google/cloud/documentai_v1beta2 *.py diff --git a/owl-bot-staging/v1beta2/README.rst b/owl-bot-staging/v1beta2/README.rst new file mode 100644 index 00000000..484a3c1c --- /dev/null +++ b/owl-bot-staging/v1beta2/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Documentai API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Documentai API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1beta2/docs/conf.py b/owl-bot-staging/v1beta2/docs/conf.py new file mode 100644 index 00000000..0788579e --- /dev/null +++ b/owl-bot-staging/v1beta2/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-documentai documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "1.6.3" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = u"google-cloud-documentai" +copyright = u"2020, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-documentai-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + master_doc, + "google-cloud-documentai.tex", + u"google-cloud-documentai Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + master_doc, + "google-cloud-documentai", + u"Google Cloud Documentai Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "google-cloud-documentai", + u"google-cloud-documentai Documentation", + author, + "google-cloud-documentai", + "GAPIC library for Google Cloud Documentai API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst new file mode 100644 index 00000000..a0d0da7e --- /dev/null +++ b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst @@ -0,0 +1,6 @@ +DocumentUnderstandingService +---------------------------------------------- + +.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service + :members: + :inherited-members: diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst new file mode 100644 index 00000000..13f4a238 --- /dev/null +++ b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Documentai v1beta2 API +================================================ +.. toctree:: + :maxdepth: 2 + + document_understanding_service diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst new file mode 100644 index 00000000..9edede43 --- /dev/null +++ b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Documentai v1beta2 API +============================================= + +.. automodule:: google.cloud.documentai_v1beta2.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1beta2/docs/index.rst b/owl-bot-staging/v1beta2/docs/index.rst new file mode 100644 index 00000000..38d5fbb5 --- /dev/null +++ b/owl-bot-staging/v1beta2/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + documentai_v1beta2/services + documentai_v1beta2/types diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py new file mode 100644 index 00000000..fe8a1486 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.cloud.documentai_v1beta2.services.document_understanding_service.client import DocumentUnderstandingServiceClient +from google.cloud.documentai_v1beta2.services.document_understanding_service.async_client import DocumentUnderstandingServiceAsyncClient + +from google.cloud.documentai_v1beta2.types.document import Document +from google.cloud.documentai_v1beta2.types.document_understanding import AutoMlParams +from google.cloud.documentai_v1beta2.types.document_understanding import BatchProcessDocumentsRequest +from google.cloud.documentai_v1beta2.types.document_understanding import BatchProcessDocumentsResponse +from google.cloud.documentai_v1beta2.types.document_understanding import EntityExtractionParams +from google.cloud.documentai_v1beta2.types.document_understanding import FormExtractionParams +from google.cloud.documentai_v1beta2.types.document_understanding import GcsDestination +from google.cloud.documentai_v1beta2.types.document_understanding import GcsSource +from google.cloud.documentai_v1beta2.types.document_understanding import InputConfig +from google.cloud.documentai_v1beta2.types.document_understanding import KeyValuePairHint +from google.cloud.documentai_v1beta2.types.document_understanding import OcrParams +from google.cloud.documentai_v1beta2.types.document_understanding import OperationMetadata +from google.cloud.documentai_v1beta2.types.document_understanding import OutputConfig +from google.cloud.documentai_v1beta2.types.document_understanding import ProcessDocumentRequest +from google.cloud.documentai_v1beta2.types.document_understanding import ProcessDocumentResponse +from google.cloud.documentai_v1beta2.types.document_understanding import TableBoundHint +from google.cloud.documentai_v1beta2.types.document_understanding import TableExtractionParams +from google.cloud.documentai_v1beta2.types.geometry import BoundingPoly +from google.cloud.documentai_v1beta2.types.geometry import NormalizedVertex +from google.cloud.documentai_v1beta2.types.geometry import Vertex + +__all__ = ('DocumentUnderstandingServiceClient', + 'DocumentUnderstandingServiceAsyncClient', + 'Document', + 'AutoMlParams', + 'BatchProcessDocumentsRequest', + 'BatchProcessDocumentsResponse', + 'EntityExtractionParams', + 'FormExtractionParams', + 'GcsDestination', + 'GcsSource', + 'InputConfig', + 'KeyValuePairHint', + 'OcrParams', + 'OperationMetadata', + 'OutputConfig', + 'ProcessDocumentRequest', + 'ProcessDocumentResponse', + 'TableBoundHint', + 'TableExtractionParams', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed b/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py new file mode 100644 index 00000000..afa1ecee --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from .services.document_understanding_service import DocumentUnderstandingServiceClient +from .services.document_understanding_service import DocumentUnderstandingServiceAsyncClient + +from .types.document import Document +from .types.document_understanding import AutoMlParams +from .types.document_understanding import BatchProcessDocumentsRequest +from .types.document_understanding import BatchProcessDocumentsResponse +from .types.document_understanding import EntityExtractionParams +from .types.document_understanding import FormExtractionParams +from .types.document_understanding import GcsDestination +from .types.document_understanding import GcsSource +from .types.document_understanding import InputConfig +from .types.document_understanding import KeyValuePairHint +from .types.document_understanding import OcrParams +from .types.document_understanding import OperationMetadata +from .types.document_understanding import OutputConfig +from .types.document_understanding import ProcessDocumentRequest +from .types.document_understanding import ProcessDocumentResponse +from .types.document_understanding import TableBoundHint +from .types.document_understanding import TableExtractionParams +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Vertex + +__all__ = ( + 'DocumentUnderstandingServiceAsyncClient', +'AutoMlParams', +'BatchProcessDocumentsRequest', +'BatchProcessDocumentsResponse', +'BoundingPoly', +'Document', +'DocumentUnderstandingServiceClient', +'EntityExtractionParams', +'FormExtractionParams', +'GcsDestination', +'GcsSource', +'InputConfig', +'KeyValuePairHint', +'NormalizedVertex', +'OcrParams', +'OperationMetadata', +'OutputConfig', +'ProcessDocumentRequest', +'ProcessDocumentResponse', +'TableBoundHint', +'TableExtractionParams', +'Vertex', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json new file mode 100644 index 00000000..633dcc19 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json @@ -0,0 +1,43 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.documentai_v1beta2", + "protoPackage": "google.cloud.documentai.v1beta2", + "schema": "1.0", + "services": { + "DocumentUnderstandingService": { + "clients": { + "grpc": { + "libraryClient": "DocumentUnderstandingServiceClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DocumentUnderstandingServiceAsyncClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py new file mode 100644 index 00000000..f9f99508 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import DocumentUnderstandingServiceClient +from .async_client import DocumentUnderstandingServiceAsyncClient + +__all__ = ( + 'DocumentUnderstandingServiceClient', + 'DocumentUnderstandingServiceAsyncClient', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py new file mode 100644 index 00000000..2f33a657 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py @@ -0,0 +1,327 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +import pkg_resources + +import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.rpc import status_pb2 # type: ignore +from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport +from .client import DocumentUnderstandingServiceClient + + +class DocumentUnderstandingServiceAsyncClient: + """Service to parse structured information from unstructured or + semi-structured documents using state-of-the-art Google AI such + as natural language, computer vision, and translation. + """ + + _client: DocumentUnderstandingServiceClient + + DEFAULT_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + + common_billing_account_path = staticmethod(DocumentUnderstandingServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(DocumentUnderstandingServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(DocumentUnderstandingServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_organization_path) + common_project_path = staticmethod(DocumentUnderstandingServiceClient.common_project_path) + parse_common_project_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_project_path) + common_location_path = staticmethod(DocumentUnderstandingServiceClient.common_location_path) + parse_common_location_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentUnderstandingServiceAsyncClient: The constructed client. + """ + return DocumentUnderstandingServiceClient.from_service_account_info.__func__(DocumentUnderstandingServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentUnderstandingServiceAsyncClient: The constructed client. + """ + return DocumentUnderstandingServiceClient.from_service_account_file.__func__(DocumentUnderstandingServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentUnderstandingServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentUnderstandingServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(DocumentUnderstandingServiceClient).get_transport_class, type(DocumentUnderstandingServiceClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, DocumentUnderstandingServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document understanding service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.DocumentUnderstandingServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = DocumentUnderstandingServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def batch_process_documents(self, + request: document_understanding.BatchProcessDocumentsRequest = None, + *, + requests: Sequence[document_understanding.ProcessDocumentRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (:class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest`): + The request object. Request to batch process documents + as an asynchronous operation. The output is written to + Cloud Storage as JSON in the [Document] format. + requests (:class:`Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]`): + Required. Individual requests for + each document. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in + the LRO Operation after the operation is complete. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([requests]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_understanding.BatchProcessDocumentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if requests: + request.requests.extend(requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_understanding.BatchProcessDocumentsResponse, + metadata_type=document_understanding.OperationMetadata, + ) + + # Done; return the response. + return response + + async def process_document(self, + request: document_understanding.ProcessDocumentRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document.Document: + r"""Processes a single document. + + Args: + request (:class:`google.cloud.documentai_v1beta2.types.ProcessDocumentRequest`): + The request object. Request to process one document. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta2.types.Document: + Document represents the canonical + document resource in Document + Understanding AI. It is an interchange + format that provides insights into + documents and allows for collaboration + between users and Document Understanding + AI to iterate and optimize for quality. + + """ + # Create or coerce a protobuf request object. + request = document_understanding.ProcessDocumentRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentUnderstandingServiceAsyncClient", +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py new file mode 100644 index 00000000..7de0957b --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -0,0 +1,492 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from distutils import util +import os +import re +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.rpc import status_pb2 # type: ignore +from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import DocumentUnderstandingServiceGrpcTransport +from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport + + +class DocumentUnderstandingServiceClientMeta(type): + """Metaclass for the DocumentUnderstandingService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentUnderstandingServiceTransport]] + _transport_registry["grpc"] = DocumentUnderstandingServiceGrpcTransport + _transport_registry["grpc_asyncio"] = DocumentUnderstandingServiceGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[DocumentUnderstandingServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class DocumentUnderstandingServiceClient(metaclass=DocumentUnderstandingServiceClientMeta): + """Service to parse structured information from unstructured or + semi-structured documents using state-of-the-art Google AI such + as natural language, computer vision, and translation. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "us-documentai.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentUnderstandingServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentUnderstandingServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentUnderstandingServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentUnderstandingServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, DocumentUnderstandingServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document understanding service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, DocumentUnderstandingServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) + + client_cert_source_func = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + is_mtls = True + client_cert_source_func = client_options.client_cert_source + else: + is_mtls = mtls.has_default_client_cert_source() + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_mtls_env == "never": + api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, DocumentUnderstandingServiceTransport): + # transport is a DocumentUnderstandingServiceTransport instance. + if credentials or client_options.credentials_file: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + ) + + def batch_process_documents(self, + request: document_understanding.BatchProcessDocumentsRequest = None, + *, + requests: Sequence[document_understanding.ProcessDocumentRequest] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest): + The request object. Request to batch process documents + as an asynchronous operation. The output is written to + Cloud Storage as JSON in the [Document] format. + requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): + Required. Individual requests for + each document. + + This corresponds to the ``requests`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in + the LRO Operation after the operation is complete. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([requests]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_understanding.BatchProcessDocumentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_understanding.BatchProcessDocumentsRequest): + request = document_understanding.BatchProcessDocumentsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_understanding.BatchProcessDocumentsResponse, + metadata_type=document_understanding.OperationMetadata, + ) + + # Done; return the response. + return response + + def process_document(self, + request: document_understanding.ProcessDocumentRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document.Document: + r"""Processes a single document. + + Args: + request (google.cloud.documentai_v1beta2.types.ProcessDocumentRequest): + The request object. Request to process one document. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta2.types.Document: + Document represents the canonical + document resource in Document + Understanding AI. It is an interchange + format that provides insights into + documents and allows for collaboration + between users and Document Understanding + AI to iterate and optimize for quality. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a document_understanding.ProcessDocumentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_understanding.ProcessDocumentRequest): + request = document_understanding.ProcessDocumentRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.process_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentUnderstandingServiceClient", +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py new file mode 100644 index 00000000..07874536 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import DocumentUnderstandingServiceTransport +from .grpc import DocumentUnderstandingServiceGrpcTransport +from .grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentUnderstandingServiceTransport]] +_transport_registry['grpc'] = DocumentUnderstandingServiceGrpcTransport +_transport_registry['grpc_asyncio'] = DocumentUnderstandingServiceGrpcAsyncIOTransport + +__all__ = ( + 'DocumentUnderstandingServiceTransport', + 'DocumentUnderstandingServiceGrpcTransport', + 'DocumentUnderstandingServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py new file mode 100644 index 00000000..6c721e8f --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -0,0 +1,204 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version +import pkg_resources + +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-documentai', + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + + +class DocumentUnderstandingServiceTransport(abc.ABC): + """Abstract transport class for DocumentUnderstandingService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + ) + + DEFAULT_HOST: str = 'us-documentai.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + + # If the credentials is service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # TODO(busunkim): This method is in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-auth is increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.batch_process_documents: gapic_v1.method.wrap_method( + self.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + self.process_document: gapic_v1.method.wrap_method( + self.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + } + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def batch_process_documents(self) -> Callable[ + [document_understanding.BatchProcessDocumentsRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def process_document(self) -> Callable[ + [document_understanding.ProcessDocumentRequest], + Union[ + document.Document, + Awaitable[document.Document] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'DocumentUnderstandingServiceTransport', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py new file mode 100644 index 00000000..bea99a20 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -0,0 +1,301 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO + + +class DocumentUnderstandingServiceGrpcTransport(DocumentUnderstandingServiceTransport): + """gRPC backend transport for DocumentUnderstandingService. + + Service to parse structured information from unstructured or + semi-structured documents using state-of-the-art Google AI such + as natural language, computer vision, and translation. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'us-documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'us-documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def batch_process_documents(self) -> Callable[ + [document_understanding.BatchProcessDocumentsRequest], + operations_pb2.Operation]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessDocumentsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/BatchProcessDocuments', + request_serializer=document_understanding.BatchProcessDocumentsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def process_document(self) -> Callable[ + [document_understanding.ProcessDocumentRequest], + document.Document]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessDocumentRequest], + ~.Document]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/ProcessDocument', + request_serializer=document_understanding.ProcessDocumentRequest.serialize, + response_deserializer=document.Document.deserialize, + ) + return self._stubs['process_document'] + + +__all__ = ( + 'DocumentUnderstandingServiceGrpcTransport', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py new file mode 100644 index 00000000..8bcdc123 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -0,0 +1,305 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import DocumentUnderstandingServiceGrpcTransport + + +class DocumentUnderstandingServiceGrpcAsyncIOTransport(DocumentUnderstandingServiceTransport): + """gRPC AsyncIO backend transport for DocumentUnderstandingService. + + Service to parse structured information from unstructured or + semi-structured documents using state-of-the-art Google AI such + as natural language, computer vision, and translation. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'us-documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'us-documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def batch_process_documents(self) -> Callable[ + [document_understanding.BatchProcessDocumentsRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessDocumentsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/BatchProcessDocuments', + request_serializer=document_understanding.BatchProcessDocumentsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def process_document(self) -> Callable[ + [document_understanding.ProcessDocumentRequest], + Awaitable[document.Document]]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessDocumentRequest], + Awaitable[~.Document]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/ProcessDocument', + request_serializer=document_understanding.ProcessDocumentRequest.serialize, + response_deserializer=document.Document.deserialize, + ) + return self._stubs['process_document'] + + +__all__ = ( + 'DocumentUnderstandingServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py new file mode 100644 index 00000000..b36d125f --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .document import ( + Document, +) +from .document_understanding import ( + AutoMlParams, + BatchProcessDocumentsRequest, + BatchProcessDocumentsResponse, + EntityExtractionParams, + FormExtractionParams, + GcsDestination, + GcsSource, + InputConfig, + KeyValuePairHint, + OcrParams, + OperationMetadata, + OutputConfig, + ProcessDocumentRequest, + ProcessDocumentResponse, + TableBoundHint, + TableExtractionParams, +) +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Vertex, +) + +__all__ = ( + 'Document', + 'AutoMlParams', + 'BatchProcessDocumentsRequest', + 'BatchProcessDocumentsResponse', + 'EntityExtractionParams', + 'FormExtractionParams', + 'GcsDestination', + 'GcsSource', + 'InputConfig', + 'KeyValuePairHint', + 'OcrParams', + 'OperationMetadata', + 'OutputConfig', + 'ProcessDocumentRequest', + 'ProcessDocumentResponse', + 'TableBoundHint', + 'TableExtractionParams', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', +) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py new file mode 100644 index 00000000..cc67300a --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py @@ -0,0 +1,993 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1beta2.types import geometry +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta2', + manifest={ + 'Document', + }, +) + + +class Document(proto.Message): + r"""Document represents the canonical document resource in + Document Understanding AI. + It is an interchange format that provides insights into + documents and allows for collaboration between users and + Document Understanding AI to iterate and optimize for quality. + + Attributes: + uri (str): + Currently supports Google Cloud Storage URI of the form + ``gs://bucket_name/object_name``. Object versioning is not + supported. See `Google Cloud Storage Request + URIs `__ + for more info. + content (bytes): + Inline document content, represented as a stream of bytes. + Note: As with all ``bytes`` fields, protobuffers use a pure + binary representation, whereas JSON representations use + base64. + mime_type (str): + An IANA published MIME type (also referred to + as media type). For more information, see + https://www.iana.org/assignments/media- + types/media-types.xhtml. + text (str): + UTF-8 encoded text in reading order from the + document. + text_styles (Sequence[google.cloud.documentai_v1beta2.types.Document.Style]): + Styles for the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + pages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page]): + Visual page layout for the + [Document][google.cloud.documentai.v1beta2.Document]. + entities (Sequence[google.cloud.documentai_v1beta2.types.Document.Entity]): + A list of entities detected on + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + For document shards, entities in this list may cross shard + boundaries. + entity_relations (Sequence[google.cloud.documentai_v1beta2.types.Document.EntityRelation]): + Relationship among + [Document.entities][google.cloud.documentai.v1beta2.Document.entities]. + shard_info (google.cloud.documentai_v1beta2.types.Document.ShardInfo): + Information about the sharding if this + document is sharded part of a larger document. + If the document is not sharded, this message is + not specified. + labels (Sequence[google.cloud.documentai_v1beta2.types.Document.Label]): + [Label][google.cloud.documentai.v1beta2.Document.Label]s for + this document. + error (google.rpc.status_pb2.Status): + Any error that occurred while processing this + document. + """ + + class ShardInfo(proto.Message): + r"""For a large document, sharding may be performed to produce + several document shards. Each document shard contains this field + to detail which shard it is. + + Attributes: + shard_index (int): + The 0-based index of this shard. + shard_count (int): + Total number of shards. + text_offset (int): + The index of the first character in + [Document.text][google.cloud.documentai.v1beta2.Document.text] + in the overall document global text. + """ + + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) + + class Label(proto.Message): + r"""Label attaches schema information and/or other metadata to segments + within a [Document][google.cloud.documentai.v1beta2.Document]. + Multiple [Label][google.cloud.documentai.v1beta2.Document.Label]s on + a single field can denote either different labels, different + instances of the same label created at different times, or some + combination of both. + + Attributes: + automl_model (str): + Label is generated AutoML model. This field stores the full + resource name of the AutoML model. + + Format: + ``projects/{project-id}/locations/{location-id}/models/{model-id}`` + name (str): + Name of the label. + When the label is generated from AutoML Text + Classification model, this field represents the + name of the category. + confidence (float): + Confidence score between 0 and 1 for label + assignment. + """ + + automl_model = proto.Field( + proto.STRING, + number=2, + oneof='source', + ) + name = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=3, + ) + + class Style(proto.Message): + r"""Annotation for common text style attributes. This adheres to + CSS conventions as much as possible. + + Attributes: + text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): + Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + color (google.type.color_pb2.Color): + Text color. + background_color (google.type.color_pb2.Color): + Text background color. + font_weight (str): + Font weight. Possible values are normal, bold, bolder, and + lighter. https://www.w3schools.com/cssref/pr_font_weight.asp + text_style (str): + Text style. Possible values are normal, italic, and oblique. + https://www.w3schools.com/cssref/pr_font_font-style.asp + text_decoration (str): + Text decoration. Follows CSS standard. + https://www.w3schools.com/cssref/pr_text_text-decoration.asp + font_size (google.cloud.documentai_v1beta2.types.Document.Style.FontSize): + Font size. + """ + + class FontSize(proto.Message): + r"""Font size with unit. + Attributes: + size (float): + Font size for the text. + unit (str): + Unit for the font size. Follows CSS naming + (in, px, pt, etc.). + """ + + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, + ) + background_color = proto.Field( + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, + ) + font_size = proto.Field( + proto.MESSAGE, + number=7, + message='Document.Style.FontSize', + ) + + class Page(proto.Message): + r"""A page in a [Document][google.cloud.documentai.v1beta2.Document]. + Attributes: + page_number (int): + 1-based index for current + [Page][google.cloud.documentai.v1beta2.Document.Page] in a + parent [Document][google.cloud.documentai.v1beta2.Document]. + Useful when a page is taken out of a + [Document][google.cloud.documentai.v1beta2.Document] for + individual processing. + dimension (google.cloud.documentai_v1beta2.types.Document.Page.Dimension): + Physical dimension of the page. + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for the page. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + blocks (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Block]): + A list of visually detected text blocks on + the page. A block has a set of lines (collected + into paragraphs) that have a common line-spacing + and orientation. + paragraphs (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Paragraph]): + A list of visually detected text paragraphs + on the page. A collection of lines that a human + would perceive as a paragraph. + lines (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Line]): + A list of visually detected text lines on the + page. A collection of tokens that a human would + perceive as a line. + tokens (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Token]): + A list of visually detected tokens on the + page. + visual_elements (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.VisualElement]): + A list of detected non-text visual elements + e.g. checkbox, signature etc. on the page. + tables (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table]): + A list of visually detected tables on the + page. + form_fields (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.FormField]): + A list of visually detected form fields on + the page. + """ + + class Dimension(proto.Message): + r"""Dimension for the page. + Attributes: + width (float): + Page width. + height (float): + Page height. + unit (str): + Dimension unit. + """ + + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) + + class Layout(proto.Message): + r"""Visual element describing a layout unit on a page. + Attributes: + text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): + Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + confidence (float): + Confidence of the current + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + within context of the object this layout is for. e.g. + confidence can be for a single token, a table, a visual + element, etc. depending on context. Range [0, 1]. + bounding_poly (google.cloud.documentai_v1beta2.types.BoundingPoly): + The bounding polygon for the + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout]. + orientation (google.cloud.documentai_v1beta2.types.Document.Page.Layout.Orientation): + Detected orientation for the + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout]. + id (str): + Optional. This is the identifier used by referencing + [PageAnchor][google.cloud.documentai.v1beta2.Document.PageAnchor]s. + """ + class Orientation(proto.Enum): + r"""Detected human reading orientation.""" + ORIENTATION_UNSPECIFIED = 0 + PAGE_UP = 1 + PAGE_RIGHT = 2 + PAGE_DOWN = 3 + PAGE_LEFT = 4 + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + orientation = proto.Field( + proto.ENUM, + number=4, + enum='Document.Page.Layout.Orientation', + ) + id = proto.Field( + proto.STRING, + number=5, + ) + + class Block(proto.Message): + r"""A block has a set of lines (collected into paragraphs) that + have a common line-spacing and orientation. + + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [Block][google.cloud.documentai.v1beta2.Document.Page.Block]. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + + class Paragraph(proto.Message): + r"""A collection of lines that a human would perceive as a + paragraph. + + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [Paragraph][google.cloud.documentai.v1beta2.Document.Page.Paragraph]. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + + class Line(proto.Message): + r"""A collection of tokens that a human would perceive as a line. + Does not cross column boundaries, can be horizontal, vertical, + etc. + + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [Line][google.cloud.documentai.v1beta2.Document.Page.Line]. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + + class Token(proto.Message): + r"""A detected token. + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. + detected_break (google.cloud.documentai_v1beta2.types.Document.Page.Token.DetectedBreak): + Detected break at the end of a + [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + class DetectedBreak(proto.Message): + r"""Detected break at the end of a + [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. + + Attributes: + type_ (google.cloud.documentai_v1beta2.types.Document.Page.Token.DetectedBreak.Type): + Detected break type. + """ + class Type(proto.Enum): + r"""Enum to denote the type of break found.""" + TYPE_UNSPECIFIED = 0 + SPACE = 1 + WIDE_SPACE = 2 + HYPHEN = 3 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='Document.Page.Token.DetectedBreak.Type', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Token.DetectedBreak', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + + class VisualElement(proto.Message): + r"""Detected non-text visual elements e.g. checkbox, signature + etc. on the page. + + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement]. + type_ (str): + Type of the + [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement]. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + + class Table(proto.Message): + r"""A table representation similar to HTML table structure. + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [Table][google.cloud.documentai.v1beta2.Document.Page.Table]. + header_rows (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableRow]): + Header rows of the table. + body_rows (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableRow]): + Body rows of the table. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + class TableRow(proto.Message): + r"""A row of table cells. + Attributes: + cells (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableCell]): + Cells that make up this row. + """ + + cells = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.Page.Table.TableCell', + ) + + class TableCell(proto.Message): + r"""A cell representation inside the table. + Attributes: + layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for + [TableCell][google.cloud.documentai.v1beta2.Document.Page.Table.TableCell]. + row_span (int): + How many rows this cell spans. + col_span (int): + How many columns this cell spans. + detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + header_rows = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.Table.TableRow', + ) + body_rows = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.Table.TableRow', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + class FormField(proto.Message): + r"""A form field detected on the page. + Attributes: + field_name (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for the + [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] + name. e.g. ``Address``, ``Email``, ``Grand total``, + ``Phone number``, etc. + field_value (google.cloud.documentai_v1beta2.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] + for the + [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] + value. + name_detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages for name + together with confidence. + value_detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): + A list of detected languages for value + together with confidence. + value_type (str): + If the value is non-textual, this field represents the type. + Current valid values are: + + - blank (this indicates the field_value is normal text) + - "unfilled_checkbox" + - "filled_checkbox". + corrected_key_text (str): + An internal field, created for Labeling UI to + export key text. + corrected_value_text (str): + An internal field, created for Labeling UI to + export value text. + """ + + field_name = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + field_value = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Layout', + ) + name_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + value_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + value_type = proto.Field( + proto.STRING, + number=5, + ) + corrected_key_text = proto.Field( + proto.STRING, + number=6, + ) + corrected_value_text = proto.Field( + proto.STRING, + number=7, + ) + + 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 + more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + confidence (float): + Confidence of detected language. Range [0, 1]. + """ + + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + + page_number = proto.Field( + proto.INT32, + number=1, + ) + dimension = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Dimension', + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='Document.Page.Block', + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=6, + message='Document.Page.Paragraph', + ) + lines = proto.RepeatedField( + proto.MESSAGE, + number=7, + message='Document.Page.Line', + ) + tokens = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='Document.Page.Token', + ) + visual_elements = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Document.Page.VisualElement', + ) + tables = proto.RepeatedField( + proto.MESSAGE, + number=10, + message='Document.Page.Table', + ) + form_fields = proto.RepeatedField( + proto.MESSAGE, + number=11, + message='Document.Page.FormField', + ) + + class Entity(proto.Message): + r"""A phrase in the text that is a known entity type, such as a + person, an organization, or location. + + Attributes: + text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): + Provenance of the entity. Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + type_ (str): + Entity type from a schema e.g. ``Address``. + mention_text (str): + Text value in the document e.g. ``1600 Amphitheatre Pkwy``. + mention_id (str): + Deprecated. Use ``id`` field instead. + confidence (float): + Optional. Confidence of detected Schema entity. Range [0, + 1]. + page_anchor (google.cloud.documentai_v1beta2.types.Document.PageAnchor): + Optional. Represents the provenance of this + entity wrt. the location on the page where it + was found. + id (str): + Optional. Canonical id. This will be a unique + value in the entity list for this document. + bounding_poly_for_demo_frontend (google.cloud.documentai_v1beta2.types.BoundingPoly): + Optional. Temporary field to store the + bounding poly for short-term POCs. Used by the + frontend only. Do not use before you talk to + ybo@ and lukasr@. + """ + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + page_anchor = proto.Field( + proto.MESSAGE, + number=6, + message='Document.PageAnchor', + ) + id = proto.Field( + proto.STRING, + number=7, + ) + bounding_poly_for_demo_frontend = proto.Field( + proto.MESSAGE, + number=8, + message=geometry.BoundingPoly, + ) + + class EntityRelation(proto.Message): + r"""Relationship between + [Entities][google.cloud.documentai.v1beta2.Document.Entity]. + + Attributes: + subject_id (str): + Subject entity id. + object_id (str): + Object entity id. + relation (str): + Relationship description. + """ + + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) + + class TextAnchor(proto.Message): + r"""Text reference indexing into the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + + Attributes: + text_segments (Sequence[google.cloud.documentai_v1beta2.types.Document.TextAnchor.TextSegment]): + The text segments from the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + """ + + class TextSegment(proto.Message): + r"""A text segment in the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. The + indices may be out of bounds which indicate that the text extends + into another document shard for large sharded documents. See + [ShardInfo.text_offset][google.cloud.documentai.v1beta2.Document.ShardInfo.text_offset] + + Attributes: + start_index (int): + [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] + start UTF-8 char index in the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + end_index (int): + [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] + half open end UTF-8 char index in the + [Document.text][google.cloud.documentai.v1beta2.Document.text]. + """ + + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) + + text_segments = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.TextAnchor.TextSegment', + ) + + class PageAnchor(proto.Message): + r"""Referencing elements in + [Document.pages][google.cloud.documentai.v1beta2.Document.pages]. + + Attributes: + page_refs (Sequence[google.cloud.documentai_v1beta2.types.Document.PageAnchor.PageRef]): + One or more references to visual page + elements + """ + + class PageRef(proto.Message): + r"""Represents a weak reference to a page element within a + document. + + Attributes: + page (int): + Required. Index into the + [Document.pages][google.cloud.documentai.v1beta2.Document.pages] + element + layout_type (google.cloud.documentai_v1beta2.types.Document.PageAnchor.PageRef.LayoutType): + Optional. The type of the layout element that + is being referenced. If not specified the whole + page is assumed to be referenced. + layout_id (str): + Optional. The + [Page.Layout.id][google.cloud.documentai.v1beta2.Document.Page.Layout.id] + on the page that this element references. If + [LayoutRef.type][] is specified this id must also be + specified. + """ + class LayoutType(proto.Enum): + r"""The type of layout that is being referenced.""" + LAYOUT_TYPE_UNSPECIFIED = 0 + BLOCK = 1 + PARAGRAPH = 2 + LINE = 3 + TOKEN = 4 + VISUAL_ELEMENT = 5 + TABLE = 6 + FORM_FIELD = 7 + + page = proto.Field( + proto.INT64, + number=1, + ) + layout_type = proto.Field( + proto.ENUM, + number=2, + enum='Document.PageAnchor.PageRef.LayoutType', + ) + layout_id = proto.Field( + proto.STRING, + number=3, + ) + + page_refs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.PageAnchor.PageRef', + ) + + uri = proto.Field( + proto.STRING, + number=1, + oneof='source', + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof='source', + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) + entity_relations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + labels = proto.RepeatedField( + proto.MESSAGE, + number=11, + message=Label, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py new file mode 100644 index 00000000..1b97579c --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py @@ -0,0 +1,546 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1beta2.types import geometry +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta2', + manifest={ + 'BatchProcessDocumentsRequest', + 'ProcessDocumentRequest', + 'BatchProcessDocumentsResponse', + 'ProcessDocumentResponse', + 'OcrParams', + 'TableExtractionParams', + 'TableBoundHint', + 'FormExtractionParams', + 'KeyValuePairHint', + 'EntityExtractionParams', + 'AutoMlParams', + 'InputConfig', + 'OutputConfig', + 'GcsSource', + 'GcsDestination', + 'OperationMetadata', + }, +) + + +class BatchProcessDocumentsRequest(proto.Message): + r"""Request to batch process documents as an asynchronous operation. The + output is written to Cloud Storage as JSON in the [Document] format. + + Attributes: + requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): + Required. Individual requests for each + document. + parent (str): + Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no location is specified, a region will be chosen + automatically. + """ + + requests = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ProcessDocumentRequest', + ) + parent = proto.Field( + proto.STRING, + number=2, + ) + + +class ProcessDocumentRequest(proto.Message): + r"""Request to process one document. + Attributes: + parent (str): + Target project and location to make a call. + + Format: ``projects/{project-id}/locations/{location-id}``. + + If no location is specified, a region will be chosen + automatically. This field is only populated when used in + ProcessDocument method. + input_config (google.cloud.documentai_v1beta2.types.InputConfig): + Required. Information about the input file. + output_config (google.cloud.documentai_v1beta2.types.OutputConfig): + Optional. The desired output location. This + field is only needed in + BatchProcessDocumentsRequest. + document_type (str): + Specifies a known document type for deeper + structure detection. Valid values are currently + "general" and "invoice". If not provided, + "general"\ is used as default. If any other + value is given, the request is rejected. + table_extraction_params (google.cloud.documentai_v1beta2.types.TableExtractionParams): + Controls table extraction behavior. If not + specified, the system will decide reasonable + defaults. + form_extraction_params (google.cloud.documentai_v1beta2.types.FormExtractionParams): + Controls form extraction behavior. If not + specified, the system will decide reasonable + defaults. + entity_extraction_params (google.cloud.documentai_v1beta2.types.EntityExtractionParams): + Controls entity extraction behavior. If not + specified, the system will decide reasonable + defaults. + ocr_params (google.cloud.documentai_v1beta2.types.OcrParams): + Controls OCR behavior. If not specified, the + system will decide reasonable defaults. + automl_params (google.cloud.documentai_v1beta2.types.AutoMlParams): + Controls AutoML model prediction behavior. + AutoMlParams cannot be used together with other + Params. + """ + + parent = proto.Field( + proto.STRING, + number=9, + ) + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message='OutputConfig', + ) + document_type = proto.Field( + proto.STRING, + number=3, + ) + table_extraction_params = proto.Field( + proto.MESSAGE, + number=4, + message='TableExtractionParams', + ) + form_extraction_params = proto.Field( + proto.MESSAGE, + number=5, + message='FormExtractionParams', + ) + entity_extraction_params = proto.Field( + proto.MESSAGE, + number=6, + message='EntityExtractionParams', + ) + ocr_params = proto.Field( + proto.MESSAGE, + number=7, + message='OcrParams', + ) + automl_params = proto.Field( + proto.MESSAGE, + number=8, + message='AutoMlParams', + ) + + +class BatchProcessDocumentsResponse(proto.Message): + r"""Response to an batch document processing request. This is + returned in the LRO Operation after the operation is complete. + + Attributes: + responses (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentResponse]): + Responses for each individual document. + """ + + responses = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='ProcessDocumentResponse', + ) + + +class ProcessDocumentResponse(proto.Message): + r"""Response to a single document processing request. + Attributes: + input_config (google.cloud.documentai_v1beta2.types.InputConfig): + Information about the input file. This is the + same as the corresponding input config in the + request. + output_config (google.cloud.documentai_v1beta2.types.OutputConfig): + The output location of the parsed responses. The responses + are written to this location as JSON-serialized ``Document`` + objects. + """ + + input_config = proto.Field( + proto.MESSAGE, + number=1, + message='InputConfig', + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message='OutputConfig', + ) + + +class OcrParams(proto.Message): + r"""Parameters to control Optical Character Recognition (OCR) + behavior. + + Attributes: + language_hints (Sequence[str]): + List of languages to use for OCR. In most cases, an empty + value yields the best results since it enables automatic + language detection. For languages based on the Latin + alphabet, setting ``language_hints`` is not needed. In rare + cases, when the language of the text in the image is known, + setting a hint will help get better results (although it + will be a significant hindrance if the hint is wrong). + Document processing returns an error if one or more of the + specified languages is not one of the supported languages. + """ + + language_hints = proto.RepeatedField( + proto.STRING, + number=1, + ) + + +class TableExtractionParams(proto.Message): + r"""Parameters to control table extraction behavior. + Attributes: + enabled (bool): + Whether to enable table extraction. + table_bound_hints (Sequence[google.cloud.documentai_v1beta2.types.TableBoundHint]): + Optional. Table bounding box hints that can + be provided to complex cases which our algorithm + cannot locate the table(s) in. + header_hints (Sequence[str]): + Optional. Table header hints. The extraction + will bias towards producing these terms as table + headers, which may improve accuracy. + model_version (str): + Model version of the table extraction system. + Default is "builtin/stable". Specify + "builtin/latest" for the latest model. + """ + + enabled = proto.Field( + proto.BOOL, + number=1, + ) + table_bound_hints = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='TableBoundHint', + ) + header_hints = proto.RepeatedField( + proto.STRING, + number=3, + ) + model_version = proto.Field( + proto.STRING, + number=4, + ) + + +class TableBoundHint(proto.Message): + r"""A hint for a table bounding box on the page for table + parsing. + + Attributes: + page_number (int): + Optional. Page number for multi-paged inputs + this hint applies to. If not provided, this hint + will apply to all pages by default. This value + is 1-based. + bounding_box (google.cloud.documentai_v1beta2.types.BoundingPoly): + Bounding box hint for a table on this page. The coordinates + must be normalized to [0,1] and the bounding box must be an + axis-aligned rectangle. + """ + + page_number = proto.Field( + proto.INT32, + number=1, + ) + bounding_box = proto.Field( + proto.MESSAGE, + number=2, + message=geometry.BoundingPoly, + ) + + +class FormExtractionParams(proto.Message): + r"""Parameters to control form extraction behavior. + Attributes: + enabled (bool): + Whether to enable form extraction. + key_value_pair_hints (Sequence[google.cloud.documentai_v1beta2.types.KeyValuePairHint]): + User can provide pairs of (key text, value type) to improve + the parsing result. + + For example, if a document has a field called "Date" that + holds a date value and a field called "Amount" that may hold + either a currency value (e.g., "$500.00") or a simple number + value (e.g., "20"), you could use the following hints: [ + {"key": "Date", value_types: [ "DATE"]}, {"key": "Amount", + "value_types": [ "PRICE", "NUMBER" ]} ] + + If the value type is unknown, but you want to provide hints + for the keys, you can leave the value_types field blank. + e.g. {"key": "Date", "value_types": []} + model_version (str): + Model version of the form extraction system. Default is + "builtin/stable". Specify "builtin/latest" for the latest + model. For custom form models, specify: + “custom/{model_name}". Model name format is + "bucket_name/path/to/modeldir" corresponding to + "gs://bucket_name/path/to/modeldir" where annotated examples + are stored. + """ + + enabled = proto.Field( + proto.BOOL, + number=1, + ) + key_value_pair_hints = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='KeyValuePairHint', + ) + model_version = proto.Field( + proto.STRING, + number=3, + ) + + +class KeyValuePairHint(proto.Message): + r"""User-provided hint for key value pair. + Attributes: + key (str): + The key text for the hint. + value_types (Sequence[str]): + Type of the value. This is case-insensitive, and could be + one of: ADDRESS, LOCATION, ORGANIZATION, PERSON, + PHONE_NUMBER, ID, NUMBER, EMAIL, PRICE, TERMS, DATE, NAME. + Types not in this list will be ignored. + """ + + key = proto.Field( + proto.STRING, + number=1, + ) + value_types = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class EntityExtractionParams(proto.Message): + r"""Parameters to control entity extraction behavior. + Attributes: + enabled (bool): + Whether to enable entity extraction. + model_version (str): + Model version of the entity extraction. + Default is "builtin/stable". Specify + "builtin/latest" for the latest model. + """ + + enabled = proto.Field( + proto.BOOL, + number=1, + ) + model_version = proto.Field( + proto.STRING, + number=2, + ) + + +class AutoMlParams(proto.Message): + r"""Parameters to control AutoML model prediction behavior. + Attributes: + model (str): + Resource name of the AutoML model. + + Format: + ``projects/{project-id}/locations/{location-id}/models/{model-id}``. + """ + + model = proto.Field( + proto.STRING, + number=1, + ) + + +class InputConfig(proto.Message): + r"""The desired input location and metadata. + Attributes: + gcs_source (google.cloud.documentai_v1beta2.types.GcsSource): + The Google Cloud Storage location to read the + input from. This must be a single file. + contents (bytes): + Content in bytes, represented as a stream of bytes. Note: As + with all ``bytes`` fields, proto buffer messages use a pure + binary representation, whereas JSON representations use + base64. + + This field only works for synchronous ProcessDocument + method. + mime_type (str): + Required. Mimetype of the input. Current supported mimetypes + are application/pdf, image/tiff, and image/gif. In addition, + application/json type is supported for requests with + [ProcessDocumentRequest.automl_params][google.cloud.documentai.v1beta2.ProcessDocumentRequest.automl_params] + field set. The JSON file needs to be in + [Document][google.cloud.documentai.v1beta2.Document] format. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='GcsSource', + ) + contents = proto.Field( + proto.BYTES, + number=3, + oneof='source', + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class OutputConfig(proto.Message): + r"""The desired output location and metadata. + Attributes: + gcs_destination (google.cloud.documentai_v1beta2.types.GcsDestination): + The Google Cloud Storage location to write + the output to. + pages_per_shard (int): + The max number of pages to include into each output Document + shard JSON on Google Cloud Storage. + + The valid range is [1, 100]. If not specified, the default + value is 20. + + For example, for one pdf file with 100 pages, 100 parsed + pages will be produced. If ``pages_per_shard`` = 20, then 5 + Document shard JSON files each containing 20 parsed pages + will be written under the prefix + [OutputConfig.gcs_destination.uri][] and suffix + pages-x-to-y.json where x and y are 1-indexed page numbers. + + Example GCS outputs with 157 pages and pages_per_shard = 50: + + pages-001-to-050.json pages-051-to-100.json + pages-101-to-150.json pages-151-to-157.json + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + oneof='destination', + message='GcsDestination', + ) + pages_per_shard = proto.Field( + proto.INT32, + number=2, + ) + + +class GcsSource(proto.Message): + r"""The Google Cloud Storage location where the input file will + be read from. + + Attributes: + uri (str): + + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class GcsDestination(proto.Message): + r"""The Google Cloud Storage location where the output file will + be written to. + + Attributes: + uri (str): + + """ + + uri = proto.Field( + proto.STRING, + number=1, + ) + + +class OperationMetadata(proto.Message): + r"""Contains metadata for the BatchProcessDocuments operation. + Attributes: + state (google.cloud.documentai_v1beta2.types.OperationMetadata.State): + The state of the current batch processing. + state_message (str): + A message providing more details about the + current state of processing. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + """ + class State(proto.Enum): + r"""""" + STATE_UNSPECIFIED = 0 + ACCEPTED = 1 + WAITING = 2 + RUNNING = 3 + SUCCEEDED = 4 + CANCELLED = 5 + FAILED = 6 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py new file mode 100644 index 00000000..4bf1ff65 --- /dev/null +++ b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta2', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + }, +) + + +class Vertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the vertex coordinates are in the same scale as the + original image. + + Attributes: + x (int): + X coordinate. + y (int): + Y coordinate. + """ + + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) + + +class NormalizedVertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the normalized vertex coordinates are relative to the + original image and range from 0 to 1. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate. + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + + +class BoundingPoly(proto.Message): + r"""A bounding polygon for the detected image annotation. + Attributes: + vertices (Sequence[google.cloud.documentai_v1beta2.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.documentai_v1beta2.types.NormalizedVertex]): + The bounding polygon normalized vertices. + """ + + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Vertex', + ) + normalized_vertices = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='NormalizedVertex', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/mypy.ini b/owl-bot-staging/v1beta2/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1beta2/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1beta2/noxfile.py b/owl-bot-staging/v1beta2/noxfile.py new file mode 100644 index 00000000..3b318e44 --- /dev/null +++ b/owl-bot-staging/v1beta2/noxfile.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", +] + +@nox.session(python=['3.6', '3.7', '3.8', '3.9']) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/documentai_v1beta2/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python='3.7') +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=['3.6', '3.7']) +def mypy(session): + """Run the type checker.""" + session.install('mypy', 'types-pkg_resources') + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python='3.6') +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx<3.0.0", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py b/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py new file mode 100644 index 00000000..22080e57 --- /dev/null +++ b/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py @@ -0,0 +1,177 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class documentaiCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'batch_process_documents': ('requests', 'parent', ), + 'process_document': ('input_config', 'parent', 'output_config', 'document_type', 'table_extraction_params', 'form_extraction_params', 'entity_extraction_params', 'ocr_params', 'automl_params', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: not a.keyword.value in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=documentaiCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the documentai client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1beta2/setup.py b/owl-bot-staging/v1beta2/setup.py new file mode 100644 index 00000000..90b5b3cf --- /dev/null +++ b/owl-bot-staging/v1beta2/setup.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os +import setuptools # type: ignore + +version = '0.1.0' + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, 'README.rst') +with io.open(readme_filename, encoding='utf-8') as readme_file: + readme = readme_file.read() + +setuptools.setup( + name='google-cloud-documentai', + version=version, + long_description=readme, + packages=setuptools.PEP420PackageFinder.find(), + namespace_packages=('google', 'google.cloud'), + platforms='Posix; MacOS X; Windows', + include_package_data=True, + install_requires=( + 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', + 'libcst >= 0.2.5', + 'proto-plus >= 1.15.0', + 'packaging >= 14.3', ), + python_requires='>=3.6', + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1beta2/tests/__init__.py b/owl-bot-staging/v1beta2/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta2/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta2/tests/unit/__init__.py b/owl-bot-staging/v1beta2/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta2/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py b/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py new file mode 100644 index 00000000..a6d25a67 --- /dev/null +++ b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -0,0 +1,1342 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import mock +import packaging.version + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.documentai_v1beta2.services.document_understanding_service import DocumentUnderstandingServiceAsyncClient +from google.cloud.documentai_v1beta2.services.document_understanding_service import DocumentUnderstandingServiceClient +from google.cloud.documentai_v1beta2.services.document_understanding_service import transports +from google.cloud.documentai_v1beta2.services.document_understanding_service.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.documentai_v1beta2.types import document +from google.cloud.documentai_v1beta2.types import document_understanding +from google.cloud.documentai_v1beta2.types import geometry +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.rpc import status_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(None) is None + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + DocumentUnderstandingServiceClient, + DocumentUnderstandingServiceAsyncClient, +]) +def test_document_understanding_service_client_from_service_account_info(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'us-documentai.googleapis.com:443' + + +@pytest.mark.parametrize("client_class", [ + DocumentUnderstandingServiceClient, + DocumentUnderstandingServiceAsyncClient, +]) +def test_document_understanding_service_client_service_account_always_use_jwt(client_class): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), + (transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_understanding_service_client_service_account_always_use_jwt_true(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + +@pytest.mark.parametrize("client_class", [ + DocumentUnderstandingServiceClient, + DocumentUnderstandingServiceAsyncClient, +]) +def test_document_understanding_service_client_from_service_account_file(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'us-documentai.googleapis.com:443' + + +def test_document_understanding_service_client_get_transport_class(): + transport = DocumentUnderstandingServiceClient.get_transport_class() + available_transports = [ + transports.DocumentUnderstandingServiceGrpcTransport, + ] + assert transport in available_transports + + transport = DocumentUnderstandingServiceClient.get_transport_class("grpc") + assert transport == transports.DocumentUnderstandingServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), + (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(DocumentUnderstandingServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceClient)) +@mock.patch.object(DocumentUnderstandingServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceAsyncClient)) +def test_document_understanding_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(DocumentUnderstandingServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(DocumentUnderstandingServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc", "true"), + (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc", "false"), + (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(DocumentUnderstandingServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceClient)) +@mock.patch.object(DocumentUnderstandingServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_document_understanding_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), + (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_understanding_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), + (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_understanding_service_client_client_options_credentials_file(client_class, transport_class, transport_name): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_document_understanding_service_client_client_options_from_dict(): + with mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = DocumentUnderstandingServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_batch_process_documents(transport: str = 'grpc', request_type=document_understanding.BatchProcessDocumentsRequest): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.BatchProcessDocumentsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_batch_process_documents_from_dict(): + test_batch_process_documents(request_type=dict) + + +def test_batch_process_documents_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + client.batch_process_documents() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.BatchProcessDocumentsRequest() + + +@pytest.mark.asyncio +async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_understanding.BatchProcessDocumentsRequest): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.BatchProcessDocumentsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_batch_process_documents_async_from_dict(): + await test_batch_process_documents_async(request_type=dict) + + +def test_batch_process_documents_field_headers(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_understanding.BatchProcessDocumentsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_batch_process_documents_field_headers_async(): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_understanding.BatchProcessDocumentsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +def test_batch_process_documents_flattened(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_process_documents( + requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].requests == [document_understanding.ProcessDocumentRequest(parent='parent_value')] + + +def test_batch_process_documents_flattened_error(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_process_documents( + document_understanding.BatchProcessDocumentsRequest(), + requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], + ) + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_async(): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_process_documents( + requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].requests == [document_understanding.ProcessDocumentRequest(parent='parent_value')] + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_error_async(): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_process_documents( + document_understanding.BatchProcessDocumentsRequest(), + requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], + ) + + +def test_process_document(transport: str = 'grpc', request_type=document_understanding.ProcessDocumentRequest): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document.Document( + mime_type='mime_type_value', + text='text_value', + uri='uri_value', + ) + response = client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.ProcessDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document.Document) + assert response.mime_type == 'mime_type_value' + assert response.text == 'text_value' + + +def test_process_document_from_dict(): + test_process_document(request_type=dict) + + +def test_process_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + client.process_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.ProcessDocumentRequest() + + +@pytest.mark.asyncio +async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_understanding.ProcessDocumentRequest): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document.Document( + mime_type='mime_type_value', + text='text_value', + )) + response = await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_understanding.ProcessDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document.Document) + assert response.mime_type == 'mime_type_value' + assert response.text == 'text_value' + + +@pytest.mark.asyncio +async def test_process_document_async_from_dict(): + await test_process_document_async(request_type=dict) + + +def test_process_document_field_headers(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_understanding.ProcessDocumentRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = document.Document() + client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_process_document_field_headers_async(): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_understanding.ProcessDocumentRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document.Document()) + await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentUnderstandingServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentUnderstandingServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = DocumentUnderstandingServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.DocumentUnderstandingServiceGrpcTransport, + transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DocumentUnderstandingServiceGrpcTransport, + ) + +def test_document_understanding_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.DocumentUnderstandingServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_document_understanding_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.DocumentUnderstandingServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'batch_process_documents', + 'process_document', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + +@requires_google_auth_gte_1_25_0 +def test_document_understanding_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentUnderstandingServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_understanding_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentUnderstandingServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + ), + quota_project_id="octopus", + ) + + +def test_document_understanding_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentUnderstandingServiceTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_document_understanding_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentUnderstandingServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_understanding_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentUnderstandingServiceClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentUnderstandingServiceGrpcTransport, + transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_document_understanding_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentUnderstandingServiceGrpcTransport, + transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_document_understanding_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") + adc.assert_called_once_with(scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DocumentUnderstandingServiceGrpcTransport, grpc_helpers), + (transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_document_understanding_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "us-documentai.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + scopes=["1", "2"], + default_host="us-documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) +def test_document_understanding_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + + +def test_document_understanding_service_host_no_port(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='us-documentai.googleapis.com'), + ) + assert client.transport._host == 'us-documentai.googleapis.com:443' + + +def test_document_understanding_service_host_with_port(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='us-documentai.googleapis.com:8000'), + ) + assert client.transport._host == 'us-documentai.googleapis.com:8000' + +def test_document_understanding_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentUnderstandingServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_document_understanding_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) +def test_document_understanding_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) +def test_document_understanding_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_document_understanding_service_grpc_lro_client(): + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_document_understanding_service_grpc_lro_async_client(): + client = DocumentUnderstandingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc_asyncio', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = DocumentUnderstandingServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = DocumentUnderstandingServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentUnderstandingServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format(folder=folder, ) + actual = DocumentUnderstandingServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = DocumentUnderstandingServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentUnderstandingServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format(organization=organization, ) + actual = DocumentUnderstandingServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = DocumentUnderstandingServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentUnderstandingServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format(project=project, ) + actual = DocumentUnderstandingServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = DocumentUnderstandingServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentUnderstandingServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = DocumentUnderstandingServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = DocumentUnderstandingServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentUnderstandingServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.DocumentUnderstandingServiceTransport, '_prep_wrapped_messages') as prep: + client = DocumentUnderstandingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.DocumentUnderstandingServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = DocumentUnderstandingServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) diff --git a/owl-bot-staging/v1beta3/.coveragerc b/owl-bot-staging/v1beta3/.coveragerc new file mode 100644 index 00000000..ef619357 --- /dev/null +++ b/owl-bot-staging/v1beta3/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/documentai/__init__.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ + # Ignore pkg_resources exceptions. + # This is added at the module level as a safeguard for if someone + # generates the code and tries to run it without pip installing. This + # makes it virtually impossible to test properly. + except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1beta3/MANIFEST.in b/owl-bot-staging/v1beta3/MANIFEST.in new file mode 100644 index 00000000..af799d71 --- /dev/null +++ b/owl-bot-staging/v1beta3/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/documentai *.py +recursive-include google/cloud/documentai_v1beta3 *.py diff --git a/owl-bot-staging/v1beta3/README.rst b/owl-bot-staging/v1beta3/README.rst new file mode 100644 index 00000000..484a3c1c --- /dev/null +++ b/owl-bot-staging/v1beta3/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Documentai API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Documentai API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1beta3/docs/conf.py b/owl-bot-staging/v1beta3/docs/conf.py new file mode 100644 index 00000000..0788579e --- /dev/null +++ b/owl-bot-staging/v1beta3/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-documentai documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "1.6.3" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = u"google-cloud-documentai" +copyright = u"2020, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-documentai-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + master_doc, + "google-cloud-documentai.tex", + u"google-cloud-documentai Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + master_doc, + "google-cloud-documentai", + u"Google Cloud Documentai Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "google-cloud-documentai", + u"google-cloud-documentai Documentation", + author, + "google-cloud-documentai", + "GAPIC library for Google Cloud Documentai API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst new file mode 100644 index 00000000..4d8d5f9e --- /dev/null +++ b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst @@ -0,0 +1,10 @@ +DocumentProcessorService +------------------------------------------ + +.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service + :members: + :inherited-members: + +.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst new file mode 100644 index 00000000..d19a944b --- /dev/null +++ b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Documentai v1beta3 API +================================================ +.. toctree:: + :maxdepth: 2 + + document_processor_service diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst new file mode 100644 index 00000000..7e22aabc --- /dev/null +++ b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Documentai v1beta3 API +============================================= + +.. automodule:: google.cloud.documentai_v1beta3.types + :members: + :undoc-members: + :show-inheritance: diff --git a/owl-bot-staging/v1beta3/docs/index.rst b/owl-bot-staging/v1beta3/docs/index.rst new file mode 100644 index 00000000..f4d3a84d --- /dev/null +++ b/owl-bot-staging/v1beta3/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + documentai_v1beta3/services + documentai_v1beta3/types diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py new file mode 100644 index 00000000..36cee4ca --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.cloud.documentai_v1beta3.services.document_processor_service.client import DocumentProcessorServiceClient +from google.cloud.documentai_v1beta3.services.document_processor_service.async_client import DocumentProcessorServiceAsyncClient + +from google.cloud.documentai_v1beta3.types.document import Document +from google.cloud.documentai_v1beta3.types.document_io import BatchDocumentsInputConfig +from google.cloud.documentai_v1beta3.types.document_io import DocumentOutputConfig +from google.cloud.documentai_v1beta3.types.document_io import GcsDocument +from google.cloud.documentai_v1beta3.types.document_io import GcsDocuments +from google.cloud.documentai_v1beta3.types.document_io import GcsPrefix +from google.cloud.documentai_v1beta3.types.document_io import RawDocument +from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessMetadata +from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import CreateProcessorRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import DeleteProcessorMetadata +from google.cloud.documentai_v1beta3.types.document_processor_service import DeleteProcessorRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorMetadata +from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorMetadata +from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import FetchProcessorTypesRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import FetchProcessorTypesResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import HumanReviewStatus +from google.cloud.documentai_v1beta3.types.document_processor_service import ListProcessorsRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import ListProcessorsResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import ProcessRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import ProcessResponse +from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentOperationMetadata +from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentRequest +from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentResponse +from google.cloud.documentai_v1beta3.types.geometry import BoundingPoly +from google.cloud.documentai_v1beta3.types.geometry import NormalizedVertex +from google.cloud.documentai_v1beta3.types.geometry import Vertex +from google.cloud.documentai_v1beta3.types.operation_metadata import CommonOperationMetadata +from google.cloud.documentai_v1beta3.types.processor import Processor +from google.cloud.documentai_v1beta3.types.processor_type import ProcessorType + +__all__ = ('DocumentProcessorServiceClient', + 'DocumentProcessorServiceAsyncClient', + 'Document', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'RawDocument', + 'BatchProcessMetadata', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'CreateProcessorRequest', + 'DeleteProcessorMetadata', + 'DeleteProcessorRequest', + 'DisableProcessorMetadata', + 'DisableProcessorRequest', + 'DisableProcessorResponse', + 'EnableProcessorMetadata', + 'EnableProcessorRequest', + 'EnableProcessorResponse', + 'FetchProcessorTypesRequest', + 'FetchProcessorTypesResponse', + 'HumanReviewStatus', + 'ListProcessorsRequest', + 'ListProcessorsResponse', + 'ProcessRequest', + 'ProcessResponse', + 'ReviewDocumentOperationMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', + 'CommonOperationMetadata', + 'Processor', + 'ProcessorType', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed b/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py new file mode 100644 index 00000000..1dc95835 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from .services.document_processor_service import DocumentProcessorServiceClient +from .services.document_processor_service import DocumentProcessorServiceAsyncClient + +from .types.document import Document +from .types.document_io import BatchDocumentsInputConfig +from .types.document_io import DocumentOutputConfig +from .types.document_io import GcsDocument +from .types.document_io import GcsDocuments +from .types.document_io import GcsPrefix +from .types.document_io import RawDocument +from .types.document_processor_service import BatchProcessMetadata +from .types.document_processor_service import BatchProcessRequest +from .types.document_processor_service import BatchProcessResponse +from .types.document_processor_service import CreateProcessorRequest +from .types.document_processor_service import DeleteProcessorMetadata +from .types.document_processor_service import DeleteProcessorRequest +from .types.document_processor_service import DisableProcessorMetadata +from .types.document_processor_service import DisableProcessorRequest +from .types.document_processor_service import DisableProcessorResponse +from .types.document_processor_service import EnableProcessorMetadata +from .types.document_processor_service import EnableProcessorRequest +from .types.document_processor_service import EnableProcessorResponse +from .types.document_processor_service import FetchProcessorTypesRequest +from .types.document_processor_service import FetchProcessorTypesResponse +from .types.document_processor_service import HumanReviewStatus +from .types.document_processor_service import ListProcessorsRequest +from .types.document_processor_service import ListProcessorsResponse +from .types.document_processor_service import ProcessRequest +from .types.document_processor_service import ProcessResponse +from .types.document_processor_service import ReviewDocumentOperationMetadata +from .types.document_processor_service import ReviewDocumentRequest +from .types.document_processor_service import ReviewDocumentResponse +from .types.geometry import BoundingPoly +from .types.geometry import NormalizedVertex +from .types.geometry import Vertex +from .types.operation_metadata import CommonOperationMetadata +from .types.processor import Processor +from .types.processor_type import ProcessorType + +__all__ = ( + 'DocumentProcessorServiceAsyncClient', +'BatchDocumentsInputConfig', +'BatchProcessMetadata', +'BatchProcessRequest', +'BatchProcessResponse', +'BoundingPoly', +'CommonOperationMetadata', +'CreateProcessorRequest', +'DeleteProcessorMetadata', +'DeleteProcessorRequest', +'DisableProcessorMetadata', +'DisableProcessorRequest', +'DisableProcessorResponse', +'Document', +'DocumentOutputConfig', +'DocumentProcessorServiceClient', +'EnableProcessorMetadata', +'EnableProcessorRequest', +'EnableProcessorResponse', +'FetchProcessorTypesRequest', +'FetchProcessorTypesResponse', +'GcsDocument', +'GcsDocuments', +'GcsPrefix', +'HumanReviewStatus', +'ListProcessorsRequest', +'ListProcessorsResponse', +'NormalizedVertex', +'ProcessRequest', +'ProcessResponse', +'Processor', +'ProcessorType', +'RawDocument', +'ReviewDocumentOperationMetadata', +'ReviewDocumentRequest', +'ReviewDocumentResponse', +'Vertex', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json new file mode 100644 index 00000000..1e2c3550 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json @@ -0,0 +1,113 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.documentai_v1beta3", + "protoPackage": "google.cloud.documentai.v1beta3", + "schema": "1.0", + "services": { + "DocumentProcessorService": { + "clients": { + "grpc": { + "libraryClient": "DocumentProcessorServiceClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "CreateProcessor": { + "methods": [ + "create_processor" + ] + }, + "DeleteProcessor": { + "methods": [ + "delete_processor" + ] + }, + "DisableProcessor": { + "methods": [ + "disable_processor" + ] + }, + "EnableProcessor": { + "methods": [ + "enable_processor" + ] + }, + "FetchProcessorTypes": { + "methods": [ + "fetch_processor_types" + ] + }, + "ListProcessors": { + "methods": [ + "list_processors" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + }, + "ReviewDocument": { + "methods": [ + "review_document" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DocumentProcessorServiceAsyncClient", + "rpcs": { + "BatchProcessDocuments": { + "methods": [ + "batch_process_documents" + ] + }, + "CreateProcessor": { + "methods": [ + "create_processor" + ] + }, + "DeleteProcessor": { + "methods": [ + "delete_processor" + ] + }, + "DisableProcessor": { + "methods": [ + "disable_processor" + ] + }, + "EnableProcessor": { + "methods": [ + "enable_processor" + ] + }, + "FetchProcessorTypes": { + "methods": [ + "fetch_processor_types" + ] + }, + "ListProcessors": { + "methods": [ + "list_processors" + ] + }, + "ProcessDocument": { + "methods": [ + "process_document" + ] + }, + "ReviewDocument": { + "methods": [ + "review_document" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed new file mode 100644 index 00000000..81b45001 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py new file mode 100644 index 00000000..4de65971 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py new file mode 100644 index 00000000..7217ec7c --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import DocumentProcessorServiceClient +from .async_client import DocumentProcessorServiceAsyncClient + +__all__ = ( + 'DocumentProcessorServiceClient', + 'DocumentProcessorServiceAsyncClient', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py new file mode 100644 index 00000000..9e2c7029 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py @@ -0,0 +1,939 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +import pkg_resources + +import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1beta3.services.document_processor_service import pagers +from google.cloud.documentai_v1beta3.types import document +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.types import processor_type +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport +from .client import DocumentProcessorServiceClient + + +class DocumentProcessorServiceAsyncClient: + """Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + """ + + _client: DocumentProcessorServiceClient + + DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + + human_review_config_path = staticmethod(DocumentProcessorServiceClient.human_review_config_path) + parse_human_review_config_path = staticmethod(DocumentProcessorServiceClient.parse_human_review_config_path) + processor_path = staticmethod(DocumentProcessorServiceClient.processor_path) + parse_processor_path = staticmethod(DocumentProcessorServiceClient.parse_processor_path) + processor_type_path = staticmethod(DocumentProcessorServiceClient.processor_type_path) + parse_processor_type_path = staticmethod(DocumentProcessorServiceClient.parse_processor_type_path) + common_billing_account_path = staticmethod(DocumentProcessorServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(DocumentProcessorServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(DocumentProcessorServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(DocumentProcessorServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(DocumentProcessorServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(DocumentProcessorServiceClient.parse_common_organization_path) + common_project_path = staticmethod(DocumentProcessorServiceClient.common_project_path) + parse_common_project_path = staticmethod(DocumentProcessorServiceClient.parse_common_project_path) + common_location_path = staticmethod(DocumentProcessorServiceClient.common_location_path) + parse_common_location_path = staticmethod(DocumentProcessorServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceAsyncClient: The constructed client. + """ + return DocumentProcessorServiceClient.from_service_account_info.__func__(DocumentProcessorServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceAsyncClient: The constructed client. + """ + return DocumentProcessorServiceClient.from_service_account_file.__func__(DocumentProcessorServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentProcessorServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentProcessorServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient)) + + def __init__(self, *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, DocumentProcessorServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document processor service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.DocumentProcessorServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = DocumentProcessorServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def process_document(self, + request: document_processor_service.ProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.ProcessResponse: + r"""Processes a single document. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.ProcessRequest`): + The request object. Request message for the process + document method. + name (:class:`str`): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.ProcessResponse: + Response message for the process + document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.ProcessRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_process_documents(self, + request: document_processor_service.BatchProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.BatchProcessRequest`): + The request object. Request message for batch process + document method. + name (:class:`str`): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.BatchProcessResponse` + Response message for batch process document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.BatchProcessRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.BatchProcessResponse, + metadata_type=document_processor_service.BatchProcessMetadata, + ) + + # Done; return the response. + return response + + async def fetch_processor_types(self, + request: document_processor_service.FetchProcessorTypesRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.FetchProcessorTypesResponse: + r"""Fetches processor types. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest`): + The request object. Request message for fetch processor + types. + parent (:class:`str`): + Required. The project of processor + type to list. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse: + Response message for fetch processor + types. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.FetchProcessorTypesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.fetch_processor_types, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_processors(self, + request: document_processor_service.ListProcessorsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProcessorsAsyncPager: + r"""Lists all processors which belong to this project. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.ListProcessorsRequest`): + The request object. Request message for list all + processors belongs to a project. + parent (:class:`str`): + Required. The parent (project and + location) which owns this collection of + Processors. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsAsyncPager: + Response message for list processors. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.ListProcessorsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_processors, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProcessorsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_processor(self, + request: document_processor_service.CreateProcessorRequest = None, + *, + parent: str = None, + processor: gcd_processor.Processor = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcd_processor.Processor: + r"""Creates a processor from the type processor that the + user chose. The processor will be at "ENABLED" state by + default after its creation. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.CreateProcessorRequest`): + The request object. Request message for create a + processor. Notice this request is sent to a regionalized + backend service, and if the processor type is not + available on that region, the creation will fail. + parent (:class:`str`): + Required. The parent (project and + location) under which to create the + processor. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + processor (:class:`google.cloud.documentai_v1beta3.types.Processor`): + Required. The processor to be created, requires + [processor_type] and [display_name] to be set. Also, the + processor is under CMEK if CMEK fields are set. + + This corresponds to the ``processor`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.Processor: + The first-class citizen for + DocumentAI. Each processor defines how + to extract structural information from a + document. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, processor]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.CreateProcessorRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if processor is not None: + request.processor = processor + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_processor, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_processor(self, + request: document_processor_service.DeleteProcessorRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes the processor, unloads all deployed model + artifacts if it was enabled and then deletes all + artifacts associated with this processor. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.DeleteProcessorRequest`): + The request object. Request message for the delete + processor method. + name (:class:`str`): + Required. The processor resource name + to be deleted. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.DeleteProcessorRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_processor, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=document_processor_service.DeleteProcessorMetadata, + ) + + # Done; return the response. + return response + + async def enable_processor(self, + request: document_processor_service.EnableProcessorRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Enables a processor + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.EnableProcessorRequest`): + The request object. Request message for the enable + processor method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.EnableProcessorResponse` + Response message for the enable processor method. + + """ + # Create or coerce a protobuf request object. + request = document_processor_service.EnableProcessorRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.enable_processor, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.EnableProcessorResponse, + metadata_type=document_processor_service.EnableProcessorMetadata, + ) + + # Done; return the response. + return response + + async def disable_processor(self, + request: document_processor_service.DisableProcessorRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Disables a processor + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.DisableProcessorRequest`): + The request object. Request message for the disable + processor method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.DisableProcessorResponse` + Response message for the disable processor method. + + """ + # Create or coerce a protobuf request object. + request = document_processor_service.DisableProcessorRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.disable_processor, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.DisableProcessorResponse, + metadata_type=document_processor_service.DisableProcessorMetadata, + ) + + # Done; return the response. + return response + + async def review_document(self, + request: document_processor_service.ReviewDocumentRequest = None, + *, + human_review_config: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Send a document for Human Review. The input document + should be processed by the specified processor. + + Args: + request (:class:`google.cloud.documentai_v1beta3.types.ReviewDocumentRequest`): + The request object. Request message for review document + method. Next Id: 6. + human_review_config (:class:`str`): + Required. The resource name of the + HumanReviewConfig that the document will + be reviewed with. + + This corresponds to the ``human_review_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.ReviewDocumentResponse` + Response message for review document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([human_review_config]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = document_processor_service.ReviewDocumentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if human_review_config is not None: + request.human_review_config = human_review_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.review_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("human_review_config", request.human_review_config), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + document_processor_service.ReviewDocumentResponse, + metadata_type=document_processor_service.ReviewDocumentOperationMetadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentProcessorServiceAsyncClient", +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py new file mode 100644 index 00000000..e72e0ebf --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -0,0 +1,1125 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from distutils import util +import os +import re +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.documentai_v1beta3.services.document_processor_service import pagers +from google.cloud.documentai_v1beta3.types import document +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.types import processor_type +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import DocumentProcessorServiceGrpcTransport +from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + + +class DocumentProcessorServiceClientMeta(type): + """Metaclass for the DocumentProcessorService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] + _transport_registry["grpc"] = DocumentProcessorServiceGrpcTransport + _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport + + def get_transport_class(cls, + label: str = None, + ) -> Type[DocumentProcessorServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMeta): + """Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "documentai.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DocumentProcessorServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DocumentProcessorServiceTransport: + """Returns the transport used by the client instance. + + Returns: + DocumentProcessorServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def human_review_config_path(project: str,location: str,processor: str,) -> str: + """Returns a fully-qualified human_review_config string.""" + return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) + + @staticmethod + def parse_human_review_config_path(path: str) -> Dict[str,str]: + """Parses a human_review_config path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)/humanReviewConfig$", path) + return m.groupdict() if m else {} + + @staticmethod + def processor_path(project: str,location: str,processor: str,) -> str: + """Returns a fully-qualified processor string.""" + return "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) + + @staticmethod + def parse_processor_path(path: str) -> Dict[str,str]: + """Parses a processor path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def processor_type_path(project: str,location: str,processor_type: str,) -> str: + """Returns a fully-qualified processor_type string.""" + return "projects/{project}/locations/{location}/processorTypes/{processor_type}".format(project=project, location=location, processor_type=processor_type, ) + + @staticmethod + def parse_processor_type_path(path: str) -> Dict[str,str]: + """Parses a processor_type path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processorTypes/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, DocumentProcessorServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the document processor service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, DocumentProcessorServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) + + client_cert_source_func = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + is_mtls = True + client_cert_source_func = client_options.client_cert_source + else: + is_mtls = mtls.has_default_client_cert_source() + if is_mtls: + client_cert_source_func = mtls.default_client_cert_source() + else: + client_cert_source_func = None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_mtls_env == "never": + api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + if is_mtls: + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = self.DEFAULT_ENDPOINT + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, DocumentProcessorServiceTransport): + # transport is a DocumentProcessorServiceTransport instance. + if credentials or client_options.credentials_file: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + ) + + def process_document(self, + request: document_processor_service.ProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.ProcessResponse: + r"""Processes a single document. + + Args: + request (google.cloud.documentai_v1beta3.types.ProcessRequest): + The request object. Request message for the process + document method. + name (str): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.ProcessResponse: + Response message for the process + document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.ProcessRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.ProcessRequest): + request = document_processor_service.ProcessRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.process_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_process_documents(self, + request: document_processor_service.BatchProcessRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Args: + request (google.cloud.documentai_v1beta3.types.BatchProcessRequest): + The request object. Request message for batch process + document method. + name (str): + Required. The processor resource + name. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.BatchProcessResponse` + Response message for batch process document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.BatchProcessRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.BatchProcessRequest): + request = document_processor_service.BatchProcessRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.BatchProcessResponse, + metadata_type=document_processor_service.BatchProcessMetadata, + ) + + # Done; return the response. + return response + + def fetch_processor_types(self, + request: document_processor_service.FetchProcessorTypesRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> document_processor_service.FetchProcessorTypesResponse: + r"""Fetches processor types. + + Args: + request (google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest): + The request object. Request message for fetch processor + types. + parent (str): + Required. The project of processor + type to list. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse: + Response message for fetch processor + types. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.FetchProcessorTypesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.FetchProcessorTypesRequest): + request = document_processor_service.FetchProcessorTypesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.fetch_processor_types] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_processors(self, + request: document_processor_service.ListProcessorsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListProcessorsPager: + r"""Lists all processors which belong to this project. + + Args: + request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): + The request object. Request message for list all + processors belongs to a project. + parent (str): + Required. The parent (project and + location) which owns this collection of + Processors. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsPager: + Response message for list processors. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.ListProcessorsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.ListProcessorsRequest): + request = document_processor_service.ListProcessorsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_processors] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProcessorsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_processor(self, + request: document_processor_service.CreateProcessorRequest = None, + *, + parent: str = None, + processor: gcd_processor.Processor = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcd_processor.Processor: + r"""Creates a processor from the type processor that the + user chose. The processor will be at "ENABLED" state by + default after its creation. + + Args: + request (google.cloud.documentai_v1beta3.types.CreateProcessorRequest): + The request object. Request message for create a + processor. Notice this request is sent to a regionalized + backend service, and if the processor type is not + available on that region, the creation will fail. + parent (str): + Required. The parent (project and + location) under which to create the + processor. Format: + projects/{project}/locations/{location} + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + processor (google.cloud.documentai_v1beta3.types.Processor): + Required. The processor to be created, requires + [processor_type] and [display_name] to be set. Also, the + processor is under CMEK if CMEK fields are set. + + This corresponds to the ``processor`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.documentai_v1beta3.types.Processor: + The first-class citizen for + DocumentAI. Each processor defines how + to extract structural information from a + document. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, processor]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.CreateProcessorRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.CreateProcessorRequest): + request = document_processor_service.CreateProcessorRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if processor is not None: + request.processor = processor + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_processor] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_processor(self, + request: document_processor_service.DeleteProcessorRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Deletes the processor, unloads all deployed model + artifacts if it was enabled and then deletes all + artifacts associated with this processor. + + Args: + request (google.cloud.documentai_v1beta3.types.DeleteProcessorRequest): + The request object. Request message for the delete + processor method. + name (str): + Required. The processor resource name + to be deleted. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.DeleteProcessorRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.DeleteProcessorRequest): + request = document_processor_service.DeleteProcessorRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_processor] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=document_processor_service.DeleteProcessorMetadata, + ) + + # Done; return the response. + return response + + def enable_processor(self, + request: document_processor_service.EnableProcessorRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Enables a processor + + Args: + request (google.cloud.documentai_v1beta3.types.EnableProcessorRequest): + The request object. Request message for the enable + processor method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.EnableProcessorResponse` + Response message for the enable processor method. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.EnableProcessorRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.EnableProcessorRequest): + request = document_processor_service.EnableProcessorRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.enable_processor] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.EnableProcessorResponse, + metadata_type=document_processor_service.EnableProcessorMetadata, + ) + + # Done; return the response. + return response + + def disable_processor(self, + request: document_processor_service.DisableProcessorRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Disables a processor + + Args: + request (google.cloud.documentai_v1beta3.types.DisableProcessorRequest): + The request object. Request message for the disable + processor method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.DisableProcessorResponse` + Response message for the disable processor method. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.DisableProcessorRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.DisableProcessorRequest): + request = document_processor_service.DisableProcessorRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.disable_processor] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.DisableProcessorResponse, + metadata_type=document_processor_service.DisableProcessorMetadata, + ) + + # Done; return the response. + return response + + def review_document(self, + request: document_processor_service.ReviewDocumentRequest = None, + *, + human_review_config: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Send a document for Human Review. The input document + should be processed by the specified processor. + + Args: + request (google.cloud.documentai_v1beta3.types.ReviewDocumentRequest): + The request object. Request message for review document + method. Next Id: 6. + human_review_config (str): + Required. The resource name of the + HumanReviewConfig that the document will + be reviewed with. + + This corresponds to the ``human_review_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.documentai_v1beta3.types.ReviewDocumentResponse` + Response message for review document method. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([human_review_config]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a document_processor_service.ReviewDocumentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, document_processor_service.ReviewDocumentRequest): + request = document_processor_service.ReviewDocumentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if human_review_config is not None: + request.human_review_config = human_review_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.review_document] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("human_review_config", request.human_review_config), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + document_processor_service.ReviewDocumentResponse, + metadata_type=document_processor_service.ReviewDocumentOperationMetadata, + ) + + # Done; return the response. + return response + + + + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-documentai", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ( + "DocumentProcessorServiceClient", +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py new file mode 100644 index 00000000..aedf0ca5 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple, Optional + +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor + + +class ListProcessorsPager: + """A pager for iterating through ``list_processors`` requests. + + This class thinly wraps an initial + :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``processors`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProcessors`` requests and continue to iterate + through the ``processors`` field on the + corresponding responses. + + All the usual :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., document_processor_service.ListProcessorsResponse], + request: document_processor_service.ListProcessorsRequest, + response: document_processor_service.ListProcessorsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): + The initial request object. + response (google.cloud.documentai_v1beta3.types.ListProcessorsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = document_processor_service.ListProcessorsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterable[document_processor_service.ListProcessorsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterable[processor.Processor]: + for page in self.pages: + yield from page.processors + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProcessorsAsyncPager: + """A pager for iterating through ``list_processors`` requests. + + This class thinly wraps an initial + :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``processors`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProcessors`` requests and continue to iterate + through the ``processors`` field on the + corresponding responses. + + All the usual :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[document_processor_service.ListProcessorsResponse]], + request: document_processor_service.ListProcessorsRequest, + response: document_processor_service.ListProcessorsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): + The initial request object. + response (google.cloud.documentai_v1beta3.types.ListProcessorsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = document_processor_service.ListProcessorsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterable[document_processor_service.ListProcessorsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterable[processor.Processor]: + async def async_generator(): + async for page in self.pages: + for response in page.processors: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py new file mode 100644 index 00000000..38f9c440 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import DocumentProcessorServiceTransport +from .grpc import DocumentProcessorServiceGrpcTransport +from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] +_transport_registry['grpc'] = DocumentProcessorServiceGrpcTransport +_transport_registry['grpc_asyncio'] = DocumentProcessorServiceGrpcAsyncIOTransport + +__all__ = ( + 'DocumentProcessorServiceTransport', + 'DocumentProcessorServiceGrpcTransport', + 'DocumentProcessorServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py new file mode 100644 index 00000000..dc126fc5 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -0,0 +1,309 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version +import pkg_resources + +import google.auth # type: ignore +import google.api_core # type: ignore +from google.api_core import exceptions as core_exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + 'google-cloud-documentai', + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + + +class DocumentProcessorServiceTransport(abc.ABC): + """Abstract transport class for DocumentProcessorService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + ) + + DEFAULT_HOST: str = 'documentai.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + + # If the credentials is service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # TODO(busunkim): This method is in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-auth is increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.process_document: gapic_v1.method.wrap_method( + self.process_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + self.batch_process_documents: gapic_v1.method.wrap_method( + self.batch_process_documents, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + self.fetch_processor_types: gapic_v1.method.wrap_method( + self.fetch_processor_types, + default_timeout=None, + client_info=client_info, + ), + self.list_processors: gapic_v1.method.wrap_method( + self.list_processors, + default_timeout=None, + client_info=client_info, + ), + self.create_processor: gapic_v1.method.wrap_method( + self.create_processor, + default_timeout=None, + client_info=client_info, + ), + self.delete_processor: gapic_v1.method.wrap_method( + self.delete_processor, + default_timeout=None, + client_info=client_info, + ), + self.enable_processor: gapic_v1.method.wrap_method( + self.enable_processor, + default_timeout=None, + client_info=client_info, + ), + self.disable_processor: gapic_v1.method.wrap_method( + self.disable_processor, + default_timeout=None, + client_info=client_info, + ), + self.review_document: gapic_v1.method.wrap_method( + self.review_document, + default_retry=retries.Retry( +initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=120.0, + ), + default_timeout=120.0, + client_info=client_info, + ), + } + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + Union[ + document_processor_service.ProcessResponse, + Awaitable[document_processor_service.ProcessResponse] + ]]: + raise NotImplementedError() + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def fetch_processor_types(self) -> Callable[ + [document_processor_service.FetchProcessorTypesRequest], + Union[ + document_processor_service.FetchProcessorTypesResponse, + Awaitable[document_processor_service.FetchProcessorTypesResponse] + ]]: + raise NotImplementedError() + + @property + def list_processors(self) -> Callable[ + [document_processor_service.ListProcessorsRequest], + Union[ + document_processor_service.ListProcessorsResponse, + Awaitable[document_processor_service.ListProcessorsResponse] + ]]: + raise NotImplementedError() + + @property + def create_processor(self) -> Callable[ + [document_processor_service.CreateProcessorRequest], + Union[ + gcd_processor.Processor, + Awaitable[gcd_processor.Processor] + ]]: + raise NotImplementedError() + + @property + def delete_processor(self) -> Callable[ + [document_processor_service.DeleteProcessorRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def enable_processor(self) -> Callable[ + [document_processor_service.EnableProcessorRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def disable_processor(self) -> Callable[ + [document_processor_service.DisableProcessorRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + +__all__ = ( + 'DocumentProcessorServiceTransport', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py new file mode 100644 index 00000000..05d45a4b --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -0,0 +1,490 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO + + +class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): + """gRPC backend transport for DocumentProcessorService. + + Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + document_processor_service.ProcessResponse]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessRequest], + ~.ProcessResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ProcessDocument', + request_serializer=document_processor_service.ProcessRequest.serialize, + response_deserializer=document_processor_service.ProcessResponse.deserialize, + ) + return self._stubs['process_document'] + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + operations_pb2.Operation]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/BatchProcessDocuments', + request_serializer=document_processor_service.BatchProcessRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def fetch_processor_types(self) -> Callable[ + [document_processor_service.FetchProcessorTypesRequest], + document_processor_service.FetchProcessorTypesResponse]: + r"""Return a callable for the fetch processor types method over gRPC. + + Fetches processor types. + + Returns: + Callable[[~.FetchProcessorTypesRequest], + ~.FetchProcessorTypesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'fetch_processor_types' not in self._stubs: + self._stubs['fetch_processor_types'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/FetchProcessorTypes', + request_serializer=document_processor_service.FetchProcessorTypesRequest.serialize, + response_deserializer=document_processor_service.FetchProcessorTypesResponse.deserialize, + ) + return self._stubs['fetch_processor_types'] + + @property + def list_processors(self) -> Callable[ + [document_processor_service.ListProcessorsRequest], + document_processor_service.ListProcessorsResponse]: + r"""Return a callable for the list processors method over gRPC. + + Lists all processors which belong to this project. + + Returns: + Callable[[~.ListProcessorsRequest], + ~.ListProcessorsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_processors' not in self._stubs: + self._stubs['list_processors'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ListProcessors', + request_serializer=document_processor_service.ListProcessorsRequest.serialize, + response_deserializer=document_processor_service.ListProcessorsResponse.deserialize, + ) + return self._stubs['list_processors'] + + @property + def create_processor(self) -> Callable[ + [document_processor_service.CreateProcessorRequest], + gcd_processor.Processor]: + r"""Return a callable for the create processor method over gRPC. + + Creates a processor from the type processor that the + user chose. The processor will be at "ENABLED" state by + default after its creation. + + Returns: + Callable[[~.CreateProcessorRequest], + ~.Processor]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_processor' not in self._stubs: + self._stubs['create_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/CreateProcessor', + request_serializer=document_processor_service.CreateProcessorRequest.serialize, + response_deserializer=gcd_processor.Processor.deserialize, + ) + return self._stubs['create_processor'] + + @property + def delete_processor(self) -> Callable[ + [document_processor_service.DeleteProcessorRequest], + operations_pb2.Operation]: + r"""Return a callable for the delete processor method over gRPC. + + Deletes the processor, unloads all deployed model + artifacts if it was enabled and then deletes all + artifacts associated with this processor. + + Returns: + Callable[[~.DeleteProcessorRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_processor' not in self._stubs: + self._stubs['delete_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/DeleteProcessor', + request_serializer=document_processor_service.DeleteProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['delete_processor'] + + @property + def enable_processor(self) -> Callable[ + [document_processor_service.EnableProcessorRequest], + operations_pb2.Operation]: + r"""Return a callable for the enable processor method over gRPC. + + Enables a processor + + Returns: + Callable[[~.EnableProcessorRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'enable_processor' not in self._stubs: + self._stubs['enable_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/EnableProcessor', + request_serializer=document_processor_service.EnableProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['enable_processor'] + + @property + def disable_processor(self) -> Callable[ + [document_processor_service.DisableProcessorRequest], + operations_pb2.Operation]: + r"""Return a callable for the disable processor method over gRPC. + + Disables a processor + + Returns: + Callable[[~.DisableProcessorRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'disable_processor' not in self._stubs: + self._stubs['disable_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/DisableProcessor', + request_serializer=document_processor_service.DisableProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['disable_processor'] + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + operations_pb2.Operation]: + r"""Return a callable for the review document method over gRPC. + + Send a document for Human Review. The input document + should be processed by the specified processor. + + Returns: + Callable[[~.ReviewDocumentRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'review_document' not in self._stubs: + self._stubs['review_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ReviewDocument', + request_serializer=document_processor_service.ReviewDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['review_document'] + + +__all__ = ( + 'DocumentProcessorServiceGrpcTransport', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py new file mode 100644 index 00000000..47040964 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -0,0 +1,494 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import operations_v1 # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.longrunning import operations_pb2 # type: ignore +from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import DocumentProcessorServiceGrpcTransport + + +class DocumentProcessorServiceGrpcAsyncIOTransport(DocumentProcessorServiceTransport): + """gRPC AsyncIO backend transport for DocumentProcessorService. + + Service to call Cloud DocumentAI to process documents + according to the processor's definition. Processors are built + using state-of-the-art Google AI such as natural language, + computer vision, and translation to extract structured + information from unstructured or semi-structured documents. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'documentai.googleapis.com', + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or applicatin default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + credentials=self._credentials, + credentials_file=credentials_file, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Sanity check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def process_document(self) -> Callable[ + [document_processor_service.ProcessRequest], + Awaitable[document_processor_service.ProcessResponse]]: + r"""Return a callable for the process document method over gRPC. + + Processes a single document. + + Returns: + Callable[[~.ProcessRequest], + Awaitable[~.ProcessResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'process_document' not in self._stubs: + self._stubs['process_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ProcessDocument', + request_serializer=document_processor_service.ProcessRequest.serialize, + response_deserializer=document_processor_service.ProcessResponse.deserialize, + ) + return self._stubs['process_document'] + + @property + def batch_process_documents(self) -> Callable[ + [document_processor_service.BatchProcessRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the batch process documents method over gRPC. + + LRO endpoint to batch process many documents. The output is + written to Cloud Storage as JSON in the [Document] format. + + Returns: + Callable[[~.BatchProcessRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_process_documents' not in self._stubs: + self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/BatchProcessDocuments', + request_serializer=document_processor_service.BatchProcessRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['batch_process_documents'] + + @property + def fetch_processor_types(self) -> Callable[ + [document_processor_service.FetchProcessorTypesRequest], + Awaitable[document_processor_service.FetchProcessorTypesResponse]]: + r"""Return a callable for the fetch processor types method over gRPC. + + Fetches processor types. + + Returns: + Callable[[~.FetchProcessorTypesRequest], + Awaitable[~.FetchProcessorTypesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'fetch_processor_types' not in self._stubs: + self._stubs['fetch_processor_types'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/FetchProcessorTypes', + request_serializer=document_processor_service.FetchProcessorTypesRequest.serialize, + response_deserializer=document_processor_service.FetchProcessorTypesResponse.deserialize, + ) + return self._stubs['fetch_processor_types'] + + @property + def list_processors(self) -> Callable[ + [document_processor_service.ListProcessorsRequest], + Awaitable[document_processor_service.ListProcessorsResponse]]: + r"""Return a callable for the list processors method over gRPC. + + Lists all processors which belong to this project. + + Returns: + Callable[[~.ListProcessorsRequest], + Awaitable[~.ListProcessorsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_processors' not in self._stubs: + self._stubs['list_processors'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ListProcessors', + request_serializer=document_processor_service.ListProcessorsRequest.serialize, + response_deserializer=document_processor_service.ListProcessorsResponse.deserialize, + ) + return self._stubs['list_processors'] + + @property + def create_processor(self) -> Callable[ + [document_processor_service.CreateProcessorRequest], + Awaitable[gcd_processor.Processor]]: + r"""Return a callable for the create processor method over gRPC. + + Creates a processor from the type processor that the + user chose. The processor will be at "ENABLED" state by + default after its creation. + + Returns: + Callable[[~.CreateProcessorRequest], + Awaitable[~.Processor]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_processor' not in self._stubs: + self._stubs['create_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/CreateProcessor', + request_serializer=document_processor_service.CreateProcessorRequest.serialize, + response_deserializer=gcd_processor.Processor.deserialize, + ) + return self._stubs['create_processor'] + + @property + def delete_processor(self) -> Callable[ + [document_processor_service.DeleteProcessorRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the delete processor method over gRPC. + + Deletes the processor, unloads all deployed model + artifacts if it was enabled and then deletes all + artifacts associated with this processor. + + Returns: + Callable[[~.DeleteProcessorRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_processor' not in self._stubs: + self._stubs['delete_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/DeleteProcessor', + request_serializer=document_processor_service.DeleteProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['delete_processor'] + + @property + def enable_processor(self) -> Callable[ + [document_processor_service.EnableProcessorRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the enable processor method over gRPC. + + Enables a processor + + Returns: + Callable[[~.EnableProcessorRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'enable_processor' not in self._stubs: + self._stubs['enable_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/EnableProcessor', + request_serializer=document_processor_service.EnableProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['enable_processor'] + + @property + def disable_processor(self) -> Callable[ + [document_processor_service.DisableProcessorRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the disable processor method over gRPC. + + Disables a processor + + Returns: + Callable[[~.DisableProcessorRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'disable_processor' not in self._stubs: + self._stubs['disable_processor'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/DisableProcessor', + request_serializer=document_processor_service.DisableProcessorRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['disable_processor'] + + @property + def review_document(self) -> Callable[ + [document_processor_service.ReviewDocumentRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the review document method over gRPC. + + Send a document for Human Review. The input document + should be processed by the specified processor. + + Returns: + Callable[[~.ReviewDocumentRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'review_document' not in self._stubs: + self._stubs['review_document'] = self.grpc_channel.unary_unary( + '/google.cloud.documentai.v1beta3.DocumentProcessorService/ReviewDocument', + request_serializer=document_processor_service.ReviewDocumentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['review_document'] + + +__all__ = ( + 'DocumentProcessorServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py new file mode 100644 index 00000000..4e9a90e4 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .document import ( + Document, +) +from .document_io import ( + BatchDocumentsInputConfig, + DocumentOutputConfig, + GcsDocument, + GcsDocuments, + GcsPrefix, + RawDocument, +) +from .document_processor_service import ( + BatchProcessMetadata, + BatchProcessRequest, + BatchProcessResponse, + CreateProcessorRequest, + DeleteProcessorMetadata, + DeleteProcessorRequest, + DisableProcessorMetadata, + DisableProcessorRequest, + DisableProcessorResponse, + EnableProcessorMetadata, + EnableProcessorRequest, + EnableProcessorResponse, + FetchProcessorTypesRequest, + FetchProcessorTypesResponse, + HumanReviewStatus, + ListProcessorsRequest, + ListProcessorsResponse, + ProcessRequest, + ProcessResponse, + ReviewDocumentOperationMetadata, + ReviewDocumentRequest, + ReviewDocumentResponse, +) +from .geometry import ( + BoundingPoly, + NormalizedVertex, + Vertex, +) +from .operation_metadata import ( + CommonOperationMetadata, +) +from .processor import ( + Processor, +) +from .processor_type import ( + ProcessorType, +) + +__all__ = ( + 'Document', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'RawDocument', + 'BatchProcessMetadata', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'CreateProcessorRequest', + 'DeleteProcessorMetadata', + 'DeleteProcessorRequest', + 'DisableProcessorMetadata', + 'DisableProcessorRequest', + 'DisableProcessorResponse', + 'EnableProcessorMetadata', + 'EnableProcessorRequest', + 'EnableProcessorResponse', + 'FetchProcessorTypesRequest', + 'FetchProcessorTypesResponse', + 'HumanReviewStatus', + 'ListProcessorsRequest', + 'ListProcessorsResponse', + 'ProcessRequest', + 'ProcessResponse', + 'ReviewDocumentOperationMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'BoundingPoly', + 'NormalizedVertex', + 'Vertex', + 'CommonOperationMetadata', + 'Processor', + 'ProcessorType', +) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py new file mode 100644 index 00000000..62f69bfc --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py @@ -0,0 +1,1373 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1beta3.types import geometry +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore +from google.type import date_pb2 # type: ignore +from google.type import datetime_pb2 # type: ignore +from google.type import money_pb2 # type: ignore +from google.type import postal_address_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'Document', + }, +) + + +class Document(proto.Message): + r"""Document represents the canonical document resource in + Document Understanding AI. + It is an interchange format that provides insights into + documents and allows for collaboration between users and + Document Understanding AI to iterate and optimize for quality. + + Attributes: + uri (str): + Optional. Currently supports Google Cloud Storage URI of the + form ``gs://bucket_name/object_name``. Object versioning is + not supported. See `Google Cloud Storage Request + URIs `__ + for more info. + content (bytes): + Optional. Inline document content, represented as a stream + of bytes. Note: As with all ``bytes`` fields, protobuffers + use a pure binary representation, whereas JSON + representations use base64. + mime_type (str): + An IANA published MIME type (also referred to + as media type). For more information, see + https://www.iana.org/assignments/media- + types/media-types.xhtml. + text (str): + Optional. UTF-8 encoded text in reading order + from the document. + text_styles (Sequence[google.cloud.documentai_v1beta3.types.Document.Style]): + Styles for the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + pages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page]): + Visual page layout for the + [Document][google.cloud.documentai.v1beta3.Document]. + entities (Sequence[google.cloud.documentai_v1beta3.types.Document.Entity]): + A list of entities detected on + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + For document shards, entities in this list may cross shard + boundaries. + entity_relations (Sequence[google.cloud.documentai_v1beta3.types.Document.EntityRelation]): + Relationship among + [Document.entities][google.cloud.documentai.v1beta3.Document.entities]. + text_changes (Sequence[google.cloud.documentai_v1beta3.types.Document.TextChange]): + A list of text corrections made to [Document.text]. This is + usually used for annotating corrections to OCR mistakes. + Text changes for a given revision may not overlap with each + other. + shard_info (google.cloud.documentai_v1beta3.types.Document.ShardInfo): + Information about the sharding if this + document is sharded part of a larger document. + If the document is not sharded, this message is + not specified. + error (google.rpc.status_pb2.Status): + Any error that occurred while processing this + document. + revisions (Sequence[google.cloud.documentai_v1beta3.types.Document.Revision]): + Revision history of this document. + """ + + class ShardInfo(proto.Message): + r"""For a large document, sharding may be performed to produce + several document shards. Each document shard contains this field + to detail which shard it is. + + Attributes: + shard_index (int): + The 0-based index of this shard. + shard_count (int): + Total number of shards. + text_offset (int): + The index of the first character in + [Document.text][google.cloud.documentai.v1beta3.Document.text] + in the overall document global text. + """ + + shard_index = proto.Field( + proto.INT64, + number=1, + ) + shard_count = proto.Field( + proto.INT64, + number=2, + ) + text_offset = proto.Field( + proto.INT64, + number=3, + ) + + class Style(proto.Message): + r"""Annotation for common text style attributes. This adheres to + CSS conventions as much as possible. + + Attributes: + text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): + Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + color (google.type.color_pb2.Color): + Text color. + background_color (google.type.color_pb2.Color): + Text background color. + font_weight (str): + Font weight. Possible values are normal, bold, bolder, and + lighter. https://www.w3schools.com/cssref/pr_font_weight.asp + text_style (str): + Text style. Possible values are normal, italic, and oblique. + https://www.w3schools.com/cssref/pr_font_font-style.asp + text_decoration (str): + Text decoration. Follows CSS standard. + https://www.w3schools.com/cssref/pr_text_text-decoration.asp + font_size (google.cloud.documentai_v1beta3.types.Document.Style.FontSize): + Font size. + """ + + class FontSize(proto.Message): + r"""Font size with unit. + Attributes: + size (float): + Font size for the text. + unit (str): + Unit for the font size. Follows CSS naming + (in, px, pt, etc.). + """ + + size = proto.Field( + proto.FLOAT, + number=1, + ) + unit = proto.Field( + proto.STRING, + number=2, + ) + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + color = proto.Field( + proto.MESSAGE, + number=2, + message=color_pb2.Color, + ) + background_color = proto.Field( + proto.MESSAGE, + number=3, + message=color_pb2.Color, + ) + font_weight = proto.Field( + proto.STRING, + number=4, + ) + text_style = proto.Field( + proto.STRING, + number=5, + ) + text_decoration = proto.Field( + proto.STRING, + number=6, + ) + font_size = proto.Field( + proto.MESSAGE, + number=7, + message='Document.Style.FontSize', + ) + + class Page(proto.Message): + r"""A page in a [Document][google.cloud.documentai.v1beta3.Document]. + Attributes: + page_number (int): + 1-based index for current + [Page][google.cloud.documentai.v1beta3.Document.Page] in a + parent [Document][google.cloud.documentai.v1beta3.Document]. + Useful when a page is taken out of a + [Document][google.cloud.documentai.v1beta3.Document] for + individual processing. + image (google.cloud.documentai_v1beta3.types.Document.Page.Image): + Rendered image for this page. This image is + preprocessed to remove any skew, rotation, and + distortions such that the annotation bounding + boxes can be upright and axis-aligned. + transforms (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Matrix]): + Transformation matrices that were applied to the original + document image to produce + [Page.image][google.cloud.documentai.v1beta3.Document.Page.image]. + dimension (google.cloud.documentai_v1beta3.types.Document.Page.Dimension): + Physical dimension of the page. + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for the page. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + blocks (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Block]): + A list of visually detected text blocks on + the page. A block has a set of lines (collected + into paragraphs) that have a common line-spacing + and orientation. + paragraphs (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Paragraph]): + A list of visually detected text paragraphs + on the page. A collection of lines that a human + would perceive as a paragraph. + lines (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Line]): + A list of visually detected text lines on the + page. A collection of tokens that a human would + perceive as a line. + tokens (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Token]): + A list of visually detected tokens on the + page. + visual_elements (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.VisualElement]): + A list of detected non-text visual elements + e.g. checkbox, signature etc. on the page. + tables (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table]): + A list of visually detected tables on the + page. + form_fields (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.FormField]): + A list of visually detected form fields on + the page. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this page. + """ + + class Dimension(proto.Message): + r"""Dimension for the page. + Attributes: + width (float): + Page width. + height (float): + Page height. + unit (str): + Dimension unit. + """ + + width = proto.Field( + proto.FLOAT, + number=1, + ) + height = proto.Field( + proto.FLOAT, + number=2, + ) + unit = proto.Field( + proto.STRING, + number=3, + ) + + class Image(proto.Message): + r"""Rendered image contents for this page. + Attributes: + content (bytes): + Raw byte content of the image. + mime_type (str): + Encoding mime type for the image. + width (int): + Width of the image in pixels. + height (int): + Height of the image in pixels. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + width = proto.Field( + proto.INT32, + number=3, + ) + height = proto.Field( + proto.INT32, + number=4, + ) + + class Matrix(proto.Message): + r"""Representation for transformation matrix, intended to be + compatible and used with OpenCV format for image manipulation. + + Attributes: + rows (int): + Number of rows in the matrix. + cols (int): + Number of columns in the matrix. + type_ (int): + This encodes information about what data type the matrix + uses. For example, 0 (CV_8U) is an unsigned 8-bit image. For + the full list of OpenCV primitive data types, please refer + to + https://docs.opencv.org/4.3.0/d1/d1b/group__core__hal__interface.html + data (bytes): + The matrix data. + """ + + rows = proto.Field( + proto.INT32, + number=1, + ) + cols = proto.Field( + proto.INT32, + number=2, + ) + type_ = proto.Field( + proto.INT32, + number=3, + ) + data = proto.Field( + proto.BYTES, + number=4, + ) + + class Layout(proto.Message): + r"""Visual element describing a layout unit on a page. + Attributes: + text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): + Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + confidence (float): + Confidence of the current + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + within context of the object this layout is for. e.g. + confidence can be for a single token, a table, a visual + element, etc. depending on context. Range [0, 1]. + bounding_poly (google.cloud.documentai_v1beta3.types.BoundingPoly): + The bounding polygon for the + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout]. + orientation (google.cloud.documentai_v1beta3.types.Document.Page.Layout.Orientation): + Detected orientation for the + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout]. + """ + class Orientation(proto.Enum): + r"""Detected human reading orientation.""" + ORIENTATION_UNSPECIFIED = 0 + PAGE_UP = 1 + PAGE_RIGHT = 2 + PAGE_DOWN = 3 + PAGE_LEFT = 4 + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=3, + message=geometry.BoundingPoly, + ) + orientation = proto.Field( + proto.ENUM, + number=4, + enum='Document.Page.Layout.Orientation', + ) + + class Block(proto.Message): + r"""A block has a set of lines (collected into paragraphs) that + have a common line-spacing and orientation. + + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Block][google.cloud.documentai.v1beta3.Document.Page.Block]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + class Paragraph(proto.Message): + r"""A collection of lines that a human would perceive as a + paragraph. + + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Paragraph][google.cloud.documentai.v1beta3.Document.Page.Paragraph]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + class Line(proto.Message): + r"""A collection of tokens that a human would perceive as a line. + Does not cross column boundaries, can be horizontal, vertical, + etc. + + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Line][google.cloud.documentai.v1beta3.Document.Page.Line]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this annotation. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + class Token(proto.Message): + r"""A detected token. + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. + detected_break (google.cloud.documentai_v1beta3.types.Document.Page.Token.DetectedBreak): + Detected break at the end of a + [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this annotation. + """ + + class DetectedBreak(proto.Message): + r"""Detected break at the end of a + [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. + + Attributes: + type_ (google.cloud.documentai_v1beta3.types.Document.Page.Token.DetectedBreak.Type): + Detected break type. + """ + class Type(proto.Enum): + r"""Enum to denote the type of break found.""" + TYPE_UNSPECIFIED = 0 + SPACE = 1 + WIDE_SPACE = 2 + HYPHEN = 3 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum='Document.Page.Token.DetectedBreak.Type', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + detected_break = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Token.DetectedBreak', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + provenance = proto.Field( + proto.MESSAGE, + number=4, + message='Document.Provenance', + ) + + class VisualElement(proto.Message): + r"""Detected non-text visual elements e.g. checkbox, signature + etc. on the page. + + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [VisualElement][google.cloud.documentai.v1beta3.Document.Page.VisualElement]. + type_ (str): + Type of the + [VisualElement][google.cloud.documentai.v1beta3.Document.Page.VisualElement]. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + + class Table(proto.Message): + r"""A table representation similar to HTML table structure. + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [Table][google.cloud.documentai.v1beta3.Document.Page.Table]. + header_rows (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableRow]): + Header rows of the table. + body_rows (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableRow]): + Body rows of the table. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + class TableRow(proto.Message): + r"""A row of table cells. + Attributes: + cells (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableCell]): + Cells that make up this row. + """ + + cells = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.Page.Table.TableCell', + ) + + class TableCell(proto.Message): + r"""A cell representation inside the table. + Attributes: + layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for + [TableCell][google.cloud.documentai.v1beta3.Document.Page.Table.TableCell]. + row_span (int): + How many rows this cell spans. + col_span (int): + How many columns this cell spans. + detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages together with + confidence. + """ + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + row_span = proto.Field( + proto.INT32, + number=2, + ) + col_span = proto.Field( + proto.INT32, + number=3, + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + layout = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + header_rows = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='Document.Page.Table.TableRow', + ) + body_rows = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.Table.TableRow', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + + class FormField(proto.Message): + r"""A form field detected on the page. + Attributes: + field_name (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for the + [FormField][google.cloud.documentai.v1beta3.Document.Page.FormField] + name. e.g. ``Address``, ``Email``, ``Grand total``, + ``Phone number``, etc. + field_value (google.cloud.documentai_v1beta3.types.Document.Page.Layout): + [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] + for the + [FormField][google.cloud.documentai.v1beta3.Document.Page.FormField] + value. + name_detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages for name + together with confidence. + value_detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): + A list of detected languages for value + together with confidence. + value_type (str): + If the value is non-textual, this field represents the type. + Current valid values are: + + - blank (this indicates the field_value is normal text) + - "unfilled_checkbox" + - "filled_checkbox". + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + The history of this annotation. + """ + + field_name = proto.Field( + proto.MESSAGE, + number=1, + message='Document.Page.Layout', + ) + field_value = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Layout', + ) + name_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Page.DetectedLanguage', + ) + value_detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + value_type = proto.Field( + proto.STRING, + number=5, + ) + provenance = proto.Field( + proto.MESSAGE, + number=8, + message='Document.Provenance', + ) + + 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 + more information, see + http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + confidence (float): + Confidence of detected language. Range [0, 1]. + """ + + language_code = proto.Field( + proto.STRING, + number=1, + ) + confidence = proto.Field( + proto.FLOAT, + number=2, + ) + + page_number = proto.Field( + proto.INT32, + number=1, + ) + image = proto.Field( + proto.MESSAGE, + number=13, + message='Document.Page.Image', + ) + transforms = proto.RepeatedField( + proto.MESSAGE, + number=14, + message='Document.Page.Matrix', + ) + dimension = proto.Field( + proto.MESSAGE, + number=2, + message='Document.Page.Dimension', + ) + layout = proto.Field( + proto.MESSAGE, + number=3, + message='Document.Page.Layout', + ) + detected_languages = proto.RepeatedField( + proto.MESSAGE, + number=4, + message='Document.Page.DetectedLanguage', + ) + blocks = proto.RepeatedField( + proto.MESSAGE, + number=5, + message='Document.Page.Block', + ) + paragraphs = proto.RepeatedField( + proto.MESSAGE, + number=6, + message='Document.Page.Paragraph', + ) + lines = proto.RepeatedField( + proto.MESSAGE, + number=7, + message='Document.Page.Line', + ) + tokens = proto.RepeatedField( + proto.MESSAGE, + number=8, + message='Document.Page.Token', + ) + visual_elements = proto.RepeatedField( + proto.MESSAGE, + number=9, + message='Document.Page.VisualElement', + ) + tables = proto.RepeatedField( + proto.MESSAGE, + number=10, + message='Document.Page.Table', + ) + form_fields = proto.RepeatedField( + proto.MESSAGE, + number=11, + message='Document.Page.FormField', + ) + provenance = proto.Field( + proto.MESSAGE, + number=16, + message='Document.Provenance', + ) + + class Entity(proto.Message): + r"""A phrase in the text that is a known entity type, such as a + person, an organization, or location. + + Attributes: + text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): + Optional. Provenance of the entity. Text anchor indexing + into the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + type_ (str): + Entity type from a schema e.g. ``Address``. + mention_text (str): + Optional. Text value in the document e.g. + ``1600 Amphitheatre Pkwy``. + mention_id (str): + Optional. Deprecated. Use ``id`` field instead. + confidence (float): + Optional. Confidence of detected Schema entity. Range [0, + 1]. + page_anchor (google.cloud.documentai_v1beta3.types.Document.PageAnchor): + Optional. Represents the provenance of this + entity wrt. the location on the page where it + was found. + id (str): + Optional. Canonical id. This will be a unique + value in the entity list for this document. + normalized_value (google.cloud.documentai_v1beta3.types.Document.Entity.NormalizedValue): + Optional. Normalized entity value. Absent if + the extracted value could not be converted or + the type (e.g. address) is not supported for + certain parsers. This field is also only + populated for certain supported document types. + properties (Sequence[google.cloud.documentai_v1beta3.types.Document.Entity]): + Optional. Entities can be nested to form a + hierarchical data structure representing the + content in the document. + provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): + Optional. The history of this annotation. + redacted (bool): + Optional. Whether the entity will be redacted + for de-identification purposes. + """ + + class NormalizedValue(proto.Message): + r"""Parsed and normalized entity value. + Attributes: + money_value (google.type.money_pb2.Money): + Money value. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/money.proto + date_value (google.type.date_pb2.Date): + Date value. Includes year, month, day. See + also: + https://github.com/googleapis/googleapis/blob/master/google/type/date.proto + datetime_value (google.type.datetime_pb2.DateTime): + DateTime value. Includes date, time, and + timezone. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto + address_value (google.type.postal_address_pb2.PostalAddress): + Postal address. See also: + https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto + boolean_value (bool): + Boolean value. Can be used for entities with + binary values, or for checkboxes. + text (str): + Required. Normalized entity value stored as a string. This + field is populated for supported document type (e.g. + Invoice). For some entity types, one of respective + 'structured_value' fields may also be populated. + + - Money/Currency type (``money_value``) is in the ISO 4217 + text format. + - Date type (``date_value``) is in the ISO 8601 text + format. + - Datetime type (``datetime_value``) is in the ISO 8601 + text format. + """ + + money_value = proto.Field( + proto.MESSAGE, + number=2, + oneof='structured_value', + message=money_pb2.Money, + ) + date_value = proto.Field( + proto.MESSAGE, + number=3, + oneof='structured_value', + message=date_pb2.Date, + ) + datetime_value = proto.Field( + proto.MESSAGE, + number=4, + oneof='structured_value', + message=datetime_pb2.DateTime, + ) + address_value = proto.Field( + proto.MESSAGE, + number=5, + oneof='structured_value', + message=postal_address_pb2.PostalAddress, + ) + boolean_value = proto.Field( + proto.BOOL, + number=6, + oneof='structured_value', + ) + text = proto.Field( + proto.STRING, + number=1, + ) + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + mention_text = proto.Field( + proto.STRING, + number=3, + ) + mention_id = proto.Field( + proto.STRING, + number=4, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + page_anchor = proto.Field( + proto.MESSAGE, + number=6, + message='Document.PageAnchor', + ) + id = proto.Field( + proto.STRING, + number=7, + ) + normalized_value = proto.Field( + proto.MESSAGE, + number=9, + message='Document.Entity.NormalizedValue', + ) + properties = proto.RepeatedField( + proto.MESSAGE, + number=10, + message='Document.Entity', + ) + provenance = proto.Field( + proto.MESSAGE, + number=11, + message='Document.Provenance', + ) + redacted = proto.Field( + proto.BOOL, + number=12, + ) + + class EntityRelation(proto.Message): + r"""Relationship between + [Entities][google.cloud.documentai.v1beta3.Document.Entity]. + + Attributes: + subject_id (str): + Subject entity id. + object_id (str): + Object entity id. + relation (str): + Relationship description. + """ + + subject_id = proto.Field( + proto.STRING, + number=1, + ) + object_id = proto.Field( + proto.STRING, + number=2, + ) + relation = proto.Field( + proto.STRING, + number=3, + ) + + class TextAnchor(proto.Message): + r"""Text reference indexing into the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + + Attributes: + text_segments (Sequence[google.cloud.documentai_v1beta3.types.Document.TextAnchor.TextSegment]): + The text segments from the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + content (str): + Contains the content of the text span so that users do not + have to look it up in the text_segments. + """ + + class TextSegment(proto.Message): + r"""A text segment in the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. The + indices may be out of bounds which indicate that the text extends + into another document shard for large sharded documents. See + [ShardInfo.text_offset][google.cloud.documentai.v1beta3.Document.ShardInfo.text_offset] + + Attributes: + start_index (int): + [TextSegment][google.cloud.documentai.v1beta3.Document.TextAnchor.TextSegment] + start UTF-8 char index in the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + end_index (int): + [TextSegment][google.cloud.documentai.v1beta3.Document.TextAnchor.TextSegment] + half open end UTF-8 char index in the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + """ + + start_index = proto.Field( + proto.INT64, + number=1, + ) + end_index = proto.Field( + proto.INT64, + number=2, + ) + + text_segments = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.TextAnchor.TextSegment', + ) + content = proto.Field( + proto.STRING, + number=2, + ) + + class PageAnchor(proto.Message): + r"""Referencing the visual context of the entity in the + [Document.pages][google.cloud.documentai.v1beta3.Document.pages]. + Page anchors can be cross-page, consist of multiple bounding + polygons and optionally reference specific layout element types. + + Attributes: + page_refs (Sequence[google.cloud.documentai_v1beta3.types.Document.PageAnchor.PageRef]): + One or more references to visual page + elements + """ + + class PageRef(proto.Message): + r"""Represents a weak reference to a page element within a + document. + + Attributes: + page (int): + Required. Index into the + [Document.pages][google.cloud.documentai.v1beta3.Document.pages] + element, for example using [Document.pages][page_refs.page] + to locate the related page element. This field is skipped + when its value is the default 0. See + https://developers.google.com/protocol-buffers/docs/proto3#json. + layout_type (google.cloud.documentai_v1beta3.types.Document.PageAnchor.PageRef.LayoutType): + Optional. The type of the layout element that + is being referenced if any. + layout_id (str): + Optional. Deprecated. Use + [PageRef.bounding_poly][google.cloud.documentai.v1beta3.Document.PageAnchor.PageRef.bounding_poly] + instead. + bounding_poly (google.cloud.documentai_v1beta3.types.BoundingPoly): + Optional. Identifies the bounding polygon of + a layout element on the page. + confidence (float): + Optional. Confidence of detected page element, if + applicable. Range [0, 1]. + """ + class LayoutType(proto.Enum): + r"""The type of layout that is being referenced.""" + LAYOUT_TYPE_UNSPECIFIED = 0 + BLOCK = 1 + PARAGRAPH = 2 + LINE = 3 + TOKEN = 4 + VISUAL_ELEMENT = 5 + TABLE = 6 + FORM_FIELD = 7 + + page = proto.Field( + proto.INT64, + number=1, + ) + layout_type = proto.Field( + proto.ENUM, + number=2, + enum='Document.PageAnchor.PageRef.LayoutType', + ) + layout_id = proto.Field( + proto.STRING, + number=3, + ) + bounding_poly = proto.Field( + proto.MESSAGE, + number=4, + message=geometry.BoundingPoly, + ) + confidence = proto.Field( + proto.FLOAT, + number=5, + ) + + page_refs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Document.PageAnchor.PageRef', + ) + + class Provenance(proto.Message): + r"""Structure to identify provenance relationships between + annotations in different revisions. + + Attributes: + revision (int): + The index of the revision that produced this + element. + id (int): + The Id of this operation. Needs to be unique + within the scope of the revision. + parents (Sequence[google.cloud.documentai_v1beta3.types.Document.Provenance.Parent]): + References to the original elements that are + replaced. + type_ (google.cloud.documentai_v1beta3.types.Document.Provenance.OperationType): + The type of provenance operation. + """ + class OperationType(proto.Enum): + r"""If a processor or agent does an explicit operation on + existing elements. + """ + OPERATION_TYPE_UNSPECIFIED = 0 + ADD = 1 + REMOVE = 2 + REPLACE = 3 + EVAL_REQUESTED = 4 + EVAL_APPROVED = 5 + EVAL_SKIPPED = 6 + + class Parent(proto.Message): + r"""Structure for referencing parent provenances. When an + element replaces one of more other elements parent references + identify the elements that are replaced. + + Attributes: + revision (int): + The index of the [Document.revisions] identifying the parent + revision. + index (int): + The index of the parent revisions + corresponding collection of items (eg. list of + entities, properties within entities, etc.) + id (int): + The id of the parent provenance. + """ + + revision = proto.Field( + proto.INT32, + number=1, + ) + index = proto.Field( + proto.INT32, + number=3, + ) + id = proto.Field( + proto.INT32, + number=2, + ) + + revision = proto.Field( + proto.INT32, + number=1, + ) + id = proto.Field( + proto.INT32, + number=2, + ) + parents = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Provenance.Parent', + ) + type_ = proto.Field( + proto.ENUM, + number=4, + enum='Document.Provenance.OperationType', + ) + + 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 + the name or id of that person. + processor (str): + If the annotation was made by processor + identify the processor by its resource name. + id (str): + Id of the revision. Unique within the + context of the document. + parent (Sequence[int]): + The revisions that this revision is based on. This can + include one or more parent (when documents are merged.) This + field represents the index into the ``revisions`` field. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time that the revision was created. + human_review (google.cloud.documentai_v1beta3.types.Document.Revision.HumanReview): + Human Review information of this revision. + """ + + class HumanReview(proto.Message): + r"""Human Review information of the document. + Attributes: + state (str): + Human review state. e.g. ``requested``, ``succeeded``, + ``rejected``. + state_message (str): + A message providing more details about the current state of + processing. For example, the rejection reason when the state + is ``rejected``. + """ + + state = proto.Field( + proto.STRING, + number=1, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + + agent = proto.Field( + proto.STRING, + number=4, + oneof='source', + ) + processor = proto.Field( + proto.STRING, + number=5, + oneof='source', + ) + id = proto.Field( + proto.STRING, + number=1, + ) + parent = proto.RepeatedField( + proto.INT32, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + human_review = proto.Field( + proto.MESSAGE, + number=6, + message='Document.Revision.HumanReview', + ) + + class TextChange(proto.Message): + r"""This message is used for text changes aka. OCR corrections. + Attributes: + text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): + Provenance of the correction. Text anchor indexing into the + [Document.text][google.cloud.documentai.v1beta3.Document.text]. + There can only be a single ``TextAnchor.text_segments`` + element. If the start and end index of the text segment are + the same, the text change is inserted before that index. + changed_text (str): + The text that replaces the text identified in the + ``text_anchor``. + provenance (Sequence[google.cloud.documentai_v1beta3.types.Document.Provenance]): + The history of this annotation. + """ + + text_anchor = proto.Field( + proto.MESSAGE, + number=1, + message='Document.TextAnchor', + ) + changed_text = proto.Field( + proto.STRING, + number=2, + ) + provenance = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='Document.Provenance', + ) + + uri = proto.Field( + proto.STRING, + number=1, + oneof='source', + ) + content = proto.Field( + proto.BYTES, + number=2, + oneof='source', + ) + mime_type = proto.Field( + proto.STRING, + number=3, + ) + text = proto.Field( + proto.STRING, + number=4, + ) + text_styles = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=Style, + ) + pages = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Page, + ) + entities = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=Entity, + ) + entity_relations = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=EntityRelation, + ) + text_changes = proto.RepeatedField( + proto.MESSAGE, + number=14, + message=TextChange, + ) + shard_info = proto.Field( + proto.MESSAGE, + number=9, + message=ShardInfo, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + revisions = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=Revision, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py new file mode 100644 index 00000000..37bc8b94 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'RawDocument', + 'GcsDocument', + 'GcsDocuments', + 'GcsPrefix', + 'BatchDocumentsInputConfig', + 'DocumentOutputConfig', + }, +) + + +class RawDocument(proto.Message): + r"""Payload message of raw document content (bytes). + Attributes: + content (bytes): + Inline document content. + mime_type (str): + An IANA MIME type (RFC6838) indicating the nature and format + of the [content]. + """ + + content = proto.Field( + proto.BYTES, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class GcsDocument(proto.Message): + r"""Specifies a document stored on Cloud Storage. + Attributes: + gcs_uri (str): + The Cloud Storage object uri. + mime_type (str): + An IANA MIME type (RFC6838) of the content. + """ + + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + +class GcsDocuments(proto.Message): + r"""Specifies a set of documents on Cloud Storage. + Attributes: + documents (Sequence[google.cloud.documentai_v1beta3.types.GcsDocument]): + The list of documents. + """ + + documents = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='GcsDocument', + ) + + +class GcsPrefix(proto.Message): + r"""Specifies all documents on Cloud Storage with a common + prefix. + + Attributes: + gcs_uri_prefix (str): + The URI prefix. + """ + + gcs_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchDocumentsInputConfig(proto.Message): + r"""The common config to specify a set of documents used as + input. + + Attributes: + gcs_prefix (google.cloud.documentai_v1beta3.types.GcsPrefix): + The set of documents that match the specified Cloud Storage + [gcs_prefix]. + gcs_documents (google.cloud.documentai_v1beta3.types.GcsDocuments): + The set of documents individually specified + on Cloud Storage. + """ + + gcs_prefix = proto.Field( + proto.MESSAGE, + number=1, + oneof='source', + message='GcsPrefix', + ) + gcs_documents = proto.Field( + proto.MESSAGE, + number=2, + oneof='source', + message='GcsDocuments', + ) + + +class DocumentOutputConfig(proto.Message): + r"""Config that controls the output of documents. All documents + will be written as a JSON file. + + Attributes: + gcs_output_config (google.cloud.documentai_v1beta3.types.DocumentOutputConfig.GcsOutputConfig): + Output config to write the results to Cloud + Storage. + """ + + class GcsOutputConfig(proto.Message): + r"""The configuration used when outputting documents. + Attributes: + gcs_uri (str): + The Cloud Storage uri (a directory) of the + output. + """ + + gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + + gcs_output_config = proto.Field( + proto.MESSAGE, + number=1, + oneof='destination', + message=GcsOutputConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py new file mode 100644 index 00000000..77ceba10 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py @@ -0,0 +1,698 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.cloud.documentai_v1beta3.types import document as gcd_document +from google.cloud.documentai_v1beta3.types import document_io +from google.cloud.documentai_v1beta3.types import operation_metadata +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.types import processor_type +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'ProcessRequest', + 'HumanReviewStatus', + 'ProcessResponse', + 'BatchProcessRequest', + 'BatchProcessResponse', + 'BatchProcessMetadata', + 'FetchProcessorTypesRequest', + 'FetchProcessorTypesResponse', + 'ListProcessorsRequest', + 'ListProcessorsResponse', + 'CreateProcessorRequest', + 'DeleteProcessorRequest', + 'DeleteProcessorMetadata', + 'EnableProcessorRequest', + 'EnableProcessorResponse', + 'EnableProcessorMetadata', + 'DisableProcessorRequest', + 'DisableProcessorResponse', + 'DisableProcessorMetadata', + 'ReviewDocumentRequest', + 'ReviewDocumentResponse', + 'ReviewDocumentOperationMetadata', + }, +) + + +class ProcessRequest(proto.Message): + r"""Request message for the process document method. + Attributes: + inline_document (google.cloud.documentai_v1beta3.types.Document): + An inline document proto. + raw_document (google.cloud.documentai_v1beta3.types.RawDocument): + A raw document content (bytes). + name (str): + Required. The processor resource name. + document (google.cloud.documentai_v1beta3.types.Document): + The document payload, the [content] and [mime_type] fields + must be set. + skip_human_review (bool): + Whether Human Review feature should be + skipped for this request. Default to false. + """ + + inline_document = proto.Field( + proto.MESSAGE, + number=4, + oneof='source', + message=gcd_document.Document, + ) + raw_document = proto.Field( + proto.MESSAGE, + number=5, + oneof='source', + message=document_io.RawDocument, + ) + name = proto.Field( + proto.STRING, + number=1, + ) + document = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_document.Document, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=3, + ) + + +class HumanReviewStatus(proto.Message): + r"""The status of human review on a processed document. + Attributes: + state (google.cloud.documentai_v1beta3.types.HumanReviewStatus.State): + The state of human review on the processing + request. + state_message (str): + A message providing more details about the + human review state. + human_review_operation (str): + The name of the operation triggered by the processed + document. This field is populated only when the [state] is + [HUMAN_REVIEW_IN_PROGRESS]. It has the same response type + and metadata as the long running operation returned by + [ReviewDocument] method. + """ + class State(proto.Enum): + r"""The final state of human review on a processed document.""" + STATE_UNSPECIFIED = 0 + SKIPPED = 1 + VALIDATION_PASSED = 2 + IN_PROGRESS = 3 + ERROR = 4 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + human_review_operation = proto.Field( + proto.STRING, + number=3, + ) + + +class ProcessResponse(proto.Message): + r"""Response message for the process document method. + Attributes: + document (google.cloud.documentai_v1beta3.types.Document): + The document payload, will populate fields + based on the processor's behavior. + human_review_operation (str): + The name of the operation triggered by the + processed document. If the human review process + is not triggered, this field will be empty. It + has the same response type and metadata as the + long running operation returned by + ReviewDocument method. + human_review_status (google.cloud.documentai_v1beta3.types.HumanReviewStatus): + The status of human review on the processed + document. + """ + + document = proto.Field( + proto.MESSAGE, + number=1, + message=gcd_document.Document, + ) + human_review_operation = proto.Field( + proto.STRING, + number=2, + ) + human_review_status = proto.Field( + proto.MESSAGE, + number=3, + message='HumanReviewStatus', + ) + + +class BatchProcessRequest(proto.Message): + r"""Request message for batch process document method. + Attributes: + name (str): + Required. The processor resource name. + input_configs (Sequence[google.cloud.documentai_v1beta3.types.BatchProcessRequest.BatchInputConfig]): + The input config for each single document in + the batch process. + output_config (google.cloud.documentai_v1beta3.types.BatchProcessRequest.BatchOutputConfig): + The overall output config for batch process. + input_documents (google.cloud.documentai_v1beta3.types.BatchDocumentsInputConfig): + The input documents for batch process. + document_output_config (google.cloud.documentai_v1beta3.types.DocumentOutputConfig): + The overall output config for batch process. + skip_human_review (bool): + Whether Human Review feature should be + skipped for this request. Default to false. + """ + + class BatchInputConfig(proto.Message): + r"""The message for input config in batch process. + Attributes: + gcs_source (str): + The Cloud Storage location as the source of + the document. + mime_type (str): + Mimetype of the input. If the input is a raw document, the + supported mimetypes are application/pdf, image/tiff, and + image/gif. If the input is a [Document] proto, the type + should be application/json. + """ + + gcs_source = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + + class BatchOutputConfig(proto.Message): + r"""The message for output config in batch process. + Attributes: + gcs_destination (str): + The output Cloud Storage directory to put the + processed documents. + """ + + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + input_configs = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=BatchInputConfig, + ) + output_config = proto.Field( + proto.MESSAGE, + number=3, + message=BatchOutputConfig, + ) + input_documents = proto.Field( + proto.MESSAGE, + number=5, + message=document_io.BatchDocumentsInputConfig, + ) + document_output_config = proto.Field( + proto.MESSAGE, + number=6, + message=document_io.DocumentOutputConfig, + ) + skip_human_review = proto.Field( + proto.BOOL, + number=4, + ) + + +class BatchProcessResponse(proto.Message): + 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_v1beta3.types.BatchProcessMetadata.State): + The state of the current batch processing. + state_message (str): + A message providing more details about the + current state of processing. For example, the + error message if the operation is failed. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + individual_process_statuses (Sequence[google.cloud.documentai_v1beta3.types.BatchProcessMetadata.IndividualProcessStatus]): + The list of response details of each + document. + """ + class State(proto.Enum): + r"""Possible states of the batch processing operation.""" + STATE_UNSPECIFIED = 0 + WAITING = 1 + RUNNING = 2 + SUCCEEDED = 3 + CANCELLING = 4 + CANCELLED = 5 + FAILED = 6 + + class IndividualProcessStatus(proto.Message): + r"""The status of a each individual document in the batch + process. + + Attributes: + input_gcs_source (str): + The source of the document, same as the [input_gcs_source] + field in the request when the batch process started. The + batch process is started by take snapshot of that document, + since a user can move or change that document during the + process. + status (google.rpc.status_pb2.Status): + The status of the processing of the document. + output_gcs_destination (str): + The output_gcs_destination (in the request as + 'output_gcs_destination') of the processed document if it + was successful, otherwise empty. + human_review_operation (str): + The name of the operation triggered by the + processed document. If the human review process + is not triggered, this field will be empty. It + has the same response type and metadata as the + long running operation returned by + ReviewDocument method. + human_review_status (google.cloud.documentai_v1beta3.types.HumanReviewStatus): + The status of human review on the processed + document. + """ + + input_gcs_source = proto.Field( + proto.STRING, + number=1, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + output_gcs_destination = proto.Field( + proto.STRING, + number=3, + ) + human_review_operation = proto.Field( + proto.STRING, + number=4, + ) + human_review_status = proto.Field( + proto.MESSAGE, + number=5, + message='HumanReviewStatus', + ) + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + individual_process_statuses = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=IndividualProcessStatus, + ) + + +class FetchProcessorTypesRequest(proto.Message): + r"""Request message for fetch processor types. + Attributes: + parent (str): + Required. The project of processor type to + list. Format: + projects/{project}/locations/{location} + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + + +class FetchProcessorTypesResponse(proto.Message): + r"""Response message for fetch processor types. + Attributes: + processor_types (Sequence[google.cloud.documentai_v1beta3.types.ProcessorType]): + The list of processor types. + """ + + processor_types = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=processor_type.ProcessorType, + ) + + +class ListProcessorsRequest(proto.Message): + r"""Request message for list all processors belongs to a project. + Attributes: + parent (str): + Required. The parent (project and location) + which owns this collection of Processors. + Format: projects/{project}/locations/{location} + page_size (int): + The maximum number of processors to return. + If unspecified, at most 50 processors will be + returned. The maximum value is 100; values above + 100 will be coerced to 100. + page_token (str): + We will return the processors sorted by + creation time. The page token will point to the + next processor. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProcessorsResponse(proto.Message): + r"""Response message for list processors. + Attributes: + processors (Sequence[google.cloud.documentai_v1beta3.types.Processor]): + The list of processors. + next_page_token (str): + Points to the next processor, otherwise + empty. + """ + + @property + def raw_page(self): + return self + + processors = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gcd_processor.Processor, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class CreateProcessorRequest(proto.Message): + r"""Request message for create a processor. Notice this request + is sent to a regionalized backend service, and if the processor + type is not available on that region, the creation will fail. + + Attributes: + parent (str): + Required. The parent (project and location) + under which to create the processor. Format: + projects/{project}/locations/{location} + processor (google.cloud.documentai_v1beta3.types.Processor): + Required. The processor to be created, requires + [processor_type] and [display_name] to be set. Also, the + processor is under CMEK if CMEK fields are set. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + processor = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_processor.Processor, + ) + + +class DeleteProcessorRequest(proto.Message): + r"""Request message for the delete processor method. + Attributes: + name (str): + Required. The processor resource name to be + deleted. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteProcessorMetadata(proto.Message): + r"""The long running operation metadata for delete processor + method. + + Attributes: + common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): + The basic metadata of the long running + operation. + """ + + common_metadata = proto.Field( + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + + +class EnableProcessorRequest(proto.Message): + r"""Request message for the enable processor method. + Attributes: + name (str): + Required. The processor resource name to be + enabled. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class EnableProcessorResponse(proto.Message): + r"""Response message for the enable processor method. """ + + +class EnableProcessorMetadata(proto.Message): + r"""The long running operation metadata for enable processor + method. + + Attributes: + common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): + The basic metadata of the long running + operation. + """ + + common_metadata = proto.Field( + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + + +class DisableProcessorRequest(proto.Message): + r"""Request message for the disable processor method. + Attributes: + name (str): + Required. The processor resource name to be + disabled. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DisableProcessorResponse(proto.Message): + r"""Response message for the disable processor method. """ + + +class DisableProcessorMetadata(proto.Message): + r"""The long running operation metadata for disable processor + method. + + Attributes: + common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): + The basic metadata of the long running + operation. + """ + + common_metadata = proto.Field( + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + + +class ReviewDocumentRequest(proto.Message): + r"""Request message for review document method. + Next Id: 6. + + Attributes: + inline_document (google.cloud.documentai_v1beta3.types.Document): + An inline document proto. + human_review_config (str): + Required. The resource name of the + HumanReviewConfig that the document will be + reviewed with. + document (google.cloud.documentai_v1beta3.types.Document): + The document that needs human review. + enable_schema_validation (bool): + Whether the validation should be performed on + the ad-hoc review request. + priority (google.cloud.documentai_v1beta3.types.ReviewDocumentRequest.Priority): + The priority of the human review task. + """ + class Priority(proto.Enum): + r"""The priority level of the human review task.""" + DEFAULT = 0 + URGENT = 1 + + inline_document = proto.Field( + proto.MESSAGE, + number=4, + oneof='source', + message=gcd_document.Document, + ) + human_review_config = proto.Field( + proto.STRING, + number=1, + ) + document = proto.Field( + proto.MESSAGE, + number=2, + message=gcd_document.Document, + ) + enable_schema_validation = proto.Field( + proto.BOOL, + number=3, + ) + priority = proto.Field( + proto.ENUM, + number=5, + enum=Priority, + ) + + +class ReviewDocumentResponse(proto.Message): + r"""Response message for review document method. + Attributes: + gcs_destination (str): + The Cloud Storage uri for the human reviewed + document. + """ + + gcs_destination = proto.Field( + proto.STRING, + number=1, + ) + + +class ReviewDocumentOperationMetadata(proto.Message): + r"""The long running operation metadata for review document + method. + + Attributes: + state (google.cloud.documentai_v1beta3.types.ReviewDocumentOperationMetadata.State): + Used only when Operation.done is false. + state_message (str): + A message providing more details about the + current state of processing. For example, the + error message if the operation is failed. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): + The basic metadata of the long running + operation. + """ + class State(proto.Enum): + r"""State of the longrunning operation.""" + STATE_UNSPECIFIED = 0 + RUNNING = 1 + CANCELLING = 2 + SUCCEEDED = 3 + FAILED = 4 + CANCELLED = 5 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + common_metadata = proto.Field( + proto.MESSAGE, + number=5, + message=operation_metadata.CommonOperationMetadata, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py new file mode 100644 index 00000000..8dfa1bba --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'Vertex', + 'NormalizedVertex', + 'BoundingPoly', + }, +) + + +class Vertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the vertex coordinates are in the same scale as the + original image. + + Attributes: + x (int): + X coordinate. + y (int): + Y coordinate (starts from the top of the + image). + """ + + x = proto.Field( + proto.INT32, + number=1, + ) + y = proto.Field( + proto.INT32, + number=2, + ) + + +class NormalizedVertex(proto.Message): + r"""A vertex represents a 2D point in the image. + NOTE: the normalized vertex coordinates are relative to the + original image and range from 0 to 1. + + Attributes: + x (float): + X coordinate. + y (float): + Y coordinate (starts from the top of the + image). + """ + + x = proto.Field( + proto.FLOAT, + number=1, + ) + y = proto.Field( + proto.FLOAT, + number=2, + ) + + +class BoundingPoly(proto.Message): + r"""A bounding polygon for the detected image annotation. + Attributes: + vertices (Sequence[google.cloud.documentai_v1beta3.types.Vertex]): + The bounding polygon vertices. + normalized_vertices (Sequence[google.cloud.documentai_v1beta3.types.NormalizedVertex]): + The bounding polygon normalized vertices. + """ + + vertices = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Vertex', + ) + normalized_vertices = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='NormalizedVertex', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py new file mode 100644 index 00000000..07ae7a1d --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'CommonOperationMetadata', + }, +) + + +class CommonOperationMetadata(proto.Message): + r"""The common metadata for long running operations. + Attributes: + state (google.cloud.documentai_v1beta3.types.CommonOperationMetadata.State): + The state of the operation. + state_message (str): + A message providing more details about the + current state of processing. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The creation time of the operation. + update_time (google.protobuf.timestamp_pb2.Timestamp): + The last update time of the operation. + """ + class State(proto.Enum): + r"""State of the longrunning operation.""" + STATE_UNSPECIFIED = 0 + RUNNING = 1 + CANCELLING = 2 + SUCCEEDED = 3 + FAILED = 4 + CANCELLED = 5 + + state = proto.Field( + proto.ENUM, + number=1, + enum=State, + ) + state_message = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py new file mode 100644 index 00000000..22632689 --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'Processor', + }, +) + + +class Processor(proto.Message): + r"""The first-class citizen for DocumentAI. Each processor + defines how to extract structural information from a document. + + Attributes: + name (str): + Output only. Immutable. The resource name of + the processor. Format: + projects/{project}/locations/{location}/processors/{processor} + type_ (str): + The processor type. + display_name (str): + The display name of the processor. + state (google.cloud.documentai_v1beta3.types.Processor.State): + Output only. The state of the processor. + default_processor_version (str): + The default processor version. + process_endpoint (str): + Output only. Immutable. The http endpoint + that can be called to invoke processing. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time the processor was created. + kms_key_name (str): + The KMS key used for encryption/decryption in + CMEK scenarios. See + https://cloud.google.com/security-key- + management. + """ + class State(proto.Enum): + r"""The possible states of the processor.""" + STATE_UNSPECIFIED = 0 + ENABLED = 1 + DISABLED = 2 + ENABLING = 3 + DISABLING = 4 + CREATING = 5 + FAILED = 6 + DELETING = 7 + + name = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=State, + ) + default_processor_version = proto.Field( + proto.STRING, + number=9, + ) + process_endpoint = proto.Field( + proto.STRING, + number=6, + ) + create_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + kms_key_name = proto.Field( + proto.STRING, + number=8, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py new file mode 100644 index 00000000..3bdc8f0f --- /dev/null +++ b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.cloud.documentai.v1beta3', + manifest={ + 'ProcessorType', + }, +) + + +class ProcessorType(proto.Message): + r"""A processor type is responsible for performing a certain + document understanding task on a certain type of document. + + Attributes: + name (str): + The resource name of the processor type. + type_ (str): + The type of the processor. + category (str): + The processor category. + available_locations (Sequence[google.cloud.documentai_v1beta3.types.ProcessorType.LocationInfo]): + The locations in which this processor is + available. + allow_creation (bool): + Whether the processor type allows creation. + If yes, user can create a processor of this + processor type. Otherwise, user needs to require + for whitelisting. + """ + + class LocationInfo(proto.Message): + r"""The location information about where the processor is + available. + + Attributes: + location_id (str): + The location id. + """ + + location_id = proto.Field( + proto.STRING, + number=1, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + category = proto.Field( + proto.STRING, + number=3, + ) + available_locations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=LocationInfo, + ) + allow_creation = proto.Field( + proto.BOOL, + number=6, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/mypy.ini b/owl-bot-staging/v1beta3/mypy.ini new file mode 100644 index 00000000..4505b485 --- /dev/null +++ b/owl-bot-staging/v1beta3/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +namespace_packages = True diff --git a/owl-bot-staging/v1beta3/noxfile.py b/owl-bot-staging/v1beta3/noxfile.py new file mode 100644 index 00000000..2f5c8bba --- /dev/null +++ b/owl-bot-staging/v1beta3/noxfile.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", +] + +@nox.session(python=['3.6', '3.7', '3.8', '3.9']) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/documentai_v1beta3/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python='3.7') +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=['3.6', '3.7']) +def mypy(session): + """Run the type checker.""" + session.install('mypy', 'types-pkg_resources') + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python='3.6') +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx<3.0.0", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py b/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py new file mode 100644 index 00000000..fcfc5540 --- /dev/null +++ b/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py @@ -0,0 +1,184 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class documentaiCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'batch_process_documents': ('name', 'input_configs', 'output_config', 'input_documents', 'document_output_config', 'skip_human_review', ), + 'create_processor': ('parent', 'processor', ), + 'delete_processor': ('name', ), + 'disable_processor': ('name', ), + 'enable_processor': ('name', ), + 'fetch_processor_types': ('parent', ), + 'list_processors': ('parent', 'page_size', 'page_token', ), + 'process_document': ('name', 'inline_document', 'raw_document', 'document', 'skip_human_review', ), + 'review_document': ('human_review_config', 'inline_document', 'document', 'enable_schema_validation', 'priority', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: not a.keyword.value in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=documentaiCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the documentai client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1beta3/setup.py b/owl-bot-staging/v1beta3/setup.py new file mode 100644 index 00000000..90b5b3cf --- /dev/null +++ b/owl-bot-staging/v1beta3/setup.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os +import setuptools # type: ignore + +version = '0.1.0' + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, 'README.rst') +with io.open(readme_filename, encoding='utf-8') as readme_file: + readme = readme_file.read() + +setuptools.setup( + name='google-cloud-documentai', + version=version, + long_description=readme, + packages=setuptools.PEP420PackageFinder.find(), + namespace_packages=('google', 'google.cloud'), + platforms='Posix; MacOS X; Windows', + include_package_data=True, + install_requires=( + 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', + 'libcst >= 0.2.5', + 'proto-plus >= 1.15.0', + 'packaging >= 14.3', ), + python_requires='>=3.6', + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + zip_safe=False, +) diff --git a/owl-bot-staging/v1beta3/tests/__init__.py b/owl-bot-staging/v1beta3/tests/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta3/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta3/tests/unit/__init__.py b/owl-bot-staging/v1beta3/tests/unit/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta3/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py b/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py new file mode 100644 index 00000000..b54a5fcc --- /dev/null +++ b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py new file mode 100644 index 00000000..6dbbe6e7 --- /dev/null +++ b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -0,0 +1,3158 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import mock +import packaging.version + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.documentai_v1beta3.services.document_processor_service import DocumentProcessorServiceAsyncClient +from google.cloud.documentai_v1beta3.services.document_processor_service import DocumentProcessorServiceClient +from google.cloud.documentai_v1beta3.services.document_processor_service import pagers +from google.cloud.documentai_v1beta3.services.document_processor_service import transports +from google.cloud.documentai_v1beta3.services.document_processor_service.transports.base import _GOOGLE_AUTH_VERSION +from google.cloud.documentai_v1beta3.types import document +from google.cloud.documentai_v1beta3.types import document_io +from google.cloud.documentai_v1beta3.types import document_processor_service +from google.cloud.documentai_v1beta3.types import geometry +from google.cloud.documentai_v1beta3.types import processor +from google.cloud.documentai_v1beta3.types import processor as gcd_processor +from google.cloud.documentai_v1beta3.types import processor_type +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import wrappers_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import color_pb2 # type: ignore +from google.type import date_pb2 # type: ignore +from google.type import datetime_pb2 # type: ignore +from google.type import money_pb2 # type: ignore +from google.type import postal_address_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_from_service_account_info(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'documentai.googleapis.com:443' + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_service_account_always_use_jwt(client_class): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_service_account_always_use_jwt_true(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + +@pytest.mark.parametrize("client_class", [ + DocumentProcessorServiceClient, + DocumentProcessorServiceAsyncClient, +]) +def test_document_processor_service_client_from_service_account_file(client_class): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == 'documentai.googleapis.com:443' + + +def test_document_processor_service_client_get_transport_class(): + transport = DocumentProcessorServiceClient.get_transport_class() + available_transports = [ + transports.DocumentProcessorServiceGrpcTransport, + ] + assert transport in available_transports + + transport = DocumentProcessorServiceClient.get_transport_class("grpc") + assert transport == transports.DocumentProcessorServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) +@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) +def test_document_processor_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "true"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "false"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), +]) +@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) +@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_document_processor_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), +]) +def test_document_processor_service_client_client_options_credentials_file(client_class, transport_class, transport_name): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_document_processor_service_client_client_options_from_dict(): + with mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = DocumentProcessorServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +def test_process_document(transport: str = 'grpc', request_type=document_processor_service.ProcessRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse( + human_review_operation='human_review_operation_value', + ) + response = client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.ProcessResponse) + assert response.human_review_operation == 'human_review_operation_value' + + +def test_process_document_from_dict(): + test_process_document(request_type=dict) + + +def test_process_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + client.process_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + +@pytest.mark.asyncio +async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ProcessRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse( + human_review_operation='human_review_operation_value', + )) + response = await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.ProcessResponse) + assert response.human_review_operation == 'human_review_operation_value' + + +@pytest.mark.asyncio +async def test_process_document_async_from_dict(): + await test_process_document_async(request_type=dict) + + +def test_process_document_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = document_processor_service.ProcessResponse() + client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_process_document_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) + await client.process_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_process_document_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.process_document( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +def test_process_document_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.process_document( + document_processor_service.ProcessRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_process_document_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.process_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ProcessResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.process_document( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +@pytest.mark.asyncio +async def test_process_document_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.process_document( + document_processor_service.ProcessRequest(), + name='name_value', + ) + + +def test_batch_process_documents(transport: str = 'grpc', request_type=document_processor_service.BatchProcessRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_batch_process_documents_from_dict(): + test_batch_process_documents(request_type=dict) + + +def test_batch_process_documents_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + client.batch_process_documents() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + +@pytest.mark.asyncio +async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.BatchProcessRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.BatchProcessRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_batch_process_documents_async_from_dict(): + await test_batch_process_documents_async(request_type=dict) + + +def test_batch_process_documents_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.BatchProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_batch_process_documents_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.BatchProcessRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.batch_process_documents(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_batch_process_documents_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_process_documents( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +def test_batch_process_documents_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_process_documents( + document_processor_service.BatchProcessRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_process_documents), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_process_documents( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +@pytest.mark.asyncio +async def test_batch_process_documents_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_process_documents( + document_processor_service.BatchProcessRequest(), + name='name_value', + ) + + +def test_fetch_processor_types(transport: str = 'grpc', request_type=document_processor_service.FetchProcessorTypesRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.FetchProcessorTypesResponse( + ) + response = client.fetch_processor_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.FetchProcessorTypesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.FetchProcessorTypesResponse) + + +def test_fetch_processor_types_from_dict(): + test_fetch_processor_types(request_type=dict) + + +def test_fetch_processor_types_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + client.fetch_processor_types() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.FetchProcessorTypesRequest() + + +@pytest.mark.asyncio +async def test_fetch_processor_types_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.FetchProcessorTypesRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse( + )) + response = await client.fetch_processor_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.FetchProcessorTypesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, document_processor_service.FetchProcessorTypesResponse) + + +@pytest.mark.asyncio +async def test_fetch_processor_types_async_from_dict(): + await test_fetch_processor_types_async(request_type=dict) + + +def test_fetch_processor_types_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.FetchProcessorTypesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + call.return_value = document_processor_service.FetchProcessorTypesResponse() + client.fetch_processor_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_fetch_processor_types_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.FetchProcessorTypesRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse()) + await client.fetch_processor_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +def test_fetch_processor_types_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.FetchProcessorTypesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.fetch_processor_types( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + + +def test_fetch_processor_types_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.fetch_processor_types( + document_processor_service.FetchProcessorTypesRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_fetch_processor_types_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_processor_types), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.FetchProcessorTypesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.fetch_processor_types( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + + +@pytest.mark.asyncio +async def test_fetch_processor_types_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.fetch_processor_types( + document_processor_service.FetchProcessorTypesRequest(), + parent='parent_value', + ) + + +def test_list_processors(transport: str = 'grpc', request_type=document_processor_service.ListProcessorsRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ListProcessorsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_processors(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ListProcessorsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProcessorsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_processors_from_dict(): + test_list_processors(request_type=dict) + + +def test_list_processors_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + client.list_processors() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ListProcessorsRequest() + + +@pytest.mark.asyncio +async def test_list_processors_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ListProcessorsRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_processors(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ListProcessorsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProcessorsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_processors_async_from_dict(): + await test_list_processors_async(request_type=dict) + + +def test_list_processors_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ListProcessorsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + call.return_value = document_processor_service.ListProcessorsResponse() + client.list_processors(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_processors_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ListProcessorsRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse()) + await client.list_processors(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +def test_list_processors_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ListProcessorsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_processors( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + + +def test_list_processors_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_processors( + document_processor_service.ListProcessorsRequest(), + parent='parent_value', + ) + + +@pytest.mark.asyncio +async def test_list_processors_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = document_processor_service.ListProcessorsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_processors( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + + +@pytest.mark.asyncio +async def test_list_processors_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_processors( + document_processor_service.ListProcessorsRequest(), + parent='parent_value', + ) + + +def test_list_processors_pager(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + processor.Processor(), + ], + next_page_token='abc', + ), + document_processor_service.ListProcessorsResponse( + processors=[], + next_page_token='def', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + ], + next_page_token='ghi', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_processors(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, processor.Processor) + for i in results) + +def test_list_processors_pages(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + processor.Processor(), + ], + next_page_token='abc', + ), + document_processor_service.ListProcessorsResponse( + processors=[], + next_page_token='def', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + ], + next_page_token='ghi', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + ], + ), + RuntimeError, + ) + pages = list(client.list_processors(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_processors_async_pager(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + processor.Processor(), + ], + next_page_token='abc', + ), + document_processor_service.ListProcessorsResponse( + processors=[], + next_page_token='def', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + ], + next_page_token='ghi', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_processors(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, processor.Processor) + for i in responses) + +@pytest.mark.asyncio +async def test_list_processors_async_pages(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_processors), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + processor.Processor(), + ], + next_page_token='abc', + ), + document_processor_service.ListProcessorsResponse( + processors=[], + next_page_token='def', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + ], + next_page_token='ghi', + ), + document_processor_service.ListProcessorsResponse( + processors=[ + processor.Processor(), + processor.Processor(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_processors(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +def test_create_processor(transport: str = 'grpc', request_type=document_processor_service.CreateProcessorRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gcd_processor.Processor( + name='name_value', + type_='type__value', + display_name='display_name_value', + state=gcd_processor.Processor.State.ENABLED, + default_processor_version='default_processor_version_value', + process_endpoint='process_endpoint_value', + kms_key_name='kms_key_name_value', + ) + response = client.create_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.CreateProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcd_processor.Processor) + assert response.name == 'name_value' + assert response.type_ == 'type__value' + assert response.display_name == 'display_name_value' + assert response.state == gcd_processor.Processor.State.ENABLED + assert response.default_processor_version == 'default_processor_version_value' + assert response.process_endpoint == 'process_endpoint_value' + assert response.kms_key_name == 'kms_key_name_value' + + +def test_create_processor_from_dict(): + test_create_processor(request_type=dict) + + +def test_create_processor_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + client.create_processor() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.CreateProcessorRequest() + + +@pytest.mark.asyncio +async def test_create_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.CreateProcessorRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor( + name='name_value', + type_='type__value', + display_name='display_name_value', + state=gcd_processor.Processor.State.ENABLED, + default_processor_version='default_processor_version_value', + process_endpoint='process_endpoint_value', + kms_key_name='kms_key_name_value', + )) + response = await client.create_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.CreateProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gcd_processor.Processor) + assert response.name == 'name_value' + assert response.type_ == 'type__value' + assert response.display_name == 'display_name_value' + assert response.state == gcd_processor.Processor.State.ENABLED + assert response.default_processor_version == 'default_processor_version_value' + assert response.process_endpoint == 'process_endpoint_value' + assert response.kms_key_name == 'kms_key_name_value' + + +@pytest.mark.asyncio +async def test_create_processor_async_from_dict(): + await test_create_processor_async(request_type=dict) + + +def test_create_processor_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.CreateProcessorRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + call.return_value = gcd_processor.Processor() + client.create_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_processor_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.CreateProcessorRequest() + + request.parent = 'parent/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor()) + await client.create_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent/value', + ) in kw['metadata'] + + +def test_create_processor_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gcd_processor.Processor() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_processor( + parent='parent_value', + processor=gcd_processor.Processor(name='name_value'), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + assert args[0].processor == gcd_processor.Processor(name='name_value') + + +def test_create_processor_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_processor( + document_processor_service.CreateProcessorRequest(), + parent='parent_value', + processor=gcd_processor.Processor(name='name_value'), + ) + + +@pytest.mark.asyncio +async def test_create_processor_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gcd_processor.Processor() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_processor( + parent='parent_value', + processor=gcd_processor.Processor(name='name_value'), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].parent == 'parent_value' + assert args[0].processor == gcd_processor.Processor(name='name_value') + + +@pytest.mark.asyncio +async def test_create_processor_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_processor( + document_processor_service.CreateProcessorRequest(), + parent='parent_value', + processor=gcd_processor.Processor(name='name_value'), + ) + + +def test_delete_processor(transport: str = 'grpc', request_type=document_processor_service.DeleteProcessorRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.delete_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DeleteProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_processor_from_dict(): + test_delete_processor(request_type=dict) + + +def test_delete_processor_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + client.delete_processor() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DeleteProcessorRequest() + + +@pytest.mark.asyncio +async def test_delete_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.DeleteProcessorRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.delete_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DeleteProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_processor_async_from_dict(): + await test_delete_processor_async(request_type=dict) + + +def test_delete_processor_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.DeleteProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.delete_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_processor_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.DeleteProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.delete_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_delete_processor_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_processor( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +def test_delete_processor_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_processor( + document_processor_service.DeleteProcessorRequest(), + name='name_value', + ) + + +@pytest.mark.asyncio +async def test_delete_processor_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_processor( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].name == 'name_value' + + +@pytest.mark.asyncio +async def test_delete_processor_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_processor( + document_processor_service.DeleteProcessorRequest(), + name='name_value', + ) + + +def test_enable_processor(transport: str = 'grpc', request_type=document_processor_service.EnableProcessorRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.enable_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.enable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.EnableProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_enable_processor_from_dict(): + test_enable_processor(request_type=dict) + + +def test_enable_processor_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.enable_processor), + '__call__') as call: + client.enable_processor() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.EnableProcessorRequest() + + +@pytest.mark.asyncio +async def test_enable_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.EnableProcessorRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.enable_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.enable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.EnableProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_enable_processor_async_from_dict(): + await test_enable_processor_async(request_type=dict) + + +def test_enable_processor_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.EnableProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.enable_processor), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.enable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_enable_processor_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.EnableProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.enable_processor), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.enable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_disable_processor(transport: str = 'grpc', request_type=document_processor_service.DisableProcessorRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.disable_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.disable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DisableProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_disable_processor_from_dict(): + test_disable_processor(request_type=dict) + + +def test_disable_processor_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.disable_processor), + '__call__') as call: + client.disable_processor() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DisableProcessorRequest() + + +@pytest.mark.asyncio +async def test_disable_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.DisableProcessorRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.disable_processor), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.disable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.DisableProcessorRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_disable_processor_async_from_dict(): + await test_disable_processor_async(request_type=dict) + + +def test_disable_processor_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.DisableProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.disable_processor), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.disable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_disable_processor_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.DisableProcessorRequest() + + request.name = 'name/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.disable_processor), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.disable_processor(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name/value', + ) in kw['metadata'] + + +def test_review_document(transport: str = 'grpc', request_type=document_processor_service.ReviewDocumentRequest): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_review_document_from_dict(): + test_review_document(request_type=dict) + + +def test_review_document_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + client.review_document() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + +@pytest.mark.asyncio +async def test_review_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ReviewDocumentRequest): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == document_processor_service.ReviewDocumentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_review_document_async_from_dict(): + await test_review_document_async(request_type=dict) + + +def test_review_document_field_headers(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ReviewDocumentRequest() + + request.human_review_config = 'human_review_config/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'human_review_config=human_review_config/value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_review_document_field_headers_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = document_processor_service.ReviewDocumentRequest() + + request.human_review_config = 'human_review_config/value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.review_document(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'human_review_config=human_review_config/value', + ) in kw['metadata'] + + +def test_review_document_flattened(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.review_document( + human_review_config='human_review_config_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0].human_review_config == 'human_review_config_value' + + +def test_review_document_flattened_error(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.review_document( + document_processor_service.ReviewDocumentRequest(), + human_review_config='human_review_config_value', + ) + + +@pytest.mark.asyncio +async def test_review_document_flattened_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.review_document), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.review_document( + human_review_config='human_review_config_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0].human_review_config == 'human_review_config_value' + + +@pytest.mark.asyncio +async def test_review_document_flattened_error_async(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.review_document( + document_processor_service.ReviewDocumentRequest(), + human_review_config='human_review_config_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DocumentProcessorServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = DocumentProcessorServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.DocumentProcessorServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DocumentProcessorServiceGrpcTransport, + ) + +def test_document_processor_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.DocumentProcessorServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_document_processor_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.DocumentProcessorServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'process_document', + 'batch_process_documents', + 'fetch_processor_types', + 'list_processors', + 'create_processor', + 'delete_processor', + 'enable_processor', + 'disable_processor', + 'review_document', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + ), + quota_project_id="octopus", + ) + + +def test_document_processor_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DocumentProcessorServiceTransport() + adc.assert_called_once() + + +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentProcessorServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DocumentProcessorServiceClient() + adc.assert_called_once_with( + scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_document_processor_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DocumentProcessorServiceGrpcTransport, + transports.DocumentProcessorServiceGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_document_processor_service_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") + adc.assert_called_once_with(scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_document_processor_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "documentai.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', +), + scopes=["1", "2"], + default_host="documentai.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + + +def test_document_processor_service_host_no_port(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com'), + ) + assert client.transport._host == 'documentai.googleapis.com:443' + + +def test_document_processor_service_host_with_port(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com:8000'), + ) + assert client.transport._host == 'documentai.googleapis.com:8000' + +def test_document_processor_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentProcessorServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_document_processor_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) +def test_document_processor_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_document_processor_service_grpc_lro_client(): + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_document_processor_service_grpc_lro_async_client(): + client = DocumentProcessorServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc_asyncio', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_human_review_config_path(): + project = "squid" + location = "clam" + processor = "whelk" + expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) + actual = DocumentProcessorServiceClient.human_review_config_path(project, location, processor) + assert expected == actual + + +def test_parse_human_review_config_path(): + expected = { + "project": "octopus", + "location": "oyster", + "processor": "nudibranch", + } + path = DocumentProcessorServiceClient.human_review_config_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_human_review_config_path(path) + assert expected == actual + +def test_processor_path(): + project = "cuttlefish" + location = "mussel" + processor = "winkle" + expected = "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) + actual = DocumentProcessorServiceClient.processor_path(project, location, processor) + assert expected == actual + + +def test_parse_processor_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "processor": "abalone", + } + path = DocumentProcessorServiceClient.processor_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_processor_path(path) + assert expected == actual + +def test_processor_type_path(): + project = "squid" + location = "clam" + processor_type = "whelk" + expected = "projects/{project}/locations/{location}/processorTypes/{processor_type}".format(project=project, location=location, processor_type=processor_type, ) + actual = DocumentProcessorServiceClient.processor_type_path(project, location, processor_type) + assert expected == actual + + +def test_parse_processor_type_path(): + expected = { + "project": "octopus", + "location": "oyster", + "processor_type": "nudibranch", + } + path = DocumentProcessorServiceClient.processor_type_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_processor_type_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = DocumentProcessorServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = DocumentProcessorServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "winkle" + expected = "folders/{folder}".format(folder=folder, ) + actual = DocumentProcessorServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = DocumentProcessorServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "scallop" + expected = "organizations/{organization}".format(organization=organization, ) + actual = DocumentProcessorServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = DocumentProcessorServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "squid" + expected = "projects/{project}".format(project=project, ) + actual = DocumentProcessorServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = DocumentProcessorServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "whelk" + location = "octopus" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = DocumentProcessorServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = DocumentProcessorServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DocumentProcessorServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: + client = DocumentProcessorServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = DocumentProcessorServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) From 0e704bc4870a1318078f8cea137bfac618db30f7 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 29 Jun 2021 22:21:12 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md --- .../transports/base.py | 42 +- .../transports/grpc.py | 10 +- .../transports/grpc_asyncio.py | 10 +- google/cloud/documentai_v1/types/document.py | 19 +- .../types/document_processor_service.py | 12 + .../transports/base.py | 42 +- .../transports/grpc.py | 10 +- .../transports/grpc_asyncio.py | 10 +- .../transports/base.py | 42 +- .../transports/grpc.py | 10 +- .../transports/grpc_asyncio.py | 10 +- owl-bot-staging/v1/.coveragerc | 17 - owl-bot-staging/v1/MANIFEST.in | 2 - owl-bot-staging/v1/README.rst | 49 - owl-bot-staging/v1/docs/conf.py | 376 -- .../document_processor_service.rst | 6 - .../v1/docs/documentai_v1/services.rst | 6 - .../v1/docs/documentai_v1/types.rst | 7 - owl-bot-staging/v1/docs/index.rst | 7 - .../v1/google/cloud/documentai/__init__.py | 63 - .../v1/google/cloud/documentai/py.typed | 2 - .../v1/google/cloud/documentai_v1/__init__.py | 64 - .../cloud/documentai_v1/gapic_metadata.json | 53 - .../v1/google/cloud/documentai_v1/py.typed | 2 - .../cloud/documentai_v1/services/__init__.py | 15 - .../document_processor_service/__init__.py | 22 - .../async_client.py | 443 --- .../document_processor_service/client.py | 618 ---- .../transports/__init__.py | 33 - .../transports/base.py | 224 -- .../transports/grpc.py | 329 -- .../transports/grpc_asyncio.py | 333 -- .../cloud/documentai_v1/types/__init__.py | 68 - .../cloud/documentai_v1/types/document.py | 1369 ------- .../cloud/documentai_v1/types/document_io.py | 158 - .../types/document_processor_service.py | 343 -- .../cloud/documentai_v1/types/geometry.py | 96 - .../documentai_v1/types/operation_metadata.py | 72 - owl-bot-staging/v1/mypy.ini | 3 - owl-bot-staging/v1/noxfile.py | 132 - .../scripts/fixup_documentai_v1_keywords.py | 178 - owl-bot-staging/v1/setup.py | 53 - owl-bot-staging/v1/tests/__init__.py | 16 - owl-bot-staging/v1/tests/unit/__init__.py | 16 - .../v1/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/documentai_v1/__init__.py | 16 - .../test_document_processor_service.py | 1695 --------- owl-bot-staging/v1beta2/.coveragerc | 17 - owl-bot-staging/v1beta2/MANIFEST.in | 2 - owl-bot-staging/v1beta2/README.rst | 49 - owl-bot-staging/v1beta2/docs/conf.py | 376 -- .../document_understanding_service.rst | 6 - .../docs/documentai_v1beta2/services.rst | 6 - .../v1beta2/docs/documentai_v1beta2/types.rst | 7 - owl-bot-staging/v1beta2/docs/index.rst | 7 - .../google/cloud/documentai/__init__.py | 63 - .../v1beta2/google/cloud/documentai/py.typed | 2 - .../cloud/documentai_v1beta2/__init__.py | 64 - .../documentai_v1beta2/gapic_metadata.json | 43 - .../google/cloud/documentai_v1beta2/py.typed | 2 - .../documentai_v1beta2/services/__init__.py | 15 - .../__init__.py | 22 - .../async_client.py | 327 -- .../document_understanding_service/client.py | 492 --- .../transports/__init__.py | 33 - .../transports/base.py | 204 -- .../transports/grpc.py | 301 -- .../transports/grpc_asyncio.py | 305 -- .../documentai_v1beta2/types/__init__.py | 64 - .../documentai_v1beta2/types/document.py | 993 ------ .../types/document_understanding.py | 546 --- .../documentai_v1beta2/types/geometry.py | 94 - owl-bot-staging/v1beta2/mypy.ini | 3 - owl-bot-staging/v1beta2/noxfile.py | 132 - .../fixup_documentai_v1beta2_keywords.py | 177 - owl-bot-staging/v1beta2/setup.py | 53 - owl-bot-staging/v1beta2/tests/__init__.py | 16 - .../v1beta2/tests/unit/__init__.py | 16 - .../v1beta2/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/documentai_v1beta2/__init__.py | 16 - .../test_document_understanding_service.py | 1342 ------- owl-bot-staging/v1beta3/.coveragerc | 17 - owl-bot-staging/v1beta3/MANIFEST.in | 2 - owl-bot-staging/v1beta3/README.rst | 49 - owl-bot-staging/v1beta3/docs/conf.py | 376 -- .../document_processor_service.rst | 10 - .../docs/documentai_v1beta3/services.rst | 6 - .../v1beta3/docs/documentai_v1beta3/types.rst | 7 - owl-bot-staging/v1beta3/docs/index.rst | 7 - .../google/cloud/documentai/__init__.py | 93 - .../v1beta3/google/cloud/documentai/py.typed | 2 - .../cloud/documentai_v1beta3/__init__.py | 94 - .../documentai_v1beta3/gapic_metadata.json | 113 - .../google/cloud/documentai_v1beta3/py.typed | 2 - .../documentai_v1beta3/services/__init__.py | 15 - .../document_processor_service/__init__.py | 22 - .../async_client.py | 939 ----- .../document_processor_service/client.py | 1125 ------ .../document_processor_service/pagers.py | 141 - .../transports/__init__.py | 33 - .../transports/base.py | 309 -- .../transports/grpc.py | 490 --- .../transports/grpc_asyncio.py | 494 --- .../documentai_v1beta3/types/__init__.py | 102 - .../documentai_v1beta3/types/document.py | 1373 ------- .../documentai_v1beta3/types/document_io.py | 158 - .../types/document_processor_service.py | 698 ---- .../documentai_v1beta3/types/geometry.py | 96 - .../types/operation_metadata.py | 72 - .../documentai_v1beta3/types/processor.py | 104 - .../types/processor_type.py | 85 - owl-bot-staging/v1beta3/mypy.ini | 3 - owl-bot-staging/v1beta3/noxfile.py | 132 - .../fixup_documentai_v1beta3_keywords.py | 184 - owl-bot-staging/v1beta3/setup.py | 53 - owl-bot-staging/v1beta3/tests/__init__.py | 16 - .../v1beta3/tests/unit/__init__.py | 16 - .../v1beta3/tests/unit/gapic/__init__.py | 16 - .../unit/gapic/documentai_v1beta3/__init__.py | 16 - .../test_document_processor_service.py | 3158 ----------------- .../test_document_processor_service.py | 129 +- .../test_document_understanding_service.py | 137 +- .../test_document_processor_service.py | 129 +- 123 files changed, 230 insertions(+), 23723 deletions(-) delete mode 100644 owl-bot-staging/v1/.coveragerc delete mode 100644 owl-bot-staging/v1/MANIFEST.in delete mode 100644 owl-bot-staging/v1/README.rst delete mode 100644 owl-bot-staging/v1/docs/conf.py delete mode 100644 owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst delete mode 100644 owl-bot-staging/v1/docs/documentai_v1/services.rst delete mode 100644 owl-bot-staging/v1/docs/documentai_v1/types.rst delete mode 100644 owl-bot-staging/v1/docs/index.rst delete mode 100644 owl-bot-staging/v1/google/cloud/documentai/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai/py.typed delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/py.typed delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py delete mode 100644 owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py delete mode 100644 owl-bot-staging/v1/mypy.ini delete mode 100644 owl-bot-staging/v1/noxfile.py delete mode 100644 owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py delete mode 100644 owl-bot-staging/v1/setup.py delete mode 100644 owl-bot-staging/v1/tests/__init__.py delete mode 100644 owl-bot-staging/v1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py delete mode 100644 owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py delete mode 100644 owl-bot-staging/v1beta2/.coveragerc delete mode 100644 owl-bot-staging/v1beta2/MANIFEST.in delete mode 100644 owl-bot-staging/v1beta2/README.rst delete mode 100644 owl-bot-staging/v1beta2/docs/conf.py delete mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst delete mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst delete mode 100644 owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst delete mode 100644 owl-bot-staging/v1beta2/docs/index.rst delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai/py.typed delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py delete mode 100644 owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py delete mode 100644 owl-bot-staging/v1beta2/mypy.ini delete mode 100644 owl-bot-staging/v1beta2/noxfile.py delete mode 100644 owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py delete mode 100644 owl-bot-staging/v1beta2/setup.py delete mode 100644 owl-bot-staging/v1beta2/tests/__init__.py delete mode 100644 owl-bot-staging/v1beta2/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py delete mode 100644 owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py delete mode 100644 owl-bot-staging/v1beta3/.coveragerc delete mode 100644 owl-bot-staging/v1beta3/MANIFEST.in delete mode 100644 owl-bot-staging/v1beta3/README.rst delete mode 100644 owl-bot-staging/v1beta3/docs/conf.py delete mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst delete mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst delete mode 100644 owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst delete mode 100644 owl-bot-staging/v1beta3/docs/index.rst delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai/py.typed delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py delete mode 100644 owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py delete mode 100644 owl-bot-staging/v1beta3/mypy.ini delete mode 100644 owl-bot-staging/v1beta3/noxfile.py delete mode 100644 owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py delete mode 100644 owl-bot-staging/v1beta3/setup.py delete mode 100644 owl-bot-staging/v1beta3/tests/__init__.py delete mode 100644 owl-bot-staging/v1beta3/tests/unit/__init__.py delete mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py delete mode 100644 owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index dabbb48a..26811788 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.documentai_v1.types import document_processor_service from google.longrunning import operations_pb2 # type: ignore @@ -47,8 +48,6 @@ except pkg_resources.DistributionNotFound: # pragma: NO COVER _GOOGLE_AUTH_VERSION = None -_API_CORE_VERSION = google.api_core.__version__ - class DocumentProcessorServiceTransport(abc.ABC): """Abstract transport class for DocumentProcessorService.""" @@ -66,6 +65,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +89,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +100,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,13 +119,20 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials - # TODO(busunkim): These two class methods are in the base transport + # TODO(busunkim): This method is in the base transport # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. + # should be deleted once the minimum required versions of google-auth is increased. # TODO: Remove this function once google-auth >= 1.25.0 is required @classmethod @@ -144,27 +153,6 @@ def _get_scopes_kwargs( return scopes_kwargs - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 7063cf35..2cdd8efd 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -63,6 +63,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -103,6 +104,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -156,6 +159,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: @@ -211,14 +215,14 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index 740ceef9..446e9422 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -84,14 +84,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -109,6 +109,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -150,6 +151,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -202,6 +205,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/documentai_v1/types/document.py b/google/cloud/documentai_v1/types/document.py index b2ba01a0..3e2726e1 100644 --- a/google/cloud/documentai_v1/types/document.py +++ b/google/cloud/documentai_v1/types/document.py @@ -212,6 +212,8 @@ class Page(proto.Message): form_fields (Sequence[google.cloud.documentai_v1.types.Document.Page.FormField]): A list of visually detected form fields on the page. + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this page. """ class Dimension(proto.Message): @@ -552,6 +554,8 @@ class FormField(proto.Message): - blank (this indicates the field_value is normal text) - "unfilled_checkbox" - "filled_checkbox". + provenance (google.cloud.documentai_v1.types.Document.Provenance): + The history of this annotation. """ field_name = proto.Field( @@ -567,6 +571,9 @@ class FormField(proto.Message): proto.MESSAGE, number=4, message="Document.Page.DetectedLanguage", ) value_type = proto.Field(proto.STRING, number=5,) + provenance = proto.Field( + proto.MESSAGE, number=8, message="Document.Provenance", + ) class DetectedLanguage(proto.Message): r"""Detected language for a structural component. @@ -615,6 +622,9 @@ class DetectedLanguage(proto.Message): form_fields = proto.RepeatedField( proto.MESSAGE, number=11, message="Document.Page.FormField", ) + provenance = proto.Field( + proto.MESSAGE, number=16, message="Document.Provenance", + ) class Entity(proto.Message): r"""A phrase in the text that is a known entity type, such as a @@ -819,7 +829,9 @@ class PageRef(proto.Message): Required. Index into the [Document.pages][google.cloud.documentai.v1.Document.pages] element, for example using [Document.pages][page_refs.page] - to locate the related page element. + to locate the related page element. This field is skipped + when its value is the default 0. See + https://developers.google.com/protocol-buffers/docs/proto3#json. layout_type (google.cloud.documentai_v1.types.Document.PageAnchor.PageRef.LayoutType): Optional. The type of the layout element that is being referenced if any. @@ -899,11 +911,16 @@ class Parent(proto.Message): revision (int): The index of the [Document.revisions] identifying the parent revision. + index (int): + The index of the parent revisions + corresponding collection of items (eg. list of + entities, properties within entities, etc.) id (int): The id of the parent provenance. """ revision = proto.Field(proto.INT32, number=1,) + index = proto.Field(proto.INT32, number=3,) id = proto.Field(proto.INT32, number=2,) revision = proto.Field(proto.INT32, number=1,) diff --git a/google/cloud/documentai_v1/types/document_processor_service.py b/google/cloud/documentai_v1/types/document_processor_service.py index 38e915be..45ed8089 100644 --- a/google/cloud/documentai_v1/types/document_processor_service.py +++ b/google/cloud/documentai_v1/types/document_processor_service.py @@ -212,12 +212,24 @@ class ReviewDocumentRequest(proto.Message): Required. The resource name of the HumanReviewConfig that the document will be reviewed with. + enable_schema_validation (bool): + Whether the validation should be performed on + the ad-hoc review request. + priority (google.cloud.documentai_v1.types.ReviewDocumentRequest.Priority): + The priority of the human review task. """ + class Priority(proto.Enum): + r"""The priority level of the human review task.""" + DEFAULT = 0 + URGENT = 1 + inline_document = proto.Field( proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document, ) human_review_config = proto.Field(proto.STRING, number=1,) + enable_schema_validation = proto.Field(proto.BOOL, number=3,) + priority = proto.Field(proto.ENUM, number=5, enum=Priority,) class ReviewDocumentResponse(proto.Message): diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index 93cf27a7..b59623e7 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.documentai_v1beta2.types import document from google.cloud.documentai_v1beta2.types import document_understanding @@ -48,8 +49,6 @@ except pkg_resources.DistributionNotFound: # pragma: NO COVER _GOOGLE_AUTH_VERSION = None -_API_CORE_VERSION = google.api_core.__version__ - class DocumentUnderstandingServiceTransport(abc.ABC): """Abstract transport class for DocumentUnderstandingService.""" @@ -67,6 +66,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +90,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +101,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,13 +120,20 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials - # TODO(busunkim): These two class methods are in the base transport + # TODO(busunkim): This method is in the base transport # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. + # should be deleted once the minimum required versions of google-auth is increased. # TODO: Remove this function once google-auth >= 1.25.0 is required @classmethod @@ -145,27 +154,6 @@ def _get_scopes_kwargs( return scopes_kwargs - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index a75e0e94..20b5889a 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -62,6 +62,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -102,6 +103,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -155,6 +158,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: @@ -210,14 +214,14 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index bd913f2d..b8ebd07a 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -85,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -110,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -151,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -203,6 +206,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index d44bd04e..f87da34b 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import retry as retries # type: ignore from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.documentai_v1beta3.types import document_processor_service from google.cloud.documentai_v1beta3.types import processor as gcd_processor @@ -48,8 +49,6 @@ except pkg_resources.DistributionNotFound: # pragma: NO COVER _GOOGLE_AUTH_VERSION = None -_API_CORE_VERSION = google.api_core.__version__ - class DocumentProcessorServiceTransport(abc.ABC): """Abstract transport class for DocumentProcessorService.""" @@ -67,6 +66,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +90,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +101,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,13 +120,20 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials - # TODO(busunkim): These two class methods are in the base transport + # TODO(busunkim): This method is in the base transport # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. + # should be deleted once the minimum required versions of google-auth is increased. # TODO: Remove this function once google-auth >= 1.25.0 is required @classmethod @@ -145,27 +154,6 @@ def _get_scopes_kwargs( return scopes_kwargs - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index 0d2ab17a..35cfbbb0 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -64,6 +64,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -104,6 +105,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -157,6 +160,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: @@ -212,14 +216,14 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index 884dfc82..1cc626bf 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -85,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -110,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -151,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -203,6 +206,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/owl-bot-staging/v1/.coveragerc b/owl-bot-staging/v1/.coveragerc deleted file mode 100644 index ef619357..00000000 --- a/owl-bot-staging/v1/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/documentai/__init__.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ - # Ignore pkg_resources exceptions. - # This is added at the module level as a safeguard for if someone - # generates the code and tries to run it without pip installing. This - # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1/MANIFEST.in b/owl-bot-staging/v1/MANIFEST.in deleted file mode 100644 index b804f157..00000000 --- a/owl-bot-staging/v1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/documentai *.py -recursive-include google/cloud/documentai_v1 *.py diff --git a/owl-bot-staging/v1/README.rst b/owl-bot-staging/v1/README.rst deleted file mode 100644 index 484a3c1c..00000000 --- a/owl-bot-staging/v1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Documentai API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Documentai API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1/docs/conf.py b/owl-bot-staging/v1/docs/conf.py deleted file mode 100644 index 0788579e..00000000 --- a/owl-bot-staging/v1/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-documentai documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = u"google-cloud-documentai" -copyright = u"2020, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-documentai-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - master_doc, - "google-cloud-documentai.tex", - u"google-cloud-documentai Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - master_doc, - "google-cloud-documentai", - u"Google Cloud Documentai Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - master_doc, - "google-cloud-documentai", - u"google-cloud-documentai Documentation", - author, - "google-cloud-documentai", - "GAPIC library for Google Cloud Documentai API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst b/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst deleted file mode 100644 index 3918355b..00000000 --- a/owl-bot-staging/v1/docs/documentai_v1/document_processor_service.rst +++ /dev/null @@ -1,6 +0,0 @@ -DocumentProcessorService ------------------------------------------- - -.. automodule:: google.cloud.documentai_v1.services.document_processor_service - :members: - :inherited-members: diff --git a/owl-bot-staging/v1/docs/documentai_v1/services.rst b/owl-bot-staging/v1/docs/documentai_v1/services.rst deleted file mode 100644 index 551bb666..00000000 --- a/owl-bot-staging/v1/docs/documentai_v1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Documentai v1 API -=========================================== -.. toctree:: - :maxdepth: 2 - - document_processor_service diff --git a/owl-bot-staging/v1/docs/documentai_v1/types.rst b/owl-bot-staging/v1/docs/documentai_v1/types.rst deleted file mode 100644 index 68ac7119..00000000 --- a/owl-bot-staging/v1/docs/documentai_v1/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Documentai v1 API -======================================== - -.. automodule:: google.cloud.documentai_v1.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1/docs/index.rst b/owl-bot-staging/v1/docs/index.rst deleted file mode 100644 index c907db5b..00000000 --- a/owl-bot-staging/v1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - documentai_v1/services - documentai_v1/types diff --git a/owl-bot-staging/v1/google/cloud/documentai/__init__.py b/owl-bot-staging/v1/google/cloud/documentai/__init__.py deleted file mode 100644 index 68d50b9c..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai/__init__.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.cloud.documentai_v1.services.document_processor_service.client import DocumentProcessorServiceClient -from google.cloud.documentai_v1.services.document_processor_service.async_client import DocumentProcessorServiceAsyncClient - -from google.cloud.documentai_v1.types.document import Document -from google.cloud.documentai_v1.types.document_io import BatchDocumentsInputConfig -from google.cloud.documentai_v1.types.document_io import DocumentOutputConfig -from google.cloud.documentai_v1.types.document_io import GcsDocument -from google.cloud.documentai_v1.types.document_io import GcsDocuments -from google.cloud.documentai_v1.types.document_io import GcsPrefix -from google.cloud.documentai_v1.types.document_io import RawDocument -from google.cloud.documentai_v1.types.document_processor_service import BatchProcessMetadata -from google.cloud.documentai_v1.types.document_processor_service import BatchProcessRequest -from google.cloud.documentai_v1.types.document_processor_service import BatchProcessResponse -from google.cloud.documentai_v1.types.document_processor_service import HumanReviewStatus -from google.cloud.documentai_v1.types.document_processor_service import ProcessRequest -from google.cloud.documentai_v1.types.document_processor_service import ProcessResponse -from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentOperationMetadata -from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentRequest -from google.cloud.documentai_v1.types.document_processor_service import ReviewDocumentResponse -from google.cloud.documentai_v1.types.geometry import BoundingPoly -from google.cloud.documentai_v1.types.geometry import NormalizedVertex -from google.cloud.documentai_v1.types.geometry import Vertex -from google.cloud.documentai_v1.types.operation_metadata import CommonOperationMetadata - -__all__ = ('DocumentProcessorServiceClient', - 'DocumentProcessorServiceAsyncClient', - 'Document', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'RawDocument', - 'BatchProcessMetadata', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'HumanReviewStatus', - 'ProcessRequest', - 'ProcessResponse', - 'ReviewDocumentOperationMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', - 'CommonOperationMetadata', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai/py.typed b/owl-bot-staging/v1/google/cloud/documentai/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py deleted file mode 100644 index 941c1e97..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/__init__.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from .services.document_processor_service import DocumentProcessorServiceClient -from .services.document_processor_service import DocumentProcessorServiceAsyncClient - -from .types.document import Document -from .types.document_io import BatchDocumentsInputConfig -from .types.document_io import DocumentOutputConfig -from .types.document_io import GcsDocument -from .types.document_io import GcsDocuments -from .types.document_io import GcsPrefix -from .types.document_io import RawDocument -from .types.document_processor_service import BatchProcessMetadata -from .types.document_processor_service import BatchProcessRequest -from .types.document_processor_service import BatchProcessResponse -from .types.document_processor_service import HumanReviewStatus -from .types.document_processor_service import ProcessRequest -from .types.document_processor_service import ProcessResponse -from .types.document_processor_service import ReviewDocumentOperationMetadata -from .types.document_processor_service import ReviewDocumentRequest -from .types.document_processor_service import ReviewDocumentResponse -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex -from .types.operation_metadata import CommonOperationMetadata - -__all__ = ( - 'DocumentProcessorServiceAsyncClient', -'BatchDocumentsInputConfig', -'BatchProcessMetadata', -'BatchProcessRequest', -'BatchProcessResponse', -'BoundingPoly', -'CommonOperationMetadata', -'Document', -'DocumentOutputConfig', -'DocumentProcessorServiceClient', -'GcsDocument', -'GcsDocuments', -'GcsPrefix', -'HumanReviewStatus', -'NormalizedVertex', -'ProcessRequest', -'ProcessResponse', -'RawDocument', -'ReviewDocumentOperationMetadata', -'ReviewDocumentRequest', -'ReviewDocumentResponse', -'Vertex', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json b/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json deleted file mode 100644 index 0013c0aa..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/gapic_metadata.json +++ /dev/null @@ -1,53 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.documentai_v1", - "protoPackage": "google.cloud.documentai.v1", - "schema": "1.0", - "services": { - "DocumentProcessorService": { - "clients": { - "grpc": { - "libraryClient": "DocumentProcessorServiceClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - }, - "ReviewDocument": { - "methods": [ - "review_document" - ] - } - } - }, - "grpc-async": { - "libraryClient": "DocumentProcessorServiceAsyncClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - }, - "ReviewDocument": { - "methods": [ - "review_document" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed b/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py deleted file mode 100644 index 7217ec7c..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import DocumentProcessorServiceClient -from .async_client import DocumentProcessorServiceAsyncClient - -__all__ = ( - 'DocumentProcessorServiceClient', - 'DocumentProcessorServiceAsyncClient', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py deleted file mode 100644 index a7d3b9e5..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ /dev/null @@ -1,443 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Sequence, Tuple, Type, Union -import pkg_resources - -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1.types import document -from google.cloud.documentai_v1.types import document_processor_service -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport -from .client import DocumentProcessorServiceClient - - -class DocumentProcessorServiceAsyncClient: - """Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - """ - - _client: DocumentProcessorServiceClient - - DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT - - human_review_config_path = staticmethod(DocumentProcessorServiceClient.human_review_config_path) - parse_human_review_config_path = staticmethod(DocumentProcessorServiceClient.parse_human_review_config_path) - processor_path = staticmethod(DocumentProcessorServiceClient.processor_path) - parse_processor_path = staticmethod(DocumentProcessorServiceClient.parse_processor_path) - common_billing_account_path = staticmethod(DocumentProcessorServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(DocumentProcessorServiceClient.parse_common_billing_account_path) - common_folder_path = staticmethod(DocumentProcessorServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(DocumentProcessorServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(DocumentProcessorServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(DocumentProcessorServiceClient.parse_common_organization_path) - common_project_path = staticmethod(DocumentProcessorServiceClient.common_project_path) - parse_common_project_path = staticmethod(DocumentProcessorServiceClient.parse_common_project_path) - common_location_path = staticmethod(DocumentProcessorServiceClient.common_location_path) - parse_common_location_path = staticmethod(DocumentProcessorServiceClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceAsyncClient: The constructed client. - """ - return DocumentProcessorServiceClient.from_service_account_info.__func__(DocumentProcessorServiceAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceAsyncClient: The constructed client. - """ - return DocumentProcessorServiceClient.from_service_account_file.__func__(DocumentProcessorServiceAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentProcessorServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentProcessorServiceTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, DocumentProcessorServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document processor service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.DocumentProcessorServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = DocumentProcessorServiceClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def process_document(self, - request: document_processor_service.ProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.ProcessResponse: - r"""Processes a single document. - - Args: - request (:class:`google.cloud.documentai_v1.types.ProcessRequest`): - The request object. Request message for the process - document method. - name (:class:`str`): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1.types.ProcessResponse: - Response message for the process - document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.ProcessRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def batch_process_documents(self, - request: document_processor_service.BatchProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (:class:`google.cloud.documentai_v1.types.BatchProcessRequest`): - The request object. Request message for batch process - document method. - name (:class:`str`): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1.types.BatchProcessResponse` - Response message for batch process document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.BatchProcessRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.BatchProcessResponse, - metadata_type=document_processor_service.BatchProcessMetadata, - ) - - # Done; return the response. - return response - - async def review_document(self, - request: document_processor_service.ReviewDocumentRequest = None, - *, - human_review_config: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Send a document for Human Review. The input document - should be processed by the specified processor. - - Args: - request (:class:`google.cloud.documentai_v1.types.ReviewDocumentRequest`): - The request object. Request message for review document - method. - human_review_config (:class:`str`): - Required. The resource name of the - HumanReviewConfig that the document will - be reviewed with. - - This corresponds to the ``human_review_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1.types.ReviewDocumentResponse` - Response message for review document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([human_review_config]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.ReviewDocumentRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if human_review_config is not None: - request.human_review_config = human_review_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.review_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("human_review_config", request.human_review_config), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.ReviewDocumentResponse, - metadata_type=document_processor_service.ReviewDocumentOperationMetadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentProcessorServiceAsyncClient", -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py deleted file mode 100644 index 6e4814ab..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/client.py +++ /dev/null @@ -1,618 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from distutils import util -import os -import re -from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources - -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1.types import document -from google.cloud.documentai_v1.types import document_processor_service -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import DocumentProcessorServiceGrpcTransport -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - - -class DocumentProcessorServiceClientMeta(type): - """Metaclass for the DocumentProcessorService client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] - _transport_registry["grpc"] = DocumentProcessorServiceGrpcTransport - _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[DocumentProcessorServiceTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMeta): - """Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "documentai.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentProcessorServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentProcessorServiceTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def human_review_config_path(project: str,location: str,processor: str,) -> str: - """Returns a fully-qualified human_review_config string.""" - return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) - - @staticmethod - def parse_human_review_config_path(path: str) -> Dict[str,str]: - """Parses a human_review_config path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)/humanReviewConfig$", path) - return m.groupdict() if m else {} - - @staticmethod - def processor_path(project: str,location: str,processor: str,) -> str: - """Returns a fully-qualified processor string.""" - return "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) - - @staticmethod - def parse_processor_path(path: str) -> Dict[str,str]: - """Parses a processor path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, DocumentProcessorServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document processor service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, DocumentProcessorServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) - - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, DocumentProcessorServiceTransport): - # transport is a DocumentProcessorServiceTransport instance. - if credentials or client_options.credentials_file: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - ) - - def process_document(self, - request: document_processor_service.ProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.ProcessResponse: - r"""Processes a single document. - - Args: - request (google.cloud.documentai_v1.types.ProcessRequest): - The request object. Request message for the process - document method. - name (str): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1.types.ProcessResponse: - Response message for the process - document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.ProcessRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.ProcessRequest): - request = document_processor_service.ProcessRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.process_document] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def batch_process_documents(self, - request: document_processor_service.BatchProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (google.cloud.documentai_v1.types.BatchProcessRequest): - The request object. Request message for batch process - document method. - name (str): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1.types.BatchProcessResponse` - Response message for batch process document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.BatchProcessRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.BatchProcessRequest): - request = document_processor_service.BatchProcessRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.BatchProcessResponse, - metadata_type=document_processor_service.BatchProcessMetadata, - ) - - # Done; return the response. - return response - - def review_document(self, - request: document_processor_service.ReviewDocumentRequest = None, - *, - human_review_config: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Send a document for Human Review. The input document - should be processed by the specified processor. - - Args: - request (google.cloud.documentai_v1.types.ReviewDocumentRequest): - The request object. Request message for review document - method. - human_review_config (str): - Required. The resource name of the - HumanReviewConfig that the document will - be reviewed with. - - This corresponds to the ``human_review_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1.types.ReviewDocumentResponse` - Response message for review document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([human_review_config]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.ReviewDocumentRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.ReviewDocumentRequest): - request = document_processor_service.ReviewDocumentRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if human_review_config is not None: - request.human_review_config = human_review_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.review_document] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("human_review_config", request.human_review_config), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.ReviewDocumentResponse, - metadata_type=document_processor_service.ReviewDocumentOperationMetadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentProcessorServiceClient", -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py deleted file mode 100644 index 38f9c440..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import DocumentProcessorServiceTransport -from .grpc import DocumentProcessorServiceGrpcTransport -from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] -_transport_registry['grpc'] = DocumentProcessorServiceGrpcTransport -_transport_registry['grpc_asyncio'] = DocumentProcessorServiceGrpcAsyncIOTransport - -__all__ = ( - 'DocumentProcessorServiceTransport', - 'DocumentProcessorServiceGrpcTransport', - 'DocumentProcessorServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py deleted file mode 100644 index 64112947..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ /dev/null @@ -1,224 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version -import pkg_resources - -import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-documentai', - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - - -class DocumentProcessorServiceTransport(abc.ABC): - """Abstract transport class for DocumentProcessorService.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - ) - - DEFAULT_HOST: str = 'documentai.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - - # If the credentials is service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.process_document: gapic_v1.method.wrap_method( - self.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - self.batch_process_documents: gapic_v1.method.wrap_method( - self.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - self.review_document: gapic_v1.method.wrap_method( - self.review_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - } - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - Union[ - document_processor_service.ProcessResponse, - Awaitable[document_processor_service.ProcessResponse] - ]]: - raise NotImplementedError() - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'DocumentProcessorServiceTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py deleted file mode 100644 index 6a11e1a4..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ /dev/null @@ -1,329 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO - - -class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): - """gRPC backend transport for DocumentProcessorService. - - Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - document_processor_service.ProcessResponse]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessRequest], - ~.ProcessResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/ProcessDocument', - request_serializer=document_processor_service.ProcessRequest.serialize, - response_deserializer=document_processor_service.ProcessResponse.deserialize, - ) - return self._stubs['process_document'] - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - operations_pb2.Operation]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/BatchProcessDocuments', - request_serializer=document_processor_service.BatchProcessRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - operations_pb2.Operation]: - r"""Return a callable for the review document method over gRPC. - - Send a document for Human Review. The input document - should be processed by the specified processor. - - Returns: - Callable[[~.ReviewDocumentRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'review_document' not in self._stubs: - self._stubs['review_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/ReviewDocument', - request_serializer=document_processor_service.ReviewDocumentRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['review_document'] - - -__all__ = ( - 'DocumentProcessorServiceGrpcTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py deleted file mode 100644 index b21cb6cc..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ /dev/null @@ -1,333 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.documentai_v1.types import document_processor_service -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .grpc import DocumentProcessorServiceGrpcTransport - - -class DocumentProcessorServiceGrpcAsyncIOTransport(DocumentProcessorServiceTransport): - """gRPC AsyncIO backend transport for DocumentProcessorService. - - Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsAsyncClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - Awaitable[document_processor_service.ProcessResponse]]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessRequest], - Awaitable[~.ProcessResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/ProcessDocument', - request_serializer=document_processor_service.ProcessRequest.serialize, - response_deserializer=document_processor_service.ProcessResponse.deserialize, - ) - return self._stubs['process_document'] - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/BatchProcessDocuments', - request_serializer=document_processor_service.BatchProcessRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the review document method over gRPC. - - Send a document for Human Review. The input document - should be processed by the specified processor. - - Returns: - Callable[[~.ReviewDocumentRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'review_document' not in self._stubs: - self._stubs['review_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1.DocumentProcessorService/ReviewDocument', - request_serializer=document_processor_service.ReviewDocumentRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['review_document'] - - -__all__ = ( - 'DocumentProcessorServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py deleted file mode 100644 index 5c6e3ea1..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/__init__.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .document import ( - Document, -) -from .document_io import ( - BatchDocumentsInputConfig, - DocumentOutputConfig, - GcsDocument, - GcsDocuments, - GcsPrefix, - RawDocument, -) -from .document_processor_service import ( - BatchProcessMetadata, - BatchProcessRequest, - BatchProcessResponse, - HumanReviewStatus, - ProcessRequest, - ProcessResponse, - ReviewDocumentOperationMetadata, - ReviewDocumentRequest, - ReviewDocumentResponse, -) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) -from .operation_metadata import ( - CommonOperationMetadata, -) - -__all__ = ( - 'Document', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'RawDocument', - 'BatchProcessMetadata', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'HumanReviewStatus', - 'ProcessRequest', - 'ProcessResponse', - 'ReviewDocumentOperationMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', - 'CommonOperationMetadata', -) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py deleted file mode 100644 index 694f1d8b..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document.py +++ /dev/null @@ -1,1369 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1.types import geometry -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import date_pb2 # type: ignore -from google.type import datetime_pb2 # type: ignore -from google.type import money_pb2 # type: ignore -from google.type import postal_address_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1', - manifest={ - 'Document', - }, -) - - -class Document(proto.Message): - r"""Document represents the canonical document resource in - Document Understanding AI. - It is an interchange format that provides insights into - documents and allows for collaboration between users and - Document Understanding AI to iterate and optimize for quality. - - Attributes: - uri (str): - Optional. Currently supports Google Cloud Storage URI of the - form ``gs://bucket_name/object_name``. Object versioning is - not supported. See `Google Cloud Storage Request - URIs `__ - for more info. - content (bytes): - Optional. Inline document content, represented as a stream - of bytes. Note: As with all ``bytes`` fields, protobuffers - use a pure binary representation, whereas JSON - representations use base64. - mime_type (str): - An IANA published MIME type (also referred to - as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. - text (str): - Optional. UTF-8 encoded text in reading order - from the document. - text_styles (Sequence[google.cloud.documentai_v1.types.Document.Style]): - Styles for the - [Document.text][google.cloud.documentai.v1.Document.text]. - pages (Sequence[google.cloud.documentai_v1.types.Document.Page]): - Visual page layout for the - [Document][google.cloud.documentai.v1.Document]. - entities (Sequence[google.cloud.documentai_v1.types.Document.Entity]): - A list of entities detected on - [Document.text][google.cloud.documentai.v1.Document.text]. - For document shards, entities in this list may cross shard - boundaries. - entity_relations (Sequence[google.cloud.documentai_v1.types.Document.EntityRelation]): - Relationship among - [Document.entities][google.cloud.documentai.v1.Document.entities]. - text_changes (Sequence[google.cloud.documentai_v1.types.Document.TextChange]): - A list of text corrections made to [Document.text]. This is - usually used for annotating corrections to OCR mistakes. - Text changes for a given revision may not overlap with each - other. - shard_info (google.cloud.documentai_v1.types.Document.ShardInfo): - Information about the sharding if this - document is sharded part of a larger document. - If the document is not sharded, this message is - not specified. - error (google.rpc.status_pb2.Status): - Any error that occurred while processing this - document. - revisions (Sequence[google.cloud.documentai_v1.types.Document.Revision]): - Revision history of this document. - """ - - class ShardInfo(proto.Message): - r"""For a large document, sharding may be performed to produce - several document shards. Each document shard contains this field - to detail which shard it is. - - Attributes: - shard_index (int): - The 0-based index of this shard. - shard_count (int): - Total number of shards. - text_offset (int): - The index of the first character in - [Document.text][google.cloud.documentai.v1.Document.text] in - the overall document global text. - """ - - shard_index = proto.Field( - proto.INT64, - number=1, - ) - shard_count = proto.Field( - proto.INT64, - number=2, - ) - text_offset = proto.Field( - proto.INT64, - number=3, - ) - - class Style(proto.Message): - r"""Annotation for common text style attributes. This adheres to - CSS conventions as much as possible. - - Attributes: - text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor): - Text anchor indexing into the - [Document.text][google.cloud.documentai.v1.Document.text]. - color (google.type.color_pb2.Color): - Text color. - background_color (google.type.color_pb2.Color): - Text background color. - font_weight (str): - Font weight. Possible values are normal, bold, bolder, and - lighter. https://www.w3schools.com/cssref/pr_font_weight.asp - text_style (str): - Text style. Possible values are normal, italic, and oblique. - https://www.w3schools.com/cssref/pr_font_font-style.asp - text_decoration (str): - Text decoration. Follows CSS standard. - https://www.w3schools.com/cssref/pr_text_text-decoration.asp - font_size (google.cloud.documentai_v1.types.Document.Style.FontSize): - Font size. - """ - - class FontSize(proto.Message): - r"""Font size with unit. - Attributes: - size (float): - Font size for the text. - unit (str): - Unit for the font size. Follows CSS naming - (in, px, pt, etc.). - """ - - size = proto.Field( - proto.FLOAT, - number=1, - ) - unit = proto.Field( - proto.STRING, - number=2, - ) - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - color = proto.Field( - proto.MESSAGE, - number=2, - message=color_pb2.Color, - ) - background_color = proto.Field( - proto.MESSAGE, - number=3, - message=color_pb2.Color, - ) - font_weight = proto.Field( - proto.STRING, - number=4, - ) - text_style = proto.Field( - proto.STRING, - number=5, - ) - text_decoration = proto.Field( - proto.STRING, - number=6, - ) - font_size = proto.Field( - proto.MESSAGE, - number=7, - message='Document.Style.FontSize', - ) - - class Page(proto.Message): - r"""A page in a [Document][google.cloud.documentai.v1.Document]. - Attributes: - page_number (int): - 1-based index for current - [Page][google.cloud.documentai.v1.Document.Page] in a parent - [Document][google.cloud.documentai.v1.Document]. Useful when - a page is taken out of a - [Document][google.cloud.documentai.v1.Document] for - individual processing. - image (google.cloud.documentai_v1.types.Document.Page.Image): - Rendered image for this page. This image is - preprocessed to remove any skew, rotation, and - distortions such that the annotation bounding - boxes can be upright and axis-aligned. - transforms (Sequence[google.cloud.documentai_v1.types.Document.Page.Matrix]): - Transformation matrices that were applied to the original - document image to produce - [Page.image][google.cloud.documentai.v1.Document.Page.image]. - dimension (google.cloud.documentai_v1.types.Document.Page.Dimension): - Physical dimension of the page. - layout (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for the page. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - blocks (Sequence[google.cloud.documentai_v1.types.Document.Page.Block]): - A list of visually detected text blocks on - the page. A block has a set of lines (collected - into paragraphs) that have a common line-spacing - and orientation. - paragraphs (Sequence[google.cloud.documentai_v1.types.Document.Page.Paragraph]): - A list of visually detected text paragraphs - on the page. A collection of lines that a human - would perceive as a paragraph. - lines (Sequence[google.cloud.documentai_v1.types.Document.Page.Line]): - A list of visually detected text lines on the - page. A collection of tokens that a human would - perceive as a line. - tokens (Sequence[google.cloud.documentai_v1.types.Document.Page.Token]): - A list of visually detected tokens on the - page. - visual_elements (Sequence[google.cloud.documentai_v1.types.Document.Page.VisualElement]): - A list of detected non-text visual elements - e.g. checkbox, signature etc. on the page. - tables (Sequence[google.cloud.documentai_v1.types.Document.Page.Table]): - A list of visually detected tables on the - page. - form_fields (Sequence[google.cloud.documentai_v1.types.Document.Page.FormField]): - A list of visually detected form fields on - the page. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this page. - """ - - class Dimension(proto.Message): - r"""Dimension for the page. - Attributes: - width (float): - Page width. - height (float): - Page height. - unit (str): - Dimension unit. - """ - - width = proto.Field( - proto.FLOAT, - number=1, - ) - height = proto.Field( - proto.FLOAT, - number=2, - ) - unit = proto.Field( - proto.STRING, - number=3, - ) - - class Image(proto.Message): - r"""Rendered image contents for this page. - Attributes: - content (bytes): - Raw byte content of the image. - mime_type (str): - Encoding mime type for the image. - width (int): - Width of the image in pixels. - height (int): - Height of the image in pixels. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - width = proto.Field( - proto.INT32, - number=3, - ) - height = proto.Field( - proto.INT32, - number=4, - ) - - class Matrix(proto.Message): - r"""Representation for transformation matrix, intended to be - compatible and used with OpenCV format for image manipulation. - - Attributes: - rows (int): - Number of rows in the matrix. - cols (int): - Number of columns in the matrix. - type_ (int): - This encodes information about what data type the matrix - uses. For example, 0 (CV_8U) is an unsigned 8-bit image. For - the full list of OpenCV primitive data types, please refer - to - https://docs.opencv.org/4.3.0/d1/d1b/group__core__hal__interface.html - data (bytes): - The matrix data. - """ - - rows = proto.Field( - proto.INT32, - number=1, - ) - cols = proto.Field( - proto.INT32, - number=2, - ) - type_ = proto.Field( - proto.INT32, - number=3, - ) - data = proto.Field( - proto.BYTES, - number=4, - ) - - 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 - [Document.text][google.cloud.documentai.v1.Document.text]. - confidence (float): - Confidence of the current - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - within context of the object this layout is for. e.g. - confidence can be for a single token, a table, a visual - element, etc. depending on context. Range [0, 1]. - bounding_poly (google.cloud.documentai_v1.types.BoundingPoly): - The bounding polygon for the - [Layout][google.cloud.documentai.v1.Document.Page.Layout]. - orientation (google.cloud.documentai_v1.types.Document.Page.Layout.Orientation): - Detected orientation for the - [Layout][google.cloud.documentai.v1.Document.Page.Layout]. - """ - class Orientation(proto.Enum): - r"""Detected human reading orientation.""" - ORIENTATION_UNSPECIFIED = 0 - PAGE_UP = 1 - PAGE_RIGHT = 2 - PAGE_DOWN = 3 - PAGE_LEFT = 4 - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - orientation = proto.Field( - proto.ENUM, - number=4, - enum='Document.Page.Layout.Orientation', - ) - - class Block(proto.Message): - r"""A block has a set of lines (collected into paragraphs) that - have a common line-spacing and orientation. - - Attributes: - layout (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for [Block][google.cloud.documentai.v1.Document.Page.Block]. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - class Paragraph(proto.Message): - r"""A collection of lines that a human would perceive as a - paragraph. - - Attributes: - layout (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for - [Paragraph][google.cloud.documentai.v1.Document.Page.Paragraph]. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - class Line(proto.Message): - r"""A collection of tokens that a human would perceive as a line. - Does not cross column boundaries, can be horizontal, vertical, - etc. - - Attributes: - layout (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for [Line][google.cloud.documentai.v1.Document.Page.Line]. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - 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] - for [Token][google.cloud.documentai.v1.Document.Page.Token]. - detected_break (google.cloud.documentai_v1.types.Document.Page.Token.DetectedBreak): - Detected break at the end of a - [Token][google.cloud.documentai.v1.Document.Page.Token]. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this annotation. - """ - - class DetectedBreak(proto.Message): - r"""Detected break at the end of a - [Token][google.cloud.documentai.v1.Document.Page.Token]. - - Attributes: - type_ (google.cloud.documentai_v1.types.Document.Page.Token.DetectedBreak.Type): - Detected break type. - """ - class Type(proto.Enum): - r"""Enum to denote the type of break found.""" - TYPE_UNSPECIFIED = 0 - SPACE = 1 - WIDE_SPACE = 2 - HYPHEN = 3 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='Document.Page.Token.DetectedBreak.Type', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Token.DetectedBreak', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=4, - message='Document.Provenance', - ) - - class VisualElement(proto.Message): - r"""Detected non-text visual elements e.g. checkbox, signature - etc. on the page. - - Attributes: - layout (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for - [VisualElement][google.cloud.documentai.v1.Document.Page.VisualElement]. - type_ (str): - Type of the - [VisualElement][google.cloud.documentai.v1.Document.Page.VisualElement]. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - - 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] - for [Table][google.cloud.documentai.v1.Document.Page.Table]. - header_rows (Sequence[google.cloud.documentai_v1.types.Document.Page.Table.TableRow]): - Header rows of the table. - body_rows (Sequence[google.cloud.documentai_v1.types.Document.Page.Table.TableRow]): - Body rows of the table. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - 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. - """ - - cells = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.Page.Table.TableCell', - ) - - 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] - for - [TableCell][google.cloud.documentai.v1.Document.Page.Table.TableCell]. - row_span (int): - How many rows this cell spans. - col_span (int): - How many columns this cell spans. - detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - row_span = proto.Field( - proto.INT32, - number=2, - ) - col_span = proto.Field( - proto.INT32, - number=3, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - header_rows = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.Table.TableRow', - ) - body_rows = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.Table.TableRow', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - 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] - for the - [FormField][google.cloud.documentai.v1.Document.Page.FormField] - name. e.g. ``Address``, ``Email``, ``Grand total``, - ``Phone number``, etc. - field_value (google.cloud.documentai_v1.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1.Document.Page.Layout] - for the - [FormField][google.cloud.documentai.v1.Document.Page.FormField] - value. - name_detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages for name - together with confidence. - value_detected_languages (Sequence[google.cloud.documentai_v1.types.Document.Page.DetectedLanguage]): - A list of detected languages for value - together with confidence. - value_type (str): - If the value is non-textual, this field represents the type. - Current valid values are: - - - blank (this indicates the field_value is normal text) - - "unfilled_checkbox" - - "filled_checkbox". - provenance (google.cloud.documentai_v1.types.Document.Provenance): - The history of this annotation. - """ - - field_name = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - field_value = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Layout', - ) - name_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - value_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - value_type = proto.Field( - proto.STRING, - number=5, - ) - provenance = proto.Field( - proto.MESSAGE, - number=8, - message='Document.Provenance', - ) - - 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 - more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - confidence (float): - Confidence of detected language. Range [0, 1]. - """ - - language_code = proto.Field( - proto.STRING, - number=1, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - - page_number = proto.Field( - proto.INT32, - number=1, - ) - image = proto.Field( - proto.MESSAGE, - number=13, - message='Document.Page.Image', - ) - transforms = proto.RepeatedField( - proto.MESSAGE, - number=14, - message='Document.Page.Matrix', - ) - dimension = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Dimension', - ) - layout = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='Document.Page.Block', - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=6, - message='Document.Page.Paragraph', - ) - lines = proto.RepeatedField( - proto.MESSAGE, - number=7, - message='Document.Page.Line', - ) - tokens = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='Document.Page.Token', - ) - visual_elements = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Document.Page.VisualElement', - ) - tables = proto.RepeatedField( - proto.MESSAGE, - number=10, - message='Document.Page.Table', - ) - form_fields = proto.RepeatedField( - proto.MESSAGE, - number=11, - message='Document.Page.FormField', - ) - provenance = proto.Field( - proto.MESSAGE, - number=16, - message='Document.Provenance', - ) - - class Entity(proto.Message): - r"""A phrase in the text that is a known entity type, such as a - person, an organization, or location. - - Attributes: - text_anchor (google.cloud.documentai_v1.types.Document.TextAnchor): - Optional. Provenance of the entity. Text anchor indexing - into the - [Document.text][google.cloud.documentai.v1.Document.text]. - type_ (str): - Entity type from a schema e.g. ``Address``. - mention_text (str): - Optional. Text value in the document e.g. - ``1600 Amphitheatre Pkwy``. - mention_id (str): - Optional. Deprecated. Use ``id`` field instead. - confidence (float): - Optional. Confidence of detected Schema entity. Range [0, - 1]. - page_anchor (google.cloud.documentai_v1.types.Document.PageAnchor): - Optional. Represents the provenance of this - entity wrt. the location on the page where it - was found. - id (str): - Optional. Canonical id. This will be a unique - value in the entity list for this document. - normalized_value (google.cloud.documentai_v1.types.Document.Entity.NormalizedValue): - Optional. Normalized entity value. Absent if - the extracted value could not be converted or - the type (e.g. address) is not supported for - certain parsers. This field is also only - populated for certain supported document types. - properties (Sequence[google.cloud.documentai_v1.types.Document.Entity]): - Optional. Entities can be nested to form a - hierarchical data structure representing the - content in the document. - provenance (google.cloud.documentai_v1.types.Document.Provenance): - Optional. The history of this annotation. - redacted (bool): - Optional. Whether the entity will be redacted - for de-identification purposes. - """ - - class NormalizedValue(proto.Message): - r"""Parsed and normalized entity value. - Attributes: - money_value (google.type.money_pb2.Money): - Money value. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/money.proto - date_value (google.type.date_pb2.Date): - Date value. Includes year, month, day. See - also: - https://github.com/googleapis/googleapis/blob/master/google/type/date.proto - datetime_value (google.type.datetime_pb2.DateTime): - DateTime value. Includes date, time, and - timezone. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto - address_value (google.type.postal_address_pb2.PostalAddress): - Postal address. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto - boolean_value (bool): - Boolean value. Can be used for entities with - binary values, or for checkboxes. - text (str): - Required. Normalized entity value stored as a string. This - field is populated for supported document type (e.g. - Invoice). For some entity types, one of respective - 'structured_value' fields may also be populated. - - - Money/Currency type (``money_value``) is in the ISO 4217 - text format. - - Date type (``date_value``) is in the ISO 8601 text - format. - - Datetime type (``datetime_value``) is in the ISO 8601 - text format. - """ - - money_value = proto.Field( - proto.MESSAGE, - number=2, - oneof='structured_value', - message=money_pb2.Money, - ) - date_value = proto.Field( - proto.MESSAGE, - number=3, - oneof='structured_value', - message=date_pb2.Date, - ) - datetime_value = proto.Field( - proto.MESSAGE, - number=4, - oneof='structured_value', - message=datetime_pb2.DateTime, - ) - address_value = proto.Field( - proto.MESSAGE, - number=5, - oneof='structured_value', - message=postal_address_pb2.PostalAddress, - ) - boolean_value = proto.Field( - proto.BOOL, - number=6, - oneof='structured_value', - ) - text = proto.Field( - proto.STRING, - number=1, - ) - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - mention_text = proto.Field( - proto.STRING, - number=3, - ) - mention_id = proto.Field( - proto.STRING, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - page_anchor = proto.Field( - proto.MESSAGE, - number=6, - message='Document.PageAnchor', - ) - id = proto.Field( - proto.STRING, - number=7, - ) - normalized_value = proto.Field( - proto.MESSAGE, - number=9, - message='Document.Entity.NormalizedValue', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=10, - message='Document.Entity', - ) - provenance = proto.Field( - proto.MESSAGE, - number=11, - message='Document.Provenance', - ) - redacted = proto.Field( - proto.BOOL, - number=12, - ) - - class EntityRelation(proto.Message): - r"""Relationship between - [Entities][google.cloud.documentai.v1.Document.Entity]. - - Attributes: - subject_id (str): - Subject entity id. - object_id (str): - Object entity id. - relation (str): - Relationship description. - """ - - subject_id = proto.Field( - proto.STRING, - number=1, - ) - object_id = proto.Field( - proto.STRING, - number=2, - ) - relation = proto.Field( - proto.STRING, - number=3, - ) - - class TextAnchor(proto.Message): - r"""Text reference indexing into the - [Document.text][google.cloud.documentai.v1.Document.text]. - - Attributes: - text_segments (Sequence[google.cloud.documentai_v1.types.Document.TextAnchor.TextSegment]): - The text segments from the - [Document.text][google.cloud.documentai.v1.Document.text]. - content (str): - Contains the content of the text span so that users do not - have to look it up in the text_segments. - """ - - class TextSegment(proto.Message): - r"""A text segment in the - [Document.text][google.cloud.documentai.v1.Document.text]. The - indices may be out of bounds which indicate that the text extends - into another document shard for large sharded documents. See - [ShardInfo.text_offset][google.cloud.documentai.v1.Document.ShardInfo.text_offset] - - Attributes: - start_index (int): - [TextSegment][google.cloud.documentai.v1.Document.TextAnchor.TextSegment] - start UTF-8 char index in the - [Document.text][google.cloud.documentai.v1.Document.text]. - end_index (int): - [TextSegment][google.cloud.documentai.v1.Document.TextAnchor.TextSegment] - half open end UTF-8 char index in the - [Document.text][google.cloud.documentai.v1.Document.text]. - """ - - start_index = proto.Field( - proto.INT64, - number=1, - ) - end_index = proto.Field( - proto.INT64, - number=2, - ) - - text_segments = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.TextAnchor.TextSegment', - ) - content = proto.Field( - proto.STRING, - number=2, - ) - - class PageAnchor(proto.Message): - r"""Referencing the visual context of the entity in the - [Document.pages][google.cloud.documentai.v1.Document.pages]. Page - anchors can be cross-page, consist of multiple bounding polygons and - optionally reference specific layout element types. - - Attributes: - page_refs (Sequence[google.cloud.documentai_v1.types.Document.PageAnchor.PageRef]): - One or more references to visual page - elements - """ - - class PageRef(proto.Message): - r"""Represents a weak reference to a page element within a - document. - - Attributes: - page (int): - Required. Index into the - [Document.pages][google.cloud.documentai.v1.Document.pages] - element, for example using [Document.pages][page_refs.page] - to locate the related page element. This field is skipped - when its value is the default 0. See - https://developers.google.com/protocol-buffers/docs/proto3#json. - layout_type (google.cloud.documentai_v1.types.Document.PageAnchor.PageRef.LayoutType): - Optional. The type of the layout element that - is being referenced if any. - layout_id (str): - Optional. Deprecated. Use - [PageRef.bounding_poly][google.cloud.documentai.v1.Document.PageAnchor.PageRef.bounding_poly] - instead. - bounding_poly (google.cloud.documentai_v1.types.BoundingPoly): - Optional. Identifies the bounding polygon of - a layout element on the page. - confidence (float): - Optional. Confidence of detected page element, if - applicable. Range [0, 1]. - """ - class LayoutType(proto.Enum): - r"""The type of layout that is being referenced.""" - LAYOUT_TYPE_UNSPECIFIED = 0 - BLOCK = 1 - PARAGRAPH = 2 - LINE = 3 - TOKEN = 4 - VISUAL_ELEMENT = 5 - TABLE = 6 - FORM_FIELD = 7 - - page = proto.Field( - proto.INT64, - number=1, - ) - layout_type = proto.Field( - proto.ENUM, - number=2, - enum='Document.PageAnchor.PageRef.LayoutType', - ) - layout_id = proto.Field( - proto.STRING, - number=3, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - page_refs = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.PageAnchor.PageRef', - ) - - class Provenance(proto.Message): - r"""Structure to identify provenance relationships between - annotations in different revisions. - - Attributes: - revision (int): - The index of the revision that produced this - element. - id (int): - The Id of this operation. Needs to be unique - within the scope of the revision. - parents (Sequence[google.cloud.documentai_v1.types.Document.Provenance.Parent]): - References to the original elements that are - replaced. - type_ (google.cloud.documentai_v1.types.Document.Provenance.OperationType): - The type of provenance operation. - """ - class OperationType(proto.Enum): - r"""If a processor or agent does an explicit operation on - existing elements. - """ - OPERATION_TYPE_UNSPECIFIED = 0 - ADD = 1 - REMOVE = 2 - REPLACE = 3 - EVAL_REQUESTED = 4 - EVAL_APPROVED = 5 - EVAL_SKIPPED = 6 - - class Parent(proto.Message): - r"""Structure for referencing parent provenances. When an - element replaces one of more other elements parent references - identify the elements that are replaced. - - Attributes: - revision (int): - The index of the [Document.revisions] identifying the parent - revision. - index (int): - The index of the parent revisions - corresponding collection of items (eg. list of - entities, properties within entities, etc.) - id (int): - The id of the parent provenance. - """ - - revision = proto.Field( - proto.INT32, - number=1, - ) - index = proto.Field( - proto.INT32, - number=3, - ) - id = proto.Field( - proto.INT32, - number=2, - ) - - revision = proto.Field( - proto.INT32, - number=1, - ) - id = proto.Field( - proto.INT32, - number=2, - ) - parents = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Provenance.Parent', - ) - type_ = proto.Field( - proto.ENUM, - number=4, - enum='Document.Provenance.OperationType', - ) - - 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 - the name or id of that person. - processor (str): - If the annotation was made by processor - identify the processor by its resource name. - id (str): - Id of the revision. Unique within the - context of the document. - parent (Sequence[int]): - The revisions that this revision is based on. This can - include one or more parent (when documents are merged.) This - field represents the index into the ``revisions`` field. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time that the revision was created. - human_review (google.cloud.documentai_v1.types.Document.Revision.HumanReview): - Human Review information of this revision. - """ - - class HumanReview(proto.Message): - r"""Human Review information of the document. - Attributes: - state (str): - Human review state. e.g. ``requested``, ``succeeded``, - ``rejected``. - state_message (str): - A message providing more details about the current state of - processing. For example, the rejection reason when the state - is ``rejected``. - """ - - state = proto.Field( - proto.STRING, - number=1, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - - agent = proto.Field( - proto.STRING, - number=4, - oneof='source', - ) - processor = proto.Field( - proto.STRING, - number=5, - oneof='source', - ) - id = proto.Field( - proto.STRING, - number=1, - ) - parent = proto.RepeatedField( - proto.INT32, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - human_review = proto.Field( - proto.MESSAGE, - number=6, - message='Document.Revision.HumanReview', - ) - - 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 - [Document.text][google.cloud.documentai.v1.Document.text]. - There can only be a single ``TextAnchor.text_segments`` - element. If the start and end index of the text segment are - the same, the text change is inserted before that index. - changed_text (str): - The text that replaces the text identified in the - ``text_anchor``. - provenance (Sequence[google.cloud.documentai_v1.types.Document.Provenance]): - The history of this annotation. - """ - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - changed_text = proto.Field( - proto.STRING, - number=2, - ) - provenance = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - uri = proto.Field( - proto.STRING, - number=1, - oneof='source', - ) - content = proto.Field( - proto.BYTES, - number=2, - oneof='source', - ) - mime_type = proto.Field( - proto.STRING, - number=3, - ) - text = proto.Field( - proto.STRING, - number=4, - ) - text_styles = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Style, - ) - pages = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=Page, - ) - entities = proto.RepeatedField( - proto.MESSAGE, - number=7, - message=Entity, - ) - entity_relations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=EntityRelation, - ) - text_changes = proto.RepeatedField( - proto.MESSAGE, - number=14, - message=TextChange, - ) - shard_info = proto.Field( - proto.MESSAGE, - number=9, - message=ShardInfo, - ) - error = proto.Field( - proto.MESSAGE, - number=10, - message=status_pb2.Status, - ) - revisions = proto.RepeatedField( - proto.MESSAGE, - number=13, - message=Revision, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py deleted file mode 100644 index fb0abcb7..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_io.py +++ /dev/null @@ -1,158 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1', - manifest={ - 'RawDocument', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - }, -) - - -class RawDocument(proto.Message): - r"""Payload message of raw document content (bytes). - Attributes: - content (bytes): - Inline document content. - mime_type (str): - An IANA MIME type (RFC6838) indicating the nature and format - of the [content]. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class GcsDocument(proto.Message): - r"""Specifies a document stored on Cloud Storage. - Attributes: - gcs_uri (str): - The Cloud Storage object uri. - mime_type (str): - An IANA MIME type (RFC6838) of the content. - """ - - gcs_uri = proto.Field( - proto.STRING, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -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. - """ - - documents = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='GcsDocument', - ) - - -class GcsPrefix(proto.Message): - r"""Specifies all documents on Cloud Storage with a common - prefix. - - Attributes: - gcs_uri_prefix (str): - The URI prefix. - """ - - gcs_uri_prefix = proto.Field( - proto.STRING, - number=1, - ) - - -class BatchDocumentsInputConfig(proto.Message): - r"""The common config to specify a set of documents used as - input. - - Attributes: - gcs_prefix (google.cloud.documentai_v1.types.GcsPrefix): - The set of documents that match the specified Cloud Storage - [gcs_prefix]. - gcs_documents (google.cloud.documentai_v1.types.GcsDocuments): - The set of documents individually specified - on Cloud Storage. - """ - - gcs_prefix = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='GcsPrefix', - ) - gcs_documents = proto.Field( - proto.MESSAGE, - number=2, - oneof='source', - message='GcsDocuments', - ) - - -class DocumentOutputConfig(proto.Message): - r"""Config that controls the output of documents. All documents - will be written as a JSON file. - - Attributes: - gcs_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig.GcsOutputConfig): - Output config to write the results to Cloud - Storage. - """ - - class GcsOutputConfig(proto.Message): - r"""The configuration used when outputting documents. - Attributes: - gcs_uri (str): - The Cloud Storage uri (a directory) of the - output. - """ - - gcs_uri = proto.Field( - proto.STRING, - number=1, - ) - - gcs_output_config = proto.Field( - proto.MESSAGE, - number=1, - oneof='destination', - message=GcsOutputConfig, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py deleted file mode 100644 index 53c58d05..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/document_processor_service.py +++ /dev/null @@ -1,343 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1.types import document as gcd_document -from google.cloud.documentai_v1.types import document_io -from google.cloud.documentai_v1.types import operation_metadata -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1', - manifest={ - 'ProcessRequest', - 'HumanReviewStatus', - 'ProcessResponse', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'BatchProcessMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'ReviewDocumentOperationMetadata', - }, -) - - -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. - raw_document (google.cloud.documentai_v1.types.RawDocument): - A raw document content (bytes). - name (str): - Required. The processor resource name. - skip_human_review (bool): - Whether Human Review feature should be - skipped for this request. Default to false. - """ - - inline_document = proto.Field( - proto.MESSAGE, - number=4, - oneof='source', - message=gcd_document.Document, - ) - raw_document = proto.Field( - proto.MESSAGE, - number=5, - oneof='source', - message=document_io.RawDocument, - ) - name = proto.Field( - proto.STRING, - number=1, - ) - skip_human_review = proto.Field( - proto.BOOL, - number=3, - ) - - -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 - request. - state_message (str): - A message providing more details about the - human review state. - human_review_operation (str): - The name of the operation triggered by the processed - document. This field is populated only when the [state] is - [HUMAN_REVIEW_IN_PROGRESS]. It has the same response type - and metadata as the long running operation returned by - [ReviewDocument] method. - """ - class State(proto.Enum): - r"""The final state of human review on a processed document.""" - STATE_UNSPECIFIED = 0 - SKIPPED = 1 - VALIDATION_PASSED = 2 - IN_PROGRESS = 3 - ERROR = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - human_review_operation = proto.Field( - proto.STRING, - number=3, - ) - - -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 - based on the processor's behavior. - human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus): - The status of human review on the processed - document. - """ - - document = proto.Field( - proto.MESSAGE, - number=1, - message=gcd_document.Document, - ) - human_review_status = proto.Field( - proto.MESSAGE, - number=3, - message='HumanReviewStatus', - ) - - -class BatchProcessRequest(proto.Message): - r"""Request message for batch process document method. - Attributes: - name (str): - Required. The processor resource name. - input_documents (google.cloud.documentai_v1.types.BatchDocumentsInputConfig): - The input documents for batch process. - document_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig): - The overall output config for batch process. - skip_human_review (bool): - Whether Human Review feature should be - skipped for this request. Default to false. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - input_documents = proto.Field( - proto.MESSAGE, - number=5, - message=document_io.BatchDocumentsInputConfig, - ) - document_output_config = proto.Field( - proto.MESSAGE, - number=6, - message=document_io.DocumentOutputConfig, - ) - skip_human_review = proto.Field( - proto.BOOL, - number=4, - ) - - -class BatchProcessResponse(proto.Message): - 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. - state_message (str): - A message providing more details about the - current state of processing. For example, the - error message if the operation is failed. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - individual_process_statuses (Sequence[google.cloud.documentai_v1.types.BatchProcessMetadata.IndividualProcessStatus]): - The list of response details of each - document. - """ - class State(proto.Enum): - r"""Possible states of the batch processing operation.""" - STATE_UNSPECIFIED = 0 - WAITING = 1 - RUNNING = 2 - SUCCEEDED = 3 - CANCELLING = 4 - CANCELLED = 5 - FAILED = 6 - - class IndividualProcessStatus(proto.Message): - r"""The status of a each individual document in the batch - process. - - Attributes: - input_gcs_source (str): - The source of the document, same as the [input_gcs_source] - field in the request when the batch process started. The - batch process is started by take snapshot of that document, - since a user can move or change that document during the - process. - status (google.rpc.status_pb2.Status): - The status of the processing of the document. - output_gcs_destination (str): - The output_gcs_destination (in the request as - 'output_gcs_destination') of the processed document if it - was successful, otherwise empty. - human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus): - The status of human review on the processed - document. - """ - - input_gcs_source = proto.Field( - proto.STRING, - number=1, - ) - status = proto.Field( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - output_gcs_destination = proto.Field( - proto.STRING, - number=3, - ) - human_review_status = proto.Field( - proto.MESSAGE, - number=5, - message='HumanReviewStatus', - ) - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - individual_process_statuses = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=IndividualProcessStatus, - ) - - -class ReviewDocumentRequest(proto.Message): - r"""Request message for review document method. - Attributes: - inline_document (google.cloud.documentai_v1.types.Document): - An inline document proto. - human_review_config (str): - Required. The resource name of the - HumanReviewConfig that the document will be - reviewed with. - enable_schema_validation (bool): - Whether the validation should be performed on - the ad-hoc review request. - priority (google.cloud.documentai_v1.types.ReviewDocumentRequest.Priority): - The priority of the human review task. - """ - class Priority(proto.Enum): - r"""The priority level of the human review task.""" - DEFAULT = 0 - URGENT = 1 - - inline_document = proto.Field( - proto.MESSAGE, - number=4, - oneof='source', - message=gcd_document.Document, - ) - human_review_config = proto.Field( - proto.STRING, - number=1, - ) - enable_schema_validation = proto.Field( - proto.BOOL, - number=3, - ) - priority = proto.Field( - proto.ENUM, - number=5, - enum=Priority, - ) - - -class ReviewDocumentResponse(proto.Message): - r"""Response message for review document method. - Attributes: - gcs_destination (str): - The Cloud Storage uri for the human reviewed - document. - """ - - gcs_destination = proto.Field( - proto.STRING, - number=1, - ) - - -class ReviewDocumentOperationMetadata(proto.Message): - r"""The long running operation metadata for review document - method. - - Attributes: - common_metadata (google.cloud.documentai_v1.types.CommonOperationMetadata): - The basic metadata of the long running - operation. - """ - - common_metadata = proto.Field( - proto.MESSAGE, - number=5, - message=operation_metadata.CommonOperationMetadata, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py deleted file mode 100644 index d145d2a0..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/geometry.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - }, -) - - -class Vertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the vertex coordinates are in the same scale as the - original image. - - Attributes: - x (int): - X coordinate. - y (int): - Y coordinate (starts from the top of the - image). - """ - - x = proto.Field( - proto.INT32, - number=1, - ) - y = proto.Field( - proto.INT32, - number=2, - ) - - -class NormalizedVertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the normalized vertex coordinates are relative to the - original image and range from 0 to 1. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate (starts from the top of the - image). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - - -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. - normalized_vertices (Sequence[google.cloud.documentai_v1.types.NormalizedVertex]): - The bounding polygon normalized vertices. - """ - - vertices = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Vertex', - ) - normalized_vertices = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='NormalizedVertex', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py b/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py deleted file mode 100644 index eec502d1..00000000 --- a/owl-bot-staging/v1/google/cloud/documentai_v1/types/operation_metadata.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1', - manifest={ - 'CommonOperationMetadata', - }, -) - - -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. - state_message (str): - A message providing more details about the - current state of processing. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - """ - class State(proto.Enum): - r"""State of the longrunning operation.""" - STATE_UNSPECIFIED = 0 - RUNNING = 1 - CANCELLING = 2 - SUCCEEDED = 3 - FAILED = 4 - CANCELLED = 5 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1/mypy.ini b/owl-bot-staging/v1/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1/noxfile.py b/owl-bot-staging/v1/noxfile.py deleted file mode 100644 index 8dd88b2e..00000000 --- a/owl-bot-staging/v1/noxfile.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", -] - -@nox.session(python=['3.6', '3.7', '3.8', '3.9']) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/documentai_v1/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python='3.7') -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=['3.6', '3.7']) -def mypy(session): - """Run the type checker.""" - session.install('mypy', 'types-pkg_resources') - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python='3.6') -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx<3.0.0", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) diff --git a/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py b/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py deleted file mode 100644 index 4ad5f8d7..00000000 --- a/owl-bot-staging/v1/scripts/fixup_documentai_v1_keywords.py +++ /dev/null @@ -1,178 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class documentaiCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_process_documents': ('name', 'input_documents', 'document_output_config', 'skip_human_review', ), - 'process_document': ('name', 'inline_document', 'raw_document', 'skip_human_review', ), - 'review_document': ('human_review_config', 'inline_document', 'enable_schema_validation', 'priority', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: not a.keyword.value in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=documentaiCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the documentai client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1/setup.py b/owl-bot-staging/v1/setup.py deleted file mode 100644 index 90b5b3cf..00000000 --- a/owl-bot-staging/v1/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os -import setuptools # type: ignore - -version = '0.1.0' - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, 'README.rst') -with io.open(readme_filename, encoding='utf-8') as readme_file: - readme = readme_file.read() - -setuptools.setup( - name='google-cloud-documentai', - version=version, - long_description=readme, - packages=setuptools.PEP420PackageFinder.find(), - namespace_packages=('google', 'google.cloud'), - platforms='Posix; MacOS X; Windows', - include_package_data=True, - install_requires=( - 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', - 'libcst >= 0.2.5', - 'proto-plus >= 1.15.0', - 'packaging >= 14.3', ), - python_requires='>=3.6', - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1/tests/__init__.py b/owl-bot-staging/v1/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1/tests/unit/__init__.py b/owl-bot-staging/v1/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py deleted file mode 100644 index da500783..00000000 --- a/owl-bot-staging/v1/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ /dev/null @@ -1,1695 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import mock -import packaging.version - -import grpc -from grpc.experimental import aio -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.documentai_v1.services.document_processor_service import DocumentProcessorServiceAsyncClient -from google.cloud.documentai_v1.services.document_processor_service import DocumentProcessorServiceClient -from google.cloud.documentai_v1.services.document_processor_service import transports -from google.cloud.documentai_v1.services.document_processor_service.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.documentai_v1.types import document -from google.cloud.documentai_v1.types import document_io -from google.cloud.documentai_v1.types import document_processor_service -from google.cloud.documentai_v1.types import geometry -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.protobuf import wrappers_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import date_pb2 # type: ignore -from google.type import datetime_pb2 # type: ignore -from google.type import money_pb2 # type: ignore -from google.type import postal_address_pb2 # type: ignore -import google.auth - - -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_from_service_account_info(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'documentai.googleapis.com:443' - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_service_account_always_use_jwt(client_class): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_service_account_always_use_jwt_true(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_from_service_account_file(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'documentai.googleapis.com:443' - - -def test_document_processor_service_client_get_transport_class(): - transport = DocumentProcessorServiceClient.get_transport_class() - available_transports = [ - transports.DocumentProcessorServiceGrpcTransport, - ] - assert transport in available_transports - - transport = DocumentProcessorServiceClient.get_transport_class("grpc") - assert transport == transports.DocumentProcessorServiceGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) -@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) -def test_document_processor_service_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "true"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "false"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) -@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_document_processor_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_client_options_credentials_file(client_class, transport_class, transport_name): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_document_processor_service_client_client_options_from_dict(): - with mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = DocumentProcessorServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_process_document(transport: str = 'grpc', request_type=document_processor_service.ProcessRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse( - ) - response = client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.ProcessResponse) - - -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - -def test_process_document_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - client.process_document() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - -@pytest.mark.asyncio -async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ProcessRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse( - )) - response = await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.ProcessResponse) - - -@pytest.mark.asyncio -async def test_process_document_async_from_dict(): - await test_process_document_async(request_type=dict) - - -def test_process_document_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = document_processor_service.ProcessResponse() - client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_process_document_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) - await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_process_document_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.process_document( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -def test_process_document_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.process_document( - document_processor_service.ProcessRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_process_document_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.process_document( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -@pytest.mark.asyncio -async def test_process_document_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.process_document( - document_processor_service.ProcessRequest(), - name='name_value', - ) - - -def test_batch_process_documents(transport: str = 'grpc', request_type=document_processor_service.BatchProcessRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - -def test_batch_process_documents_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - client.batch_process_documents() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - -@pytest.mark.asyncio -async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.BatchProcessRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_batch_process_documents_async_from_dict(): - await test_batch_process_documents_async(request_type=dict) - - -def test_batch_process_documents_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.BatchProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_batch_process_documents_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.BatchProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_batch_process_documents_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_process_documents( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -def test_batch_process_documents_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.batch_process_documents( - document_processor_service.BatchProcessRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_process_documents( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.batch_process_documents( - document_processor_service.BatchProcessRequest(), - name='name_value', - ) - - -def test_review_document(transport: str = 'grpc', request_type=document_processor_service.ReviewDocumentRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_review_document_from_dict(): - test_review_document(request_type=dict) - - -def test_review_document_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - client.review_document() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - -@pytest.mark.asyncio -async def test_review_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ReviewDocumentRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_review_document_async_from_dict(): - await test_review_document_async(request_type=dict) - - -def test_review_document_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ReviewDocumentRequest() - - request.human_review_config = 'human_review_config/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'human_review_config=human_review_config/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_review_document_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ReviewDocumentRequest() - - request.human_review_config = 'human_review_config/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'human_review_config=human_review_config/value', - ) in kw['metadata'] - - -def test_review_document_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.review_document( - human_review_config='human_review_config_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].human_review_config == 'human_review_config_value' - - -def test_review_document_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.review_document( - document_processor_service.ReviewDocumentRequest(), - human_review_config='human_review_config_value', - ) - - -@pytest.mark.asyncio -async def test_review_document_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.review_document( - human_review_config='human_review_config_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].human_review_config == 'human_review_config_value' - - -@pytest.mark.asyncio -async def test_review_document_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.review_document( - document_processor_service.ReviewDocumentRequest(), - human_review_config='human_review_config_value', - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = DocumentProcessorServiceClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.DocumentProcessorServiceGrpcTransport, - ) - -def test_document_processor_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_document_processor_service_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'process_document', - 'batch_process_documents', - 'review_document', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - ), - quota_project_id="octopus", - ) - - -def test_document_processor_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with(scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_document_processor_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - scopes=["1", "2"], - default_host="documentai.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - - -def test_document_processor_service_host_no_port(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com'), - ) - assert client.transport._host == 'documentai.googleapis.com:443' - - -def test_document_processor_service_host_with_port(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com:8000'), - ) - assert client.transport._host == 'documentai.googleapis.com:8000' - -def test_document_processor_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentProcessorServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_document_processor_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_document_processor_service_grpc_lro_client(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_document_processor_service_grpc_lro_async_client(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc_asyncio', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsAsyncClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_human_review_config_path(): - project = "squid" - location = "clam" - processor = "whelk" - expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) - actual = DocumentProcessorServiceClient.human_review_config_path(project, location, processor) - assert expected == actual - - -def test_parse_human_review_config_path(): - expected = { - "project": "octopus", - "location": "oyster", - "processor": "nudibranch", - } - path = DocumentProcessorServiceClient.human_review_config_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_human_review_config_path(path) - assert expected == actual - -def test_processor_path(): - project = "cuttlefish" - location = "mussel" - processor = "winkle" - expected = "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) - actual = DocumentProcessorServiceClient.processor_path(project, location, processor) - assert expected == actual - - -def test_parse_processor_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "processor": "abalone", - } - path = DocumentProcessorServiceClient.processor_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_processor_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = DocumentProcessorServiceClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = DocumentProcessorServiceClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = DocumentProcessorServiceClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = DocumentProcessorServiceClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = DocumentProcessorServiceClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = DocumentProcessorServiceClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = DocumentProcessorServiceClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = DocumentProcessorServiceClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "winkle" - location = "nautilus" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = DocumentProcessorServiceClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = DocumentProcessorServiceClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: - transport_class = DocumentProcessorServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) diff --git a/owl-bot-staging/v1beta2/.coveragerc b/owl-bot-staging/v1beta2/.coveragerc deleted file mode 100644 index ef619357..00000000 --- a/owl-bot-staging/v1beta2/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/documentai/__init__.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ - # Ignore pkg_resources exceptions. - # This is added at the module level as a safeguard for if someone - # generates the code and tries to run it without pip installing. This - # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1beta2/MANIFEST.in b/owl-bot-staging/v1beta2/MANIFEST.in deleted file mode 100644 index cd0fd7a8..00000000 --- a/owl-bot-staging/v1beta2/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/documentai *.py -recursive-include google/cloud/documentai_v1beta2 *.py diff --git a/owl-bot-staging/v1beta2/README.rst b/owl-bot-staging/v1beta2/README.rst deleted file mode 100644 index 484a3c1c..00000000 --- a/owl-bot-staging/v1beta2/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Documentai API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Documentai API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1beta2/docs/conf.py b/owl-bot-staging/v1beta2/docs/conf.py deleted file mode 100644 index 0788579e..00000000 --- a/owl-bot-staging/v1beta2/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-documentai documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = u"google-cloud-documentai" -copyright = u"2020, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-documentai-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - master_doc, - "google-cloud-documentai.tex", - u"google-cloud-documentai Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - master_doc, - "google-cloud-documentai", - u"Google Cloud Documentai Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - master_doc, - "google-cloud-documentai", - u"google-cloud-documentai Documentation", - author, - "google-cloud-documentai", - "GAPIC library for Google Cloud Documentai API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst deleted file mode 100644 index a0d0da7e..00000000 --- a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/document_understanding_service.rst +++ /dev/null @@ -1,6 +0,0 @@ -DocumentUnderstandingService ----------------------------------------------- - -.. automodule:: google.cloud.documentai_v1beta2.services.document_understanding_service - :members: - :inherited-members: diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst deleted file mode 100644 index 13f4a238..00000000 --- a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Documentai v1beta2 API -================================================ -.. toctree:: - :maxdepth: 2 - - document_understanding_service diff --git a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst b/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst deleted file mode 100644 index 9edede43..00000000 --- a/owl-bot-staging/v1beta2/docs/documentai_v1beta2/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Documentai v1beta2 API -============================================= - -.. automodule:: google.cloud.documentai_v1beta2.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1beta2/docs/index.rst b/owl-bot-staging/v1beta2/docs/index.rst deleted file mode 100644 index 38d5fbb5..00000000 --- a/owl-bot-staging/v1beta2/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - documentai_v1beta2/services - documentai_v1beta2/types diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py deleted file mode 100644 index fe8a1486..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai/__init__.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.cloud.documentai_v1beta2.services.document_understanding_service.client import DocumentUnderstandingServiceClient -from google.cloud.documentai_v1beta2.services.document_understanding_service.async_client import DocumentUnderstandingServiceAsyncClient - -from google.cloud.documentai_v1beta2.types.document import Document -from google.cloud.documentai_v1beta2.types.document_understanding import AutoMlParams -from google.cloud.documentai_v1beta2.types.document_understanding import BatchProcessDocumentsRequest -from google.cloud.documentai_v1beta2.types.document_understanding import BatchProcessDocumentsResponse -from google.cloud.documentai_v1beta2.types.document_understanding import EntityExtractionParams -from google.cloud.documentai_v1beta2.types.document_understanding import FormExtractionParams -from google.cloud.documentai_v1beta2.types.document_understanding import GcsDestination -from google.cloud.documentai_v1beta2.types.document_understanding import GcsSource -from google.cloud.documentai_v1beta2.types.document_understanding import InputConfig -from google.cloud.documentai_v1beta2.types.document_understanding import KeyValuePairHint -from google.cloud.documentai_v1beta2.types.document_understanding import OcrParams -from google.cloud.documentai_v1beta2.types.document_understanding import OperationMetadata -from google.cloud.documentai_v1beta2.types.document_understanding import OutputConfig -from google.cloud.documentai_v1beta2.types.document_understanding import ProcessDocumentRequest -from google.cloud.documentai_v1beta2.types.document_understanding import ProcessDocumentResponse -from google.cloud.documentai_v1beta2.types.document_understanding import TableBoundHint -from google.cloud.documentai_v1beta2.types.document_understanding import TableExtractionParams -from google.cloud.documentai_v1beta2.types.geometry import BoundingPoly -from google.cloud.documentai_v1beta2.types.geometry import NormalizedVertex -from google.cloud.documentai_v1beta2.types.geometry import Vertex - -__all__ = ('DocumentUnderstandingServiceClient', - 'DocumentUnderstandingServiceAsyncClient', - 'Document', - 'AutoMlParams', - 'BatchProcessDocumentsRequest', - 'BatchProcessDocumentsResponse', - 'EntityExtractionParams', - 'FormExtractionParams', - 'GcsDestination', - 'GcsSource', - 'InputConfig', - 'KeyValuePairHint', - 'OcrParams', - 'OperationMetadata', - 'OutputConfig', - 'ProcessDocumentRequest', - 'ProcessDocumentResponse', - 'TableBoundHint', - 'TableExtractionParams', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed b/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py deleted file mode 100644 index afa1ecee..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/__init__.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from .services.document_understanding_service import DocumentUnderstandingServiceClient -from .services.document_understanding_service import DocumentUnderstandingServiceAsyncClient - -from .types.document import Document -from .types.document_understanding import AutoMlParams -from .types.document_understanding import BatchProcessDocumentsRequest -from .types.document_understanding import BatchProcessDocumentsResponse -from .types.document_understanding import EntityExtractionParams -from .types.document_understanding import FormExtractionParams -from .types.document_understanding import GcsDestination -from .types.document_understanding import GcsSource -from .types.document_understanding import InputConfig -from .types.document_understanding import KeyValuePairHint -from .types.document_understanding import OcrParams -from .types.document_understanding import OperationMetadata -from .types.document_understanding import OutputConfig -from .types.document_understanding import ProcessDocumentRequest -from .types.document_understanding import ProcessDocumentResponse -from .types.document_understanding import TableBoundHint -from .types.document_understanding import TableExtractionParams -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex - -__all__ = ( - 'DocumentUnderstandingServiceAsyncClient', -'AutoMlParams', -'BatchProcessDocumentsRequest', -'BatchProcessDocumentsResponse', -'BoundingPoly', -'Document', -'DocumentUnderstandingServiceClient', -'EntityExtractionParams', -'FormExtractionParams', -'GcsDestination', -'GcsSource', -'InputConfig', -'KeyValuePairHint', -'NormalizedVertex', -'OcrParams', -'OperationMetadata', -'OutputConfig', -'ProcessDocumentRequest', -'ProcessDocumentResponse', -'TableBoundHint', -'TableExtractionParams', -'Vertex', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json deleted file mode 100644 index 633dcc19..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/gapic_metadata.json +++ /dev/null @@ -1,43 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.documentai_v1beta2", - "protoPackage": "google.cloud.documentai.v1beta2", - "schema": "1.0", - "services": { - "DocumentUnderstandingService": { - "clients": { - "grpc": { - "libraryClient": "DocumentUnderstandingServiceClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - } - } - }, - "grpc-async": { - "libraryClient": "DocumentUnderstandingServiceAsyncClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py deleted file mode 100644 index f9f99508..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import DocumentUnderstandingServiceClient -from .async_client import DocumentUnderstandingServiceAsyncClient - -__all__ = ( - 'DocumentUnderstandingServiceClient', - 'DocumentUnderstandingServiceAsyncClient', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py deleted file mode 100644 index 2f33a657..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ /dev/null @@ -1,327 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Sequence, Tuple, Type, Union -import pkg_resources - -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.rpc import status_pb2 # type: ignore -from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport -from .client import DocumentUnderstandingServiceClient - - -class DocumentUnderstandingServiceAsyncClient: - """Service to parse structured information from unstructured or - semi-structured documents using state-of-the-art Google AI such - as natural language, computer vision, and translation. - """ - - _client: DocumentUnderstandingServiceClient - - DEFAULT_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT - - common_billing_account_path = staticmethod(DocumentUnderstandingServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_billing_account_path) - common_folder_path = staticmethod(DocumentUnderstandingServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(DocumentUnderstandingServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_organization_path) - common_project_path = staticmethod(DocumentUnderstandingServiceClient.common_project_path) - parse_common_project_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_project_path) - common_location_path = staticmethod(DocumentUnderstandingServiceClient.common_location_path) - parse_common_location_path = staticmethod(DocumentUnderstandingServiceClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentUnderstandingServiceAsyncClient: The constructed client. - """ - return DocumentUnderstandingServiceClient.from_service_account_info.__func__(DocumentUnderstandingServiceAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentUnderstandingServiceAsyncClient: The constructed client. - """ - return DocumentUnderstandingServiceClient.from_service_account_file.__func__(DocumentUnderstandingServiceAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentUnderstandingServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentUnderstandingServiceTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(DocumentUnderstandingServiceClient).get_transport_class, type(DocumentUnderstandingServiceClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, DocumentUnderstandingServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document understanding service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.DocumentUnderstandingServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = DocumentUnderstandingServiceClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def batch_process_documents(self, - request: document_understanding.BatchProcessDocumentsRequest = None, - *, - requests: Sequence[document_understanding.ProcessDocumentRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (:class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest`): - The request object. Request to batch process documents - as an asynchronous operation. The output is written to - Cloud Storage as JSON in the [Document] format. - requests (:class:`Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]`): - Required. Individual requests for - each document. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in - the LRO Operation after the operation is complete. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([requests]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_understanding.BatchProcessDocumentsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if requests: - request.requests.extend(requests) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_understanding.BatchProcessDocumentsResponse, - metadata_type=document_understanding.OperationMetadata, - ) - - # Done; return the response. - return response - - async def process_document(self, - request: document_understanding.ProcessDocumentRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document.Document: - r"""Processes a single document. - - Args: - request (:class:`google.cloud.documentai_v1beta2.types.ProcessDocumentRequest`): - The request object. Request to process one document. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta2.types.Document: - Document represents the canonical - document resource in Document - Understanding AI. It is an interchange - format that provides insights into - documents and allows for collaboration - between users and Document Understanding - AI to iterate and optimize for quality. - - """ - # Create or coerce a protobuf request object. - request = document_understanding.ProcessDocumentRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentUnderstandingServiceAsyncClient", -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py deleted file mode 100644 index 7de0957b..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ /dev/null @@ -1,492 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from distutils import util -import os -import re -from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources - -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.rpc import status_pb2 # type: ignore -from .transports.base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import DocumentUnderstandingServiceGrpcTransport -from .transports.grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport - - -class DocumentUnderstandingServiceClientMeta(type): - """Metaclass for the DocumentUnderstandingService client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentUnderstandingServiceTransport]] - _transport_registry["grpc"] = DocumentUnderstandingServiceGrpcTransport - _transport_registry["grpc_asyncio"] = DocumentUnderstandingServiceGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[DocumentUnderstandingServiceTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class DocumentUnderstandingServiceClient(metaclass=DocumentUnderstandingServiceClientMeta): - """Service to parse structured information from unstructured or - semi-structured documents using state-of-the-art Google AI such - as natural language, computer vision, and translation. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "us-documentai.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentUnderstandingServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentUnderstandingServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentUnderstandingServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentUnderstandingServiceTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, DocumentUnderstandingServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document understanding service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, DocumentUnderstandingServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) - - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, DocumentUnderstandingServiceTransport): - # transport is a DocumentUnderstandingServiceTransport instance. - if credentials or client_options.credentials_file: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - ) - - def batch_process_documents(self, - request: document_understanding.BatchProcessDocumentsRequest = None, - *, - requests: Sequence[document_understanding.ProcessDocumentRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (google.cloud.documentai_v1beta2.types.BatchProcessDocumentsRequest): - The request object. Request to batch process documents - as an asynchronous operation. The output is written to - Cloud Storage as JSON in the [Document] format. - requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): - Required. Individual requests for - each document. - - This corresponds to the ``requests`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.documentai_v1beta2.types.BatchProcessDocumentsResponse` Response to an batch document processing request. This is returned in - the LRO Operation after the operation is complete. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([requests]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_understanding.BatchProcessDocumentsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_understanding.BatchProcessDocumentsRequest): - request = document_understanding.BatchProcessDocumentsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if requests is not None: - request.requests = requests - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_understanding.BatchProcessDocumentsResponse, - metadata_type=document_understanding.OperationMetadata, - ) - - # Done; return the response. - return response - - def process_document(self, - request: document_understanding.ProcessDocumentRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document.Document: - r"""Processes a single document. - - Args: - request (google.cloud.documentai_v1beta2.types.ProcessDocumentRequest): - The request object. Request to process one document. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta2.types.Document: - Document represents the canonical - document resource in Document - Understanding AI. It is an interchange - format that provides insights into - documents and allows for collaboration - between users and Document Understanding - AI to iterate and optimize for quality. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a document_understanding.ProcessDocumentRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_understanding.ProcessDocumentRequest): - request = document_understanding.ProcessDocumentRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.process_document] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentUnderstandingServiceClient", -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py deleted file mode 100644 index 07874536..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import DocumentUnderstandingServiceTransport -from .grpc import DocumentUnderstandingServiceGrpcTransport -from .grpc_asyncio import DocumentUnderstandingServiceGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentUnderstandingServiceTransport]] -_transport_registry['grpc'] = DocumentUnderstandingServiceGrpcTransport -_transport_registry['grpc_asyncio'] = DocumentUnderstandingServiceGrpcAsyncIOTransport - -__all__ = ( - 'DocumentUnderstandingServiceTransport', - 'DocumentUnderstandingServiceGrpcTransport', - 'DocumentUnderstandingServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py deleted file mode 100644 index 6c721e8f..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ /dev/null @@ -1,204 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version -import pkg_resources - -import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-documentai', - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - - -class DocumentUnderstandingServiceTransport(abc.ABC): - """Abstract transport class for DocumentUnderstandingService.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - ) - - DEFAULT_HOST: str = 'us-documentai.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - - # If the credentials is service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.batch_process_documents: gapic_v1.method.wrap_method( - self.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - self.process_document: gapic_v1.method.wrap_method( - self.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - } - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def batch_process_documents(self) -> Callable[ - [document_understanding.BatchProcessDocumentsRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def process_document(self) -> Callable[ - [document_understanding.ProcessDocumentRequest], - Union[ - document.Document, - Awaitable[document.Document] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'DocumentUnderstandingServiceTransport', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py deleted file mode 100644 index bea99a20..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ /dev/null @@ -1,301 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO - - -class DocumentUnderstandingServiceGrpcTransport(DocumentUnderstandingServiceTransport): - """gRPC backend transport for DocumentUnderstandingService. - - Service to parse structured information from unstructured or - semi-structured documents using state-of-the-art Google AI such - as natural language, computer vision, and translation. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'us-documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'us-documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def batch_process_documents(self) -> Callable[ - [document_understanding.BatchProcessDocumentsRequest], - operations_pb2.Operation]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessDocumentsRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/BatchProcessDocuments', - request_serializer=document_understanding.BatchProcessDocumentsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def process_document(self) -> Callable[ - [document_understanding.ProcessDocumentRequest], - document.Document]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessDocumentRequest], - ~.Document]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/ProcessDocument', - request_serializer=document_understanding.ProcessDocumentRequest.serialize, - response_deserializer=document.Document.deserialize, - ) - return self._stubs['process_document'] - - -__all__ = ( - 'DocumentUnderstandingServiceGrpcTransport', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py deleted file mode 100644 index 8bcdc123..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ /dev/null @@ -1,305 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentUnderstandingServiceTransport, DEFAULT_CLIENT_INFO -from .grpc import DocumentUnderstandingServiceGrpcTransport - - -class DocumentUnderstandingServiceGrpcAsyncIOTransport(DocumentUnderstandingServiceTransport): - """gRPC AsyncIO backend transport for DocumentUnderstandingService. - - Service to parse structured information from unstructured or - semi-structured documents using state-of-the-art Google AI such - as natural language, computer vision, and translation. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'us-documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'us-documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsAsyncClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def batch_process_documents(self) -> Callable[ - [document_understanding.BatchProcessDocumentsRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessDocumentsRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/BatchProcessDocuments', - request_serializer=document_understanding.BatchProcessDocumentsRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def process_document(self) -> Callable[ - [document_understanding.ProcessDocumentRequest], - Awaitable[document.Document]]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessDocumentRequest], - Awaitable[~.Document]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta2.DocumentUnderstandingService/ProcessDocument', - request_serializer=document_understanding.ProcessDocumentRequest.serialize, - response_deserializer=document.Document.deserialize, - ) - return self._stubs['process_document'] - - -__all__ = ( - 'DocumentUnderstandingServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py deleted file mode 100644 index b36d125f..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/__init__.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .document import ( - Document, -) -from .document_understanding import ( - AutoMlParams, - BatchProcessDocumentsRequest, - BatchProcessDocumentsResponse, - EntityExtractionParams, - FormExtractionParams, - GcsDestination, - GcsSource, - InputConfig, - KeyValuePairHint, - OcrParams, - OperationMetadata, - OutputConfig, - ProcessDocumentRequest, - ProcessDocumentResponse, - TableBoundHint, - TableExtractionParams, -) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) - -__all__ = ( - 'Document', - 'AutoMlParams', - 'BatchProcessDocumentsRequest', - 'BatchProcessDocumentsResponse', - 'EntityExtractionParams', - 'FormExtractionParams', - 'GcsDestination', - 'GcsSource', - 'InputConfig', - 'KeyValuePairHint', - 'OcrParams', - 'OperationMetadata', - 'OutputConfig', - 'ProcessDocumentRequest', - 'ProcessDocumentResponse', - 'TableBoundHint', - 'TableExtractionParams', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', -) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py deleted file mode 100644 index cc67300a..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document.py +++ /dev/null @@ -1,993 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1beta2.types import geometry -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta2', - manifest={ - 'Document', - }, -) - - -class Document(proto.Message): - r"""Document represents the canonical document resource in - Document Understanding AI. - It is an interchange format that provides insights into - documents and allows for collaboration between users and - Document Understanding AI to iterate and optimize for quality. - - Attributes: - uri (str): - Currently supports Google Cloud Storage URI of the form - ``gs://bucket_name/object_name``. Object versioning is not - supported. See `Google Cloud Storage Request - URIs `__ - for more info. - content (bytes): - Inline document content, represented as a stream of bytes. - Note: As with all ``bytes`` fields, protobuffers use a pure - binary representation, whereas JSON representations use - base64. - mime_type (str): - An IANA published MIME type (also referred to - as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. - text (str): - UTF-8 encoded text in reading order from the - document. - text_styles (Sequence[google.cloud.documentai_v1beta2.types.Document.Style]): - Styles for the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - pages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page]): - Visual page layout for the - [Document][google.cloud.documentai.v1beta2.Document]. - entities (Sequence[google.cloud.documentai_v1beta2.types.Document.Entity]): - A list of entities detected on - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - For document shards, entities in this list may cross shard - boundaries. - entity_relations (Sequence[google.cloud.documentai_v1beta2.types.Document.EntityRelation]): - Relationship among - [Document.entities][google.cloud.documentai.v1beta2.Document.entities]. - shard_info (google.cloud.documentai_v1beta2.types.Document.ShardInfo): - Information about the sharding if this - document is sharded part of a larger document. - If the document is not sharded, this message is - not specified. - labels (Sequence[google.cloud.documentai_v1beta2.types.Document.Label]): - [Label][google.cloud.documentai.v1beta2.Document.Label]s for - this document. - error (google.rpc.status_pb2.Status): - Any error that occurred while processing this - document. - """ - - class ShardInfo(proto.Message): - r"""For a large document, sharding may be performed to produce - several document shards. Each document shard contains this field - to detail which shard it is. - - Attributes: - shard_index (int): - The 0-based index of this shard. - shard_count (int): - Total number of shards. - text_offset (int): - The index of the first character in - [Document.text][google.cloud.documentai.v1beta2.Document.text] - in the overall document global text. - """ - - shard_index = proto.Field( - proto.INT64, - number=1, - ) - shard_count = proto.Field( - proto.INT64, - number=2, - ) - text_offset = proto.Field( - proto.INT64, - number=3, - ) - - class Label(proto.Message): - r"""Label attaches schema information and/or other metadata to segments - within a [Document][google.cloud.documentai.v1beta2.Document]. - Multiple [Label][google.cloud.documentai.v1beta2.Document.Label]s on - a single field can denote either different labels, different - instances of the same label created at different times, or some - combination of both. - - Attributes: - automl_model (str): - Label is generated AutoML model. This field stores the full - resource name of the AutoML model. - - Format: - ``projects/{project-id}/locations/{location-id}/models/{model-id}`` - name (str): - Name of the label. - When the label is generated from AutoML Text - Classification model, this field represents the - name of the category. - confidence (float): - Confidence score between 0 and 1 for label - assignment. - """ - - automl_model = proto.Field( - proto.STRING, - number=2, - oneof='source', - ) - name = proto.Field( - proto.STRING, - number=1, - ) - confidence = proto.Field( - proto.FLOAT, - number=3, - ) - - class Style(proto.Message): - r"""Annotation for common text style attributes. This adheres to - CSS conventions as much as possible. - - Attributes: - text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): - Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - color (google.type.color_pb2.Color): - Text color. - background_color (google.type.color_pb2.Color): - Text background color. - font_weight (str): - Font weight. Possible values are normal, bold, bolder, and - lighter. https://www.w3schools.com/cssref/pr_font_weight.asp - text_style (str): - Text style. Possible values are normal, italic, and oblique. - https://www.w3schools.com/cssref/pr_font_font-style.asp - text_decoration (str): - Text decoration. Follows CSS standard. - https://www.w3schools.com/cssref/pr_text_text-decoration.asp - font_size (google.cloud.documentai_v1beta2.types.Document.Style.FontSize): - Font size. - """ - - class FontSize(proto.Message): - r"""Font size with unit. - Attributes: - size (float): - Font size for the text. - unit (str): - Unit for the font size. Follows CSS naming - (in, px, pt, etc.). - """ - - size = proto.Field( - proto.FLOAT, - number=1, - ) - unit = proto.Field( - proto.STRING, - number=2, - ) - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - color = proto.Field( - proto.MESSAGE, - number=2, - message=color_pb2.Color, - ) - background_color = proto.Field( - proto.MESSAGE, - number=3, - message=color_pb2.Color, - ) - font_weight = proto.Field( - proto.STRING, - number=4, - ) - text_style = proto.Field( - proto.STRING, - number=5, - ) - text_decoration = proto.Field( - proto.STRING, - number=6, - ) - font_size = proto.Field( - proto.MESSAGE, - number=7, - message='Document.Style.FontSize', - ) - - class Page(proto.Message): - r"""A page in a [Document][google.cloud.documentai.v1beta2.Document]. - Attributes: - page_number (int): - 1-based index for current - [Page][google.cloud.documentai.v1beta2.Document.Page] in a - parent [Document][google.cloud.documentai.v1beta2.Document]. - Useful when a page is taken out of a - [Document][google.cloud.documentai.v1beta2.Document] for - individual processing. - dimension (google.cloud.documentai_v1beta2.types.Document.Page.Dimension): - Physical dimension of the page. - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for the page. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - blocks (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Block]): - A list of visually detected text blocks on - the page. A block has a set of lines (collected - into paragraphs) that have a common line-spacing - and orientation. - paragraphs (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Paragraph]): - A list of visually detected text paragraphs - on the page. A collection of lines that a human - would perceive as a paragraph. - lines (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Line]): - A list of visually detected text lines on the - page. A collection of tokens that a human would - perceive as a line. - tokens (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Token]): - A list of visually detected tokens on the - page. - visual_elements (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.VisualElement]): - A list of detected non-text visual elements - e.g. checkbox, signature etc. on the page. - tables (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table]): - A list of visually detected tables on the - page. - form_fields (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.FormField]): - A list of visually detected form fields on - the page. - """ - - class Dimension(proto.Message): - r"""Dimension for the page. - Attributes: - width (float): - Page width. - height (float): - Page height. - unit (str): - Dimension unit. - """ - - width = proto.Field( - proto.FLOAT, - number=1, - ) - height = proto.Field( - proto.FLOAT, - number=2, - ) - unit = proto.Field( - proto.STRING, - number=3, - ) - - class Layout(proto.Message): - r"""Visual element describing a layout unit on a page. - Attributes: - text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): - Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - confidence (float): - Confidence of the current - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - within context of the object this layout is for. e.g. - confidence can be for a single token, a table, a visual - element, etc. depending on context. Range [0, 1]. - bounding_poly (google.cloud.documentai_v1beta2.types.BoundingPoly): - The bounding polygon for the - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout]. - orientation (google.cloud.documentai_v1beta2.types.Document.Page.Layout.Orientation): - Detected orientation for the - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout]. - id (str): - Optional. This is the identifier used by referencing - [PageAnchor][google.cloud.documentai.v1beta2.Document.PageAnchor]s. - """ - class Orientation(proto.Enum): - r"""Detected human reading orientation.""" - ORIENTATION_UNSPECIFIED = 0 - PAGE_UP = 1 - PAGE_RIGHT = 2 - PAGE_DOWN = 3 - PAGE_LEFT = 4 - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - orientation = proto.Field( - proto.ENUM, - number=4, - enum='Document.Page.Layout.Orientation', - ) - id = proto.Field( - proto.STRING, - number=5, - ) - - class Block(proto.Message): - r"""A block has a set of lines (collected into paragraphs) that - have a common line-spacing and orientation. - - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [Block][google.cloud.documentai.v1beta2.Document.Page.Block]. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - - class Paragraph(proto.Message): - r"""A collection of lines that a human would perceive as a - paragraph. - - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [Paragraph][google.cloud.documentai.v1beta2.Document.Page.Paragraph]. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - - class Line(proto.Message): - r"""A collection of tokens that a human would perceive as a line. - Does not cross column boundaries, can be horizontal, vertical, - etc. - - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [Line][google.cloud.documentai.v1beta2.Document.Page.Line]. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - - class Token(proto.Message): - r"""A detected token. - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. - detected_break (google.cloud.documentai_v1beta2.types.Document.Page.Token.DetectedBreak): - Detected break at the end of a - [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - class DetectedBreak(proto.Message): - r"""Detected break at the end of a - [Token][google.cloud.documentai.v1beta2.Document.Page.Token]. - - Attributes: - type_ (google.cloud.documentai_v1beta2.types.Document.Page.Token.DetectedBreak.Type): - Detected break type. - """ - class Type(proto.Enum): - r"""Enum to denote the type of break found.""" - TYPE_UNSPECIFIED = 0 - SPACE = 1 - WIDE_SPACE = 2 - HYPHEN = 3 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='Document.Page.Token.DetectedBreak.Type', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Token.DetectedBreak', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - - class VisualElement(proto.Message): - r"""Detected non-text visual elements e.g. checkbox, signature - etc. on the page. - - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement]. - type_ (str): - Type of the - [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement]. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - - class Table(proto.Message): - r"""A table representation similar to HTML table structure. - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [Table][google.cloud.documentai.v1beta2.Document.Page.Table]. - header_rows (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableRow]): - Header rows of the table. - body_rows (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableRow]): - Body rows of the table. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - class TableRow(proto.Message): - r"""A row of table cells. - Attributes: - cells (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.Table.TableCell]): - Cells that make up this row. - """ - - cells = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.Page.Table.TableCell', - ) - - class TableCell(proto.Message): - r"""A cell representation inside the table. - Attributes: - layout (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for - [TableCell][google.cloud.documentai.v1beta2.Document.Page.Table.TableCell]. - row_span (int): - How many rows this cell spans. - col_span (int): - How many columns this cell spans. - detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - row_span = proto.Field( - proto.INT32, - number=2, - ) - col_span = proto.Field( - proto.INT32, - number=3, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - header_rows = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.Table.TableRow', - ) - body_rows = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.Table.TableRow', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - class FormField(proto.Message): - r"""A form field detected on the page. - Attributes: - field_name (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for the - [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] - name. e.g. ``Address``, ``Email``, ``Grand total``, - ``Phone number``, etc. - field_value (google.cloud.documentai_v1beta2.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] - for the - [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] - value. - name_detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages for name - together with confidence. - value_detected_languages (Sequence[google.cloud.documentai_v1beta2.types.Document.Page.DetectedLanguage]): - A list of detected languages for value - together with confidence. - value_type (str): - If the value is non-textual, this field represents the type. - Current valid values are: - - - blank (this indicates the field_value is normal text) - - "unfilled_checkbox" - - "filled_checkbox". - corrected_key_text (str): - An internal field, created for Labeling UI to - export key text. - corrected_value_text (str): - An internal field, created for Labeling UI to - export value text. - """ - - field_name = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - field_value = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Layout', - ) - name_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - value_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - value_type = proto.Field( - proto.STRING, - number=5, - ) - corrected_key_text = proto.Field( - proto.STRING, - number=6, - ) - corrected_value_text = proto.Field( - proto.STRING, - number=7, - ) - - 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 - more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - confidence (float): - Confidence of detected language. Range [0, 1]. - """ - - language_code = proto.Field( - proto.STRING, - number=1, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - - page_number = proto.Field( - proto.INT32, - number=1, - ) - dimension = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Dimension', - ) - layout = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='Document.Page.Block', - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=6, - message='Document.Page.Paragraph', - ) - lines = proto.RepeatedField( - proto.MESSAGE, - number=7, - message='Document.Page.Line', - ) - tokens = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='Document.Page.Token', - ) - visual_elements = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Document.Page.VisualElement', - ) - tables = proto.RepeatedField( - proto.MESSAGE, - number=10, - message='Document.Page.Table', - ) - form_fields = proto.RepeatedField( - proto.MESSAGE, - number=11, - message='Document.Page.FormField', - ) - - class Entity(proto.Message): - r"""A phrase in the text that is a known entity type, such as a - person, an organization, or location. - - Attributes: - text_anchor (google.cloud.documentai_v1beta2.types.Document.TextAnchor): - Provenance of the entity. Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - type_ (str): - Entity type from a schema e.g. ``Address``. - mention_text (str): - Text value in the document e.g. ``1600 Amphitheatre Pkwy``. - mention_id (str): - Deprecated. Use ``id`` field instead. - confidence (float): - Optional. Confidence of detected Schema entity. Range [0, - 1]. - page_anchor (google.cloud.documentai_v1beta2.types.Document.PageAnchor): - Optional. Represents the provenance of this - entity wrt. the location on the page where it - was found. - id (str): - Optional. Canonical id. This will be a unique - value in the entity list for this document. - bounding_poly_for_demo_frontend (google.cloud.documentai_v1beta2.types.BoundingPoly): - Optional. Temporary field to store the - bounding poly for short-term POCs. Used by the - frontend only. Do not use before you talk to - ybo@ and lukasr@. - """ - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - mention_text = proto.Field( - proto.STRING, - number=3, - ) - mention_id = proto.Field( - proto.STRING, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - page_anchor = proto.Field( - proto.MESSAGE, - number=6, - message='Document.PageAnchor', - ) - id = proto.Field( - proto.STRING, - number=7, - ) - bounding_poly_for_demo_frontend = proto.Field( - proto.MESSAGE, - number=8, - message=geometry.BoundingPoly, - ) - - class EntityRelation(proto.Message): - r"""Relationship between - [Entities][google.cloud.documentai.v1beta2.Document.Entity]. - - Attributes: - subject_id (str): - Subject entity id. - object_id (str): - Object entity id. - relation (str): - Relationship description. - """ - - subject_id = proto.Field( - proto.STRING, - number=1, - ) - object_id = proto.Field( - proto.STRING, - number=2, - ) - relation = proto.Field( - proto.STRING, - number=3, - ) - - class TextAnchor(proto.Message): - r"""Text reference indexing into the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - - Attributes: - text_segments (Sequence[google.cloud.documentai_v1beta2.types.Document.TextAnchor.TextSegment]): - The text segments from the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - """ - - class TextSegment(proto.Message): - r"""A text segment in the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. The - indices may be out of bounds which indicate that the text extends - into another document shard for large sharded documents. See - [ShardInfo.text_offset][google.cloud.documentai.v1beta2.Document.ShardInfo.text_offset] - - Attributes: - start_index (int): - [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] - start UTF-8 char index in the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - end_index (int): - [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] - half open end UTF-8 char index in the - [Document.text][google.cloud.documentai.v1beta2.Document.text]. - """ - - start_index = proto.Field( - proto.INT64, - number=1, - ) - end_index = proto.Field( - proto.INT64, - number=2, - ) - - text_segments = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.TextAnchor.TextSegment', - ) - - class PageAnchor(proto.Message): - r"""Referencing elements in - [Document.pages][google.cloud.documentai.v1beta2.Document.pages]. - - Attributes: - page_refs (Sequence[google.cloud.documentai_v1beta2.types.Document.PageAnchor.PageRef]): - One or more references to visual page - elements - """ - - class PageRef(proto.Message): - r"""Represents a weak reference to a page element within a - document. - - Attributes: - page (int): - Required. Index into the - [Document.pages][google.cloud.documentai.v1beta2.Document.pages] - element - layout_type (google.cloud.documentai_v1beta2.types.Document.PageAnchor.PageRef.LayoutType): - Optional. The type of the layout element that - is being referenced. If not specified the whole - page is assumed to be referenced. - layout_id (str): - Optional. The - [Page.Layout.id][google.cloud.documentai.v1beta2.Document.Page.Layout.id] - on the page that this element references. If - [LayoutRef.type][] is specified this id must also be - specified. - """ - class LayoutType(proto.Enum): - r"""The type of layout that is being referenced.""" - LAYOUT_TYPE_UNSPECIFIED = 0 - BLOCK = 1 - PARAGRAPH = 2 - LINE = 3 - TOKEN = 4 - VISUAL_ELEMENT = 5 - TABLE = 6 - FORM_FIELD = 7 - - page = proto.Field( - proto.INT64, - number=1, - ) - layout_type = proto.Field( - proto.ENUM, - number=2, - enum='Document.PageAnchor.PageRef.LayoutType', - ) - layout_id = proto.Field( - proto.STRING, - number=3, - ) - - page_refs = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.PageAnchor.PageRef', - ) - - uri = proto.Field( - proto.STRING, - number=1, - oneof='source', - ) - content = proto.Field( - proto.BYTES, - number=2, - oneof='source', - ) - mime_type = proto.Field( - proto.STRING, - number=3, - ) - text = proto.Field( - proto.STRING, - number=4, - ) - text_styles = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Style, - ) - pages = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=Page, - ) - entities = proto.RepeatedField( - proto.MESSAGE, - number=7, - message=Entity, - ) - entity_relations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=EntityRelation, - ) - shard_info = proto.Field( - proto.MESSAGE, - number=9, - message=ShardInfo, - ) - labels = proto.RepeatedField( - proto.MESSAGE, - number=11, - message=Label, - ) - error = proto.Field( - proto.MESSAGE, - number=10, - message=status_pb2.Status, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py deleted file mode 100644 index 1b97579c..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/document_understanding.py +++ /dev/null @@ -1,546 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1beta2.types import geometry -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta2', - manifest={ - 'BatchProcessDocumentsRequest', - 'ProcessDocumentRequest', - 'BatchProcessDocumentsResponse', - 'ProcessDocumentResponse', - 'OcrParams', - 'TableExtractionParams', - 'TableBoundHint', - 'FormExtractionParams', - 'KeyValuePairHint', - 'EntityExtractionParams', - 'AutoMlParams', - 'InputConfig', - 'OutputConfig', - 'GcsSource', - 'GcsDestination', - 'OperationMetadata', - }, -) - - -class BatchProcessDocumentsRequest(proto.Message): - r"""Request to batch process documents as an asynchronous operation. The - output is written to Cloud Storage as JSON in the [Document] format. - - Attributes: - requests (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentRequest]): - Required. Individual requests for each - document. - parent (str): - Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no location is specified, a region will be chosen - automatically. - """ - - requests = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ProcessDocumentRequest', - ) - parent = proto.Field( - proto.STRING, - number=2, - ) - - -class ProcessDocumentRequest(proto.Message): - r"""Request to process one document. - Attributes: - parent (str): - Target project and location to make a call. - - Format: ``projects/{project-id}/locations/{location-id}``. - - If no location is specified, a region will be chosen - automatically. This field is only populated when used in - ProcessDocument method. - input_config (google.cloud.documentai_v1beta2.types.InputConfig): - Required. Information about the input file. - output_config (google.cloud.documentai_v1beta2.types.OutputConfig): - Optional. The desired output location. This - field is only needed in - BatchProcessDocumentsRequest. - document_type (str): - Specifies a known document type for deeper - structure detection. Valid values are currently - "general" and "invoice". If not provided, - "general"\ is used as default. If any other - value is given, the request is rejected. - table_extraction_params (google.cloud.documentai_v1beta2.types.TableExtractionParams): - Controls table extraction behavior. If not - specified, the system will decide reasonable - defaults. - form_extraction_params (google.cloud.documentai_v1beta2.types.FormExtractionParams): - Controls form extraction behavior. If not - specified, the system will decide reasonable - defaults. - entity_extraction_params (google.cloud.documentai_v1beta2.types.EntityExtractionParams): - Controls entity extraction behavior. If not - specified, the system will decide reasonable - defaults. - ocr_params (google.cloud.documentai_v1beta2.types.OcrParams): - Controls OCR behavior. If not specified, the - system will decide reasonable defaults. - automl_params (google.cloud.documentai_v1beta2.types.AutoMlParams): - Controls AutoML model prediction behavior. - AutoMlParams cannot be used together with other - Params. - """ - - parent = proto.Field( - proto.STRING, - number=9, - ) - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - output_config = proto.Field( - proto.MESSAGE, - number=2, - message='OutputConfig', - ) - document_type = proto.Field( - proto.STRING, - number=3, - ) - table_extraction_params = proto.Field( - proto.MESSAGE, - number=4, - message='TableExtractionParams', - ) - form_extraction_params = proto.Field( - proto.MESSAGE, - number=5, - message='FormExtractionParams', - ) - entity_extraction_params = proto.Field( - proto.MESSAGE, - number=6, - message='EntityExtractionParams', - ) - ocr_params = proto.Field( - proto.MESSAGE, - number=7, - message='OcrParams', - ) - automl_params = proto.Field( - proto.MESSAGE, - number=8, - message='AutoMlParams', - ) - - -class BatchProcessDocumentsResponse(proto.Message): - r"""Response to an batch document processing request. This is - returned in the LRO Operation after the operation is complete. - - Attributes: - responses (Sequence[google.cloud.documentai_v1beta2.types.ProcessDocumentResponse]): - Responses for each individual document. - """ - - responses = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='ProcessDocumentResponse', - ) - - -class ProcessDocumentResponse(proto.Message): - r"""Response to a single document processing request. - Attributes: - input_config (google.cloud.documentai_v1beta2.types.InputConfig): - Information about the input file. This is the - same as the corresponding input config in the - request. - output_config (google.cloud.documentai_v1beta2.types.OutputConfig): - The output location of the parsed responses. The responses - are written to this location as JSON-serialized ``Document`` - objects. - """ - - input_config = proto.Field( - proto.MESSAGE, - number=1, - message='InputConfig', - ) - output_config = proto.Field( - proto.MESSAGE, - number=2, - message='OutputConfig', - ) - - -class OcrParams(proto.Message): - r"""Parameters to control Optical Character Recognition (OCR) - behavior. - - Attributes: - language_hints (Sequence[str]): - List of languages to use for OCR. In most cases, an empty - value yields the best results since it enables automatic - language detection. For languages based on the Latin - alphabet, setting ``language_hints`` is not needed. In rare - cases, when the language of the text in the image is known, - setting a hint will help get better results (although it - will be a significant hindrance if the hint is wrong). - Document processing returns an error if one or more of the - specified languages is not one of the supported languages. - """ - - language_hints = proto.RepeatedField( - proto.STRING, - number=1, - ) - - -class TableExtractionParams(proto.Message): - r"""Parameters to control table extraction behavior. - Attributes: - enabled (bool): - Whether to enable table extraction. - table_bound_hints (Sequence[google.cloud.documentai_v1beta2.types.TableBoundHint]): - Optional. Table bounding box hints that can - be provided to complex cases which our algorithm - cannot locate the table(s) in. - header_hints (Sequence[str]): - Optional. Table header hints. The extraction - will bias towards producing these terms as table - headers, which may improve accuracy. - model_version (str): - Model version of the table extraction system. - Default is "builtin/stable". Specify - "builtin/latest" for the latest model. - """ - - enabled = proto.Field( - proto.BOOL, - number=1, - ) - table_bound_hints = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='TableBoundHint', - ) - header_hints = proto.RepeatedField( - proto.STRING, - number=3, - ) - model_version = proto.Field( - proto.STRING, - number=4, - ) - - -class TableBoundHint(proto.Message): - r"""A hint for a table bounding box on the page for table - parsing. - - Attributes: - page_number (int): - Optional. Page number for multi-paged inputs - this hint applies to. If not provided, this hint - will apply to all pages by default. This value - is 1-based. - bounding_box (google.cloud.documentai_v1beta2.types.BoundingPoly): - Bounding box hint for a table on this page. The coordinates - must be normalized to [0,1] and the bounding box must be an - axis-aligned rectangle. - """ - - page_number = proto.Field( - proto.INT32, - number=1, - ) - bounding_box = proto.Field( - proto.MESSAGE, - number=2, - message=geometry.BoundingPoly, - ) - - -class FormExtractionParams(proto.Message): - r"""Parameters to control form extraction behavior. - Attributes: - enabled (bool): - Whether to enable form extraction. - key_value_pair_hints (Sequence[google.cloud.documentai_v1beta2.types.KeyValuePairHint]): - User can provide pairs of (key text, value type) to improve - the parsing result. - - For example, if a document has a field called "Date" that - holds a date value and a field called "Amount" that may hold - either a currency value (e.g., "$500.00") or a simple number - value (e.g., "20"), you could use the following hints: [ - {"key": "Date", value_types: [ "DATE"]}, {"key": "Amount", - "value_types": [ "PRICE", "NUMBER" ]} ] - - If the value type is unknown, but you want to provide hints - for the keys, you can leave the value_types field blank. - e.g. {"key": "Date", "value_types": []} - model_version (str): - Model version of the form extraction system. Default is - "builtin/stable". Specify "builtin/latest" for the latest - model. For custom form models, specify: - “custom/{model_name}". Model name format is - "bucket_name/path/to/modeldir" corresponding to - "gs://bucket_name/path/to/modeldir" where annotated examples - are stored. - """ - - enabled = proto.Field( - proto.BOOL, - number=1, - ) - key_value_pair_hints = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='KeyValuePairHint', - ) - model_version = proto.Field( - proto.STRING, - number=3, - ) - - -class KeyValuePairHint(proto.Message): - r"""User-provided hint for key value pair. - Attributes: - key (str): - The key text for the hint. - value_types (Sequence[str]): - Type of the value. This is case-insensitive, and could be - one of: ADDRESS, LOCATION, ORGANIZATION, PERSON, - PHONE_NUMBER, ID, NUMBER, EMAIL, PRICE, TERMS, DATE, NAME. - Types not in this list will be ignored. - """ - - key = proto.Field( - proto.STRING, - number=1, - ) - value_types = proto.RepeatedField( - proto.STRING, - number=2, - ) - - -class EntityExtractionParams(proto.Message): - r"""Parameters to control entity extraction behavior. - Attributes: - enabled (bool): - Whether to enable entity extraction. - model_version (str): - Model version of the entity extraction. - Default is "builtin/stable". Specify - "builtin/latest" for the latest model. - """ - - enabled = proto.Field( - proto.BOOL, - number=1, - ) - model_version = proto.Field( - proto.STRING, - number=2, - ) - - -class AutoMlParams(proto.Message): - r"""Parameters to control AutoML model prediction behavior. - Attributes: - model (str): - Resource name of the AutoML model. - - Format: - ``projects/{project-id}/locations/{location-id}/models/{model-id}``. - """ - - model = proto.Field( - proto.STRING, - number=1, - ) - - -class InputConfig(proto.Message): - r"""The desired input location and metadata. - Attributes: - gcs_source (google.cloud.documentai_v1beta2.types.GcsSource): - The Google Cloud Storage location to read the - input from. This must be a single file. - contents (bytes): - Content in bytes, represented as a stream of bytes. Note: As - with all ``bytes`` fields, proto buffer messages use a pure - binary representation, whereas JSON representations use - base64. - - This field only works for synchronous ProcessDocument - method. - mime_type (str): - Required. Mimetype of the input. Current supported mimetypes - are application/pdf, image/tiff, and image/gif. In addition, - application/json type is supported for requests with - [ProcessDocumentRequest.automl_params][google.cloud.documentai.v1beta2.ProcessDocumentRequest.automl_params] - field set. The JSON file needs to be in - [Document][google.cloud.documentai.v1beta2.Document] format. - """ - - gcs_source = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='GcsSource', - ) - contents = proto.Field( - proto.BYTES, - number=3, - oneof='source', - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class OutputConfig(proto.Message): - r"""The desired output location and metadata. - Attributes: - gcs_destination (google.cloud.documentai_v1beta2.types.GcsDestination): - The Google Cloud Storage location to write - the output to. - pages_per_shard (int): - The max number of pages to include into each output Document - shard JSON on Google Cloud Storage. - - The valid range is [1, 100]. If not specified, the default - value is 20. - - For example, for one pdf file with 100 pages, 100 parsed - pages will be produced. If ``pages_per_shard`` = 20, then 5 - Document shard JSON files each containing 20 parsed pages - will be written under the prefix - [OutputConfig.gcs_destination.uri][] and suffix - pages-x-to-y.json where x and y are 1-indexed page numbers. - - Example GCS outputs with 157 pages and pages_per_shard = 50: - - pages-001-to-050.json pages-051-to-100.json - pages-101-to-150.json pages-151-to-157.json - """ - - gcs_destination = proto.Field( - proto.MESSAGE, - number=1, - oneof='destination', - message='GcsDestination', - ) - pages_per_shard = proto.Field( - proto.INT32, - number=2, - ) - - -class GcsSource(proto.Message): - r"""The Google Cloud Storage location where the input file will - be read from. - - Attributes: - uri (str): - - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class GcsDestination(proto.Message): - r"""The Google Cloud Storage location where the output file will - be written to. - - Attributes: - uri (str): - - """ - - uri = proto.Field( - proto.STRING, - number=1, - ) - - -class OperationMetadata(proto.Message): - r"""Contains metadata for the BatchProcessDocuments operation. - Attributes: - state (google.cloud.documentai_v1beta2.types.OperationMetadata.State): - The state of the current batch processing. - state_message (str): - A message providing more details about the - current state of processing. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - """ - class State(proto.Enum): - r"""""" - STATE_UNSPECIFIED = 0 - ACCEPTED = 1 - WAITING = 2 - RUNNING = 3 - SUCCEEDED = 4 - CANCELLED = 5 - FAILED = 6 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py b/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py deleted file mode 100644 index 4bf1ff65..00000000 --- a/owl-bot-staging/v1beta2/google/cloud/documentai_v1beta2/types/geometry.py +++ /dev/null @@ -1,94 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta2', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - }, -) - - -class Vertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the vertex coordinates are in the same scale as the - original image. - - Attributes: - x (int): - X coordinate. - y (int): - Y coordinate. - """ - - x = proto.Field( - proto.INT32, - number=1, - ) - y = proto.Field( - proto.INT32, - number=2, - ) - - -class NormalizedVertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the normalized vertex coordinates are relative to the - original image and range from 0 to 1. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate. - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - - -class BoundingPoly(proto.Message): - r"""A bounding polygon for the detected image annotation. - Attributes: - vertices (Sequence[google.cloud.documentai_v1beta2.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.documentai_v1beta2.types.NormalizedVertex]): - The bounding polygon normalized vertices. - """ - - vertices = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Vertex', - ) - normalized_vertices = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='NormalizedVertex', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta2/mypy.ini b/owl-bot-staging/v1beta2/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1beta2/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1beta2/noxfile.py b/owl-bot-staging/v1beta2/noxfile.py deleted file mode 100644 index 3b318e44..00000000 --- a/owl-bot-staging/v1beta2/noxfile.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", -] - -@nox.session(python=['3.6', '3.7', '3.8', '3.9']) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/documentai_v1beta2/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python='3.7') -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=['3.6', '3.7']) -def mypy(session): - """Run the type checker.""" - session.install('mypy', 'types-pkg_resources') - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python='3.6') -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx<3.0.0", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) diff --git a/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py b/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py deleted file mode 100644 index 22080e57..00000000 --- a/owl-bot-staging/v1beta2/scripts/fixup_documentai_v1beta2_keywords.py +++ /dev/null @@ -1,177 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class documentaiCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_process_documents': ('requests', 'parent', ), - 'process_document': ('input_config', 'parent', 'output_config', 'document_type', 'table_extraction_params', 'form_extraction_params', 'entity_extraction_params', 'ocr_params', 'automl_params', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: not a.keyword.value in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=documentaiCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the documentai client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1beta2/setup.py b/owl-bot-staging/v1beta2/setup.py deleted file mode 100644 index 90b5b3cf..00000000 --- a/owl-bot-staging/v1beta2/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os -import setuptools # type: ignore - -version = '0.1.0' - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, 'README.rst') -with io.open(readme_filename, encoding='utf-8') as readme_file: - readme = readme_file.read() - -setuptools.setup( - name='google-cloud-documentai', - version=version, - long_description=readme, - packages=setuptools.PEP420PackageFinder.find(), - namespace_packages=('google', 'google.cloud'), - platforms='Posix; MacOS X; Windows', - include_package_data=True, - install_requires=( - 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', - 'libcst >= 0.2.5', - 'proto-plus >= 1.15.0', - 'packaging >= 14.3', ), - python_requires='>=3.6', - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1beta2/tests/__init__.py b/owl-bot-staging/v1beta2/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta2/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta2/tests/unit/__init__.py b/owl-bot-staging/v1beta2/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta2/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py b/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta2/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py deleted file mode 100644 index a6d25a67..00000000 --- a/owl-bot-staging/v1beta2/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ /dev/null @@ -1,1342 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import mock -import packaging.version - -import grpc -from grpc.experimental import aio -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.documentai_v1beta2.services.document_understanding_service import DocumentUnderstandingServiceAsyncClient -from google.cloud.documentai_v1beta2.services.document_understanding_service import DocumentUnderstandingServiceClient -from google.cloud.documentai_v1beta2.services.document_understanding_service import transports -from google.cloud.documentai_v1beta2.services.document_understanding_service.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.documentai_v1beta2.types import document -from google.cloud.documentai_v1beta2.types import document_understanding -from google.cloud.documentai_v1beta2.types import geometry -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.rpc import status_pb2 # type: ignore -import google.auth - - -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(None) is None - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert DocumentUnderstandingServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - DocumentUnderstandingServiceClient, - DocumentUnderstandingServiceAsyncClient, -]) -def test_document_understanding_service_client_from_service_account_info(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'us-documentai.googleapis.com:443' - - -@pytest.mark.parametrize("client_class", [ - DocumentUnderstandingServiceClient, - DocumentUnderstandingServiceAsyncClient, -]) -def test_document_understanding_service_client_service_account_always_use_jwt(client_class): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), - (transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_understanding_service_client_service_account_always_use_jwt_true(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - -@pytest.mark.parametrize("client_class", [ - DocumentUnderstandingServiceClient, - DocumentUnderstandingServiceAsyncClient, -]) -def test_document_understanding_service_client_from_service_account_file(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'us-documentai.googleapis.com:443' - - -def test_document_understanding_service_client_get_transport_class(): - transport = DocumentUnderstandingServiceClient.get_transport_class() - available_transports = [ - transports.DocumentUnderstandingServiceGrpcTransport, - ] - assert transport in available_transports - - transport = DocumentUnderstandingServiceClient.get_transport_class("grpc") - assert transport == transports.DocumentUnderstandingServiceGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), - (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(DocumentUnderstandingServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceClient)) -@mock.patch.object(DocumentUnderstandingServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceAsyncClient)) -def test_document_understanding_service_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(DocumentUnderstandingServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(DocumentUnderstandingServiceClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc", "true"), - (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc", "false"), - (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(DocumentUnderstandingServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceClient)) -@mock.patch.object(DocumentUnderstandingServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentUnderstandingServiceAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_document_understanding_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), - (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_understanding_service_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentUnderstandingServiceClient, transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), - (DocumentUnderstandingServiceAsyncClient, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_understanding_service_client_client_options_credentials_file(client_class, transport_class, transport_name): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_document_understanding_service_client_client_options_from_dict(): - with mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = DocumentUnderstandingServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_batch_process_documents(transport: str = 'grpc', request_type=document_understanding.BatchProcessDocumentsRequest): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.BatchProcessDocumentsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - -def test_batch_process_documents_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - client.batch_process_documents() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.BatchProcessDocumentsRequest() - - -@pytest.mark.asyncio -async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_understanding.BatchProcessDocumentsRequest): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.BatchProcessDocumentsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_batch_process_documents_async_from_dict(): - await test_batch_process_documents_async(request_type=dict) - - -def test_batch_process_documents_field_headers(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_understanding.BatchProcessDocumentsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_batch_process_documents_field_headers_async(): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_understanding.BatchProcessDocumentsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -def test_batch_process_documents_flattened(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_process_documents( - requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].requests == [document_understanding.ProcessDocumentRequest(parent='parent_value')] - - -def test_batch_process_documents_flattened_error(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.batch_process_documents( - document_understanding.BatchProcessDocumentsRequest(), - requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], - ) - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_async(): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_process_documents( - requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].requests == [document_understanding.ProcessDocumentRequest(parent='parent_value')] - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_error_async(): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.batch_process_documents( - document_understanding.BatchProcessDocumentsRequest(), - requests=[document_understanding.ProcessDocumentRequest(parent='parent_value')], - ) - - -def test_process_document(transport: str = 'grpc', request_type=document_understanding.ProcessDocumentRequest): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document.Document( - mime_type='mime_type_value', - text='text_value', - uri='uri_value', - ) - response = client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.ProcessDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document.Document) - assert response.mime_type == 'mime_type_value' - assert response.text == 'text_value' - - -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - -def test_process_document_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - client.process_document() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.ProcessDocumentRequest() - - -@pytest.mark.asyncio -async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_understanding.ProcessDocumentRequest): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document.Document( - mime_type='mime_type_value', - text='text_value', - )) - response = await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_understanding.ProcessDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document.Document) - assert response.mime_type == 'mime_type_value' - assert response.text == 'text_value' - - -@pytest.mark.asyncio -async def test_process_document_async_from_dict(): - await test_process_document_async(request_type=dict) - - -def test_process_document_field_headers(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_understanding.ProcessDocumentRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = document.Document() - client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_process_document_field_headers_async(): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_understanding.ProcessDocumentRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document.Document()) - await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentUnderstandingServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentUnderstandingServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = DocumentUnderstandingServiceClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.DocumentUnderstandingServiceGrpcTransport, - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.DocumentUnderstandingServiceGrpcTransport, - ) - -def test_document_understanding_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.DocumentUnderstandingServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_document_understanding_service_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.DocumentUnderstandingServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'batch_process_documents', - 'process_document', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - -@requires_google_auth_gte_1_25_0 -def test_document_understanding_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentUnderstandingServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentUnderstandingServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - ), - quota_project_id="octopus", - ) - - -def test_document_understanding_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentUnderstandingServiceTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_document_understanding_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentUnderstandingServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentUnderstandingServiceClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentUnderstandingServiceGrpcTransport, - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_document_understanding_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentUnderstandingServiceGrpcTransport, - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_understanding_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with(scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentUnderstandingServiceGrpcTransport, grpc_helpers), - (transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_document_understanding_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "us-documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - scopes=["1", "2"], - default_host="us-documentai.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) -def test_document_understanding_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - - -def test_document_understanding_service_host_no_port(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='us-documentai.googleapis.com'), - ) - assert client.transport._host == 'us-documentai.googleapis.com:443' - - -def test_document_understanding_service_host_with_port(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='us-documentai.googleapis.com:8000'), - ) - assert client.transport._host == 'us-documentai.googleapis.com:8000' - -def test_document_understanding_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentUnderstandingServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_document_understanding_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) -def test_document_understanding_service_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentUnderstandingServiceGrpcTransport, transports.DocumentUnderstandingServiceGrpcAsyncIOTransport]) -def test_document_understanding_service_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_document_understanding_service_grpc_lro_client(): - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_document_understanding_service_grpc_lro_async_client(): - client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc_asyncio', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsAsyncClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = DocumentUnderstandingServiceClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = DocumentUnderstandingServiceClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentUnderstandingServiceClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder, ) - actual = DocumentUnderstandingServiceClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = DocumentUnderstandingServiceClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentUnderstandingServiceClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization, ) - actual = DocumentUnderstandingServiceClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = DocumentUnderstandingServiceClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentUnderstandingServiceClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project, ) - actual = DocumentUnderstandingServiceClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = DocumentUnderstandingServiceClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentUnderstandingServiceClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "winkle" - location = "nautilus" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = DocumentUnderstandingServiceClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = DocumentUnderstandingServiceClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentUnderstandingServiceClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.DocumentUnderstandingServiceTransport, '_prep_wrapped_messages') as prep: - client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.DocumentUnderstandingServiceTransport, '_prep_wrapped_messages') as prep: - transport_class = DocumentUnderstandingServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) diff --git a/owl-bot-staging/v1beta3/.coveragerc b/owl-bot-staging/v1beta3/.coveragerc deleted file mode 100644 index ef619357..00000000 --- a/owl-bot-staging/v1beta3/.coveragerc +++ /dev/null @@ -1,17 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/documentai/__init__.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ - # Ignore pkg_resources exceptions. - # This is added at the module level as a safeguard for if someone - # generates the code and tries to run it without pip installing. This - # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound diff --git a/owl-bot-staging/v1beta3/MANIFEST.in b/owl-bot-staging/v1beta3/MANIFEST.in deleted file mode 100644 index af799d71..00000000 --- a/owl-bot-staging/v1beta3/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/documentai *.py -recursive-include google/cloud/documentai_v1beta3 *.py diff --git a/owl-bot-staging/v1beta3/README.rst b/owl-bot-staging/v1beta3/README.rst deleted file mode 100644 index 484a3c1c..00000000 --- a/owl-bot-staging/v1beta3/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Documentai API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Documentai API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/v1beta3/docs/conf.py b/owl-bot-staging/v1beta3/docs/conf.py deleted file mode 100644 index 0788579e..00000000 --- a/owl-bot-staging/v1beta3/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-documentai documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = "index" - -# General information about the project. -project = u"google-cloud-documentai" -copyright = u"2020, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-documentai-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - master_doc, - "google-cloud-documentai.tex", - u"google-cloud-documentai Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - master_doc, - "google-cloud-documentai", - u"Google Cloud Documentai Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - master_doc, - "google-cloud-documentai", - u"google-cloud-documentai Documentation", - author, - "google-cloud-documentai", - "GAPIC library for Google Cloud Documentai API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst deleted file mode 100644 index 4d8d5f9e..00000000 --- a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/document_processor_service.rst +++ /dev/null @@ -1,10 +0,0 @@ -DocumentProcessorService ------------------------------------------- - -.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service - :members: - :inherited-members: - -.. automodule:: google.cloud.documentai_v1beta3.services.document_processor_service.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst deleted file mode 100644 index d19a944b..00000000 --- a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Documentai v1beta3 API -================================================ -.. toctree:: - :maxdepth: 2 - - document_processor_service diff --git a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst b/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst deleted file mode 100644 index 7e22aabc..00000000 --- a/owl-bot-staging/v1beta3/docs/documentai_v1beta3/types.rst +++ /dev/null @@ -1,7 +0,0 @@ -Types for Google Cloud Documentai v1beta3 API -============================================= - -.. automodule:: google.cloud.documentai_v1beta3.types - :members: - :undoc-members: - :show-inheritance: diff --git a/owl-bot-staging/v1beta3/docs/index.rst b/owl-bot-staging/v1beta3/docs/index.rst deleted file mode 100644 index f4d3a84d..00000000 --- a/owl-bot-staging/v1beta3/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - documentai_v1beta3/services - documentai_v1beta3/types diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py deleted file mode 100644 index 36cee4ca..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai/__init__.py +++ /dev/null @@ -1,93 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.cloud.documentai_v1beta3.services.document_processor_service.client import DocumentProcessorServiceClient -from google.cloud.documentai_v1beta3.services.document_processor_service.async_client import DocumentProcessorServiceAsyncClient - -from google.cloud.documentai_v1beta3.types.document import Document -from google.cloud.documentai_v1beta3.types.document_io import BatchDocumentsInputConfig -from google.cloud.documentai_v1beta3.types.document_io import DocumentOutputConfig -from google.cloud.documentai_v1beta3.types.document_io import GcsDocument -from google.cloud.documentai_v1beta3.types.document_io import GcsDocuments -from google.cloud.documentai_v1beta3.types.document_io import GcsPrefix -from google.cloud.documentai_v1beta3.types.document_io import RawDocument -from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessMetadata -from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import BatchProcessResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import CreateProcessorRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import DeleteProcessorMetadata -from google.cloud.documentai_v1beta3.types.document_processor_service import DeleteProcessorRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorMetadata -from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import DisableProcessorResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorMetadata -from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import EnableProcessorResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import FetchProcessorTypesRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import FetchProcessorTypesResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import HumanReviewStatus -from google.cloud.documentai_v1beta3.types.document_processor_service import ListProcessorsRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import ListProcessorsResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import ProcessRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import ProcessResponse -from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentOperationMetadata -from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentRequest -from google.cloud.documentai_v1beta3.types.document_processor_service import ReviewDocumentResponse -from google.cloud.documentai_v1beta3.types.geometry import BoundingPoly -from google.cloud.documentai_v1beta3.types.geometry import NormalizedVertex -from google.cloud.documentai_v1beta3.types.geometry import Vertex -from google.cloud.documentai_v1beta3.types.operation_metadata import CommonOperationMetadata -from google.cloud.documentai_v1beta3.types.processor import Processor -from google.cloud.documentai_v1beta3.types.processor_type import ProcessorType - -__all__ = ('DocumentProcessorServiceClient', - 'DocumentProcessorServiceAsyncClient', - 'Document', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'RawDocument', - 'BatchProcessMetadata', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'CreateProcessorRequest', - 'DeleteProcessorMetadata', - 'DeleteProcessorRequest', - 'DisableProcessorMetadata', - 'DisableProcessorRequest', - 'DisableProcessorResponse', - 'EnableProcessorMetadata', - 'EnableProcessorRequest', - 'EnableProcessorResponse', - 'FetchProcessorTypesRequest', - 'FetchProcessorTypesResponse', - 'HumanReviewStatus', - 'ListProcessorsRequest', - 'ListProcessorsResponse', - 'ProcessRequest', - 'ProcessResponse', - 'ReviewDocumentOperationMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', - 'CommonOperationMetadata', - 'Processor', - 'ProcessorType', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed b/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py deleted file mode 100644 index 1dc95835..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/__init__.py +++ /dev/null @@ -1,94 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from .services.document_processor_service import DocumentProcessorServiceClient -from .services.document_processor_service import DocumentProcessorServiceAsyncClient - -from .types.document import Document -from .types.document_io import BatchDocumentsInputConfig -from .types.document_io import DocumentOutputConfig -from .types.document_io import GcsDocument -from .types.document_io import GcsDocuments -from .types.document_io import GcsPrefix -from .types.document_io import RawDocument -from .types.document_processor_service import BatchProcessMetadata -from .types.document_processor_service import BatchProcessRequest -from .types.document_processor_service import BatchProcessResponse -from .types.document_processor_service import CreateProcessorRequest -from .types.document_processor_service import DeleteProcessorMetadata -from .types.document_processor_service import DeleteProcessorRequest -from .types.document_processor_service import DisableProcessorMetadata -from .types.document_processor_service import DisableProcessorRequest -from .types.document_processor_service import DisableProcessorResponse -from .types.document_processor_service import EnableProcessorMetadata -from .types.document_processor_service import EnableProcessorRequest -from .types.document_processor_service import EnableProcessorResponse -from .types.document_processor_service import FetchProcessorTypesRequest -from .types.document_processor_service import FetchProcessorTypesResponse -from .types.document_processor_service import HumanReviewStatus -from .types.document_processor_service import ListProcessorsRequest -from .types.document_processor_service import ListProcessorsResponse -from .types.document_processor_service import ProcessRequest -from .types.document_processor_service import ProcessResponse -from .types.document_processor_service import ReviewDocumentOperationMetadata -from .types.document_processor_service import ReviewDocumentRequest -from .types.document_processor_service import ReviewDocumentResponse -from .types.geometry import BoundingPoly -from .types.geometry import NormalizedVertex -from .types.geometry import Vertex -from .types.operation_metadata import CommonOperationMetadata -from .types.processor import Processor -from .types.processor_type import ProcessorType - -__all__ = ( - 'DocumentProcessorServiceAsyncClient', -'BatchDocumentsInputConfig', -'BatchProcessMetadata', -'BatchProcessRequest', -'BatchProcessResponse', -'BoundingPoly', -'CommonOperationMetadata', -'CreateProcessorRequest', -'DeleteProcessorMetadata', -'DeleteProcessorRequest', -'DisableProcessorMetadata', -'DisableProcessorRequest', -'DisableProcessorResponse', -'Document', -'DocumentOutputConfig', -'DocumentProcessorServiceClient', -'EnableProcessorMetadata', -'EnableProcessorRequest', -'EnableProcessorResponse', -'FetchProcessorTypesRequest', -'FetchProcessorTypesResponse', -'GcsDocument', -'GcsDocuments', -'GcsPrefix', -'HumanReviewStatus', -'ListProcessorsRequest', -'ListProcessorsResponse', -'NormalizedVertex', -'ProcessRequest', -'ProcessResponse', -'Processor', -'ProcessorType', -'RawDocument', -'ReviewDocumentOperationMetadata', -'ReviewDocumentRequest', -'ReviewDocumentResponse', -'Vertex', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json deleted file mode 100644 index 1e2c3550..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/gapic_metadata.json +++ /dev/null @@ -1,113 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.documentai_v1beta3", - "protoPackage": "google.cloud.documentai.v1beta3", - "schema": "1.0", - "services": { - "DocumentProcessorService": { - "clients": { - "grpc": { - "libraryClient": "DocumentProcessorServiceClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "CreateProcessor": { - "methods": [ - "create_processor" - ] - }, - "DeleteProcessor": { - "methods": [ - "delete_processor" - ] - }, - "DisableProcessor": { - "methods": [ - "disable_processor" - ] - }, - "EnableProcessor": { - "methods": [ - "enable_processor" - ] - }, - "FetchProcessorTypes": { - "methods": [ - "fetch_processor_types" - ] - }, - "ListProcessors": { - "methods": [ - "list_processors" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - }, - "ReviewDocument": { - "methods": [ - "review_document" - ] - } - } - }, - "grpc-async": { - "libraryClient": "DocumentProcessorServiceAsyncClient", - "rpcs": { - "BatchProcessDocuments": { - "methods": [ - "batch_process_documents" - ] - }, - "CreateProcessor": { - "methods": [ - "create_processor" - ] - }, - "DeleteProcessor": { - "methods": [ - "delete_processor" - ] - }, - "DisableProcessor": { - "methods": [ - "disable_processor" - ] - }, - "EnableProcessor": { - "methods": [ - "enable_processor" - ] - }, - "FetchProcessorTypes": { - "methods": [ - "fetch_processor_types" - ] - }, - "ListProcessors": { - "methods": [ - "list_processors" - ] - }, - "ProcessDocument": { - "methods": [ - "process_document" - ] - }, - "ReviewDocument": { - "methods": [ - "review_document" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed deleted file mode 100644 index 81b45001..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-documentai package uses inline types. diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py deleted file mode 100644 index 4de65971..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py deleted file mode 100644 index 7217ec7c..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import DocumentProcessorServiceClient -from .async_client import DocumentProcessorServiceAsyncClient - -__all__ = ( - 'DocumentProcessorServiceClient', - 'DocumentProcessorServiceAsyncClient', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py deleted file mode 100644 index 9e2c7029..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ /dev/null @@ -1,939 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Sequence, Tuple, Type, Union -import pkg_resources - -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.types import document -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport -from .client import DocumentProcessorServiceClient - - -class DocumentProcessorServiceAsyncClient: - """Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - """ - - _client: DocumentProcessorServiceClient - - DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT - - human_review_config_path = staticmethod(DocumentProcessorServiceClient.human_review_config_path) - parse_human_review_config_path = staticmethod(DocumentProcessorServiceClient.parse_human_review_config_path) - processor_path = staticmethod(DocumentProcessorServiceClient.processor_path) - parse_processor_path = staticmethod(DocumentProcessorServiceClient.parse_processor_path) - processor_type_path = staticmethod(DocumentProcessorServiceClient.processor_type_path) - parse_processor_type_path = staticmethod(DocumentProcessorServiceClient.parse_processor_type_path) - common_billing_account_path = staticmethod(DocumentProcessorServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(DocumentProcessorServiceClient.parse_common_billing_account_path) - common_folder_path = staticmethod(DocumentProcessorServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(DocumentProcessorServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(DocumentProcessorServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(DocumentProcessorServiceClient.parse_common_organization_path) - common_project_path = staticmethod(DocumentProcessorServiceClient.common_project_path) - parse_common_project_path = staticmethod(DocumentProcessorServiceClient.parse_common_project_path) - common_location_path = staticmethod(DocumentProcessorServiceClient.common_location_path) - parse_common_location_path = staticmethod(DocumentProcessorServiceClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceAsyncClient: The constructed client. - """ - return DocumentProcessorServiceClient.from_service_account_info.__func__(DocumentProcessorServiceAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceAsyncClient: The constructed client. - """ - return DocumentProcessorServiceClient.from_service_account_file.__func__(DocumentProcessorServiceAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentProcessorServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentProcessorServiceTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient)) - - def __init__(self, *, - credentials: ga_credentials.Credentials = None, - transport: Union[str, DocumentProcessorServiceTransport] = "grpc_asyncio", - client_options: ClientOptions = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document processor service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.DocumentProcessorServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = DocumentProcessorServiceClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def process_document(self, - request: document_processor_service.ProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.ProcessResponse: - r"""Processes a single document. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.ProcessRequest`): - The request object. Request message for the process - document method. - name (:class:`str`): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.ProcessResponse: - Response message for the process - document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.ProcessRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def batch_process_documents(self, - request: document_processor_service.BatchProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.BatchProcessRequest`): - The request object. Request message for batch process - document method. - name (:class:`str`): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.BatchProcessResponse` - Response message for batch process document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.BatchProcessRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.BatchProcessResponse, - metadata_type=document_processor_service.BatchProcessMetadata, - ) - - # Done; return the response. - return response - - async def fetch_processor_types(self, - request: document_processor_service.FetchProcessorTypesRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.FetchProcessorTypesResponse: - r"""Fetches processor types. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest`): - The request object. Request message for fetch processor - types. - parent (:class:`str`): - Required. The project of processor - type to list. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse: - Response message for fetch processor - types. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.FetchProcessorTypesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.fetch_processor_types, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_processors(self, - request: document_processor_service.ListProcessorsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProcessorsAsyncPager: - r"""Lists all processors which belong to this project. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.ListProcessorsRequest`): - The request object. Request message for list all - processors belongs to a project. - parent (:class:`str`): - Required. The parent (project and - location) which owns this collection of - Processors. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsAsyncPager: - Response message for list processors. - Iterating over this object will yield - results and resolve additional pages - automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.ListProcessorsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_processors, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProcessorsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def create_processor(self, - request: document_processor_service.CreateProcessorRequest = None, - *, - parent: str = None, - processor: gcd_processor.Processor = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> gcd_processor.Processor: - r"""Creates a processor from the type processor that the - user chose. The processor will be at "ENABLED" state by - default after its creation. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.CreateProcessorRequest`): - The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. - parent (:class:`str`): - Required. The parent (project and - location) under which to create the - processor. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - processor (:class:`google.cloud.documentai_v1beta3.types.Processor`): - Required. The processor to be created, requires - [processor_type] and [display_name] to be set. Also, the - processor is under CMEK if CMEK fields are set. - - This corresponds to the ``processor`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.Processor: - The first-class citizen for - DocumentAI. Each processor defines how - to extract structural information from a - document. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, processor]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.CreateProcessorRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if processor is not None: - request.processor = processor - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_processor, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_processor(self, - request: document_processor_service.DeleteProcessorRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Deletes the processor, unloads all deployed model - artifacts if it was enabled and then deletes all - artifacts associated with this processor. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.DeleteProcessorRequest`): - The request object. Request message for the delete - processor method. - name (:class:`str`): - Required. The processor resource name - to be deleted. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - The JSON representation for Empty is empty JSON - object {}. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.DeleteProcessorRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_processor, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - empty_pb2.Empty, - metadata_type=document_processor_service.DeleteProcessorMetadata, - ) - - # Done; return the response. - return response - - async def enable_processor(self, - request: document_processor_service.EnableProcessorRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Enables a processor - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.EnableProcessorRequest`): - The request object. Request message for the enable - processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.EnableProcessorResponse` - Response message for the enable processor method. - - """ - # Create or coerce a protobuf request object. - request = document_processor_service.EnableProcessorRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.enable_processor, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.EnableProcessorResponse, - metadata_type=document_processor_service.EnableProcessorMetadata, - ) - - # Done; return the response. - return response - - async def disable_processor(self, - request: document_processor_service.DisableProcessorRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Disables a processor - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.DisableProcessorRequest`): - The request object. Request message for the disable - processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.DisableProcessorResponse` - Response message for the disable processor method. - - """ - # Create or coerce a protobuf request object. - request = document_processor_service.DisableProcessorRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.disable_processor, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.DisableProcessorResponse, - metadata_type=document_processor_service.DisableProcessorMetadata, - ) - - # Done; return the response. - return response - - async def review_document(self, - request: document_processor_service.ReviewDocumentRequest = None, - *, - human_review_config: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Send a document for Human Review. The input document - should be processed by the specified processor. - - Args: - request (:class:`google.cloud.documentai_v1beta3.types.ReviewDocumentRequest`): - The request object. Request message for review document - method. Next Id: 6. - human_review_config (:class:`str`): - Required. The resource name of the - HumanReviewConfig that the document will - be reviewed with. - - This corresponds to the ``human_review_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.ReviewDocumentResponse` - Response message for review document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([human_review_config]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = document_processor_service.ReviewDocumentRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if human_review_config is not None: - request.human_review_config = human_review_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.review_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("human_review_config", request.human_review_config), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - document_processor_service.ReviewDocumentResponse, - metadata_type=document_processor_service.ReviewDocumentOperationMetadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentProcessorServiceAsyncClient", -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py deleted file mode 100644 index e72e0ebf..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ /dev/null @@ -1,1125 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from distutils import util -import os -import re -from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union -import pkg_resources - -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.types import document -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import DocumentProcessorServiceGrpcTransport -from .transports.grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - - -class DocumentProcessorServiceClientMeta(type): - """Metaclass for the DocumentProcessorService client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] - _transport_registry["grpc"] = DocumentProcessorServiceGrpcTransport - _transport_registry["grpc_asyncio"] = DocumentProcessorServiceGrpcAsyncIOTransport - - def get_transport_class(cls, - label: str = None, - ) -> Type[DocumentProcessorServiceTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class DocumentProcessorServiceClient(metaclass=DocumentProcessorServiceClientMeta): - """Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "documentai.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DocumentProcessorServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DocumentProcessorServiceTransport: - """Returns the transport used by the client instance. - - Returns: - DocumentProcessorServiceTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def human_review_config_path(project: str,location: str,processor: str,) -> str: - """Returns a fully-qualified human_review_config string.""" - return "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) - - @staticmethod - def parse_human_review_config_path(path: str) -> Dict[str,str]: - """Parses a human_review_config path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)/humanReviewConfig$", path) - return m.groupdict() if m else {} - - @staticmethod - def processor_path(project: str,location: str,processor: str,) -> str: - """Returns a fully-qualified processor string.""" - return "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) - - @staticmethod - def parse_processor_path(path: str) -> Dict[str,str]: - """Parses a processor path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processors/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def processor_type_path(project: str,location: str,processor_type: str,) -> str: - """Returns a fully-qualified processor_type string.""" - return "projects/{project}/locations/{location}/processorTypes/{processor_type}".format(project=project, location=location, processor_type=processor_type, ) - - @staticmethod - def parse_processor_type_path(path: str) -> Dict[str,str]: - """Parses a processor_type path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/processorTypes/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, DocumentProcessorServiceTransport, None] = None, - client_options: Optional[client_options_lib.ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the document processor service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, DocumentProcessorServiceTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) - - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, DocumentProcessorServiceTransport): - # transport is a DocumentProcessorServiceTransport instance. - if credentials or client_options.credentials_file: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - ) - - def process_document(self, - request: document_processor_service.ProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.ProcessResponse: - r"""Processes a single document. - - Args: - request (google.cloud.documentai_v1beta3.types.ProcessRequest): - The request object. Request message for the process - document method. - name (str): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.ProcessResponse: - Response message for the process - document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.ProcessRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.ProcessRequest): - request = document_processor_service.ProcessRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.process_document] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def batch_process_documents(self, - request: document_processor_service.BatchProcessRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Args: - request (google.cloud.documentai_v1beta3.types.BatchProcessRequest): - The request object. Request message for batch process - document method. - name (str): - Required. The processor resource - name. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.BatchProcessResponse` - Response message for batch process document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.BatchProcessRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.BatchProcessRequest): - request = document_processor_service.BatchProcessRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.batch_process_documents] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.BatchProcessResponse, - metadata_type=document_processor_service.BatchProcessMetadata, - ) - - # Done; return the response. - return response - - def fetch_processor_types(self, - request: document_processor_service.FetchProcessorTypesRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> document_processor_service.FetchProcessorTypesResponse: - r"""Fetches processor types. - - Args: - request (google.cloud.documentai_v1beta3.types.FetchProcessorTypesRequest): - The request object. Request message for fetch processor - types. - parent (str): - Required. The project of processor - type to list. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.FetchProcessorTypesResponse: - Response message for fetch processor - types. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.FetchProcessorTypesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.FetchProcessorTypesRequest): - request = document_processor_service.FetchProcessorTypesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.fetch_processor_types] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_processors(self, - request: document_processor_service.ListProcessorsRequest = None, - *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListProcessorsPager: - r"""Lists all processors which belong to this project. - - Args: - request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): - The request object. Request message for list all - processors belongs to a project. - parent (str): - Required. The parent (project and - location) which owns this collection of - Processors. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.services.document_processor_service.pagers.ListProcessorsPager: - Response message for list processors. - Iterating over this object will yield - results and resolve additional pages - automatically. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.ListProcessorsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.ListProcessorsRequest): - request = document_processor_service.ListProcessorsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_processors] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListProcessorsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def create_processor(self, - request: document_processor_service.CreateProcessorRequest = None, - *, - parent: str = None, - processor: gcd_processor.Processor = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> gcd_processor.Processor: - r"""Creates a processor from the type processor that the - user chose. The processor will be at "ENABLED" state by - default after its creation. - - Args: - request (google.cloud.documentai_v1beta3.types.CreateProcessorRequest): - The request object. Request message for create a - processor. Notice this request is sent to a regionalized - backend service, and if the processor type is not - available on that region, the creation will fail. - parent (str): - Required. The parent (project and - location) under which to create the - processor. Format: - projects/{project}/locations/{location} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - processor (google.cloud.documentai_v1beta3.types.Processor): - Required. The processor to be created, requires - [processor_type] and [display_name] to be set. Also, the - processor is under CMEK if CMEK fields are set. - - This corresponds to the ``processor`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.documentai_v1beta3.types.Processor: - The first-class citizen for - DocumentAI. Each processor defines how - to extract structural information from a - document. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, processor]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.CreateProcessorRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.CreateProcessorRequest): - request = document_processor_service.CreateProcessorRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if processor is not None: - request.processor = processor - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_processor] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_processor(self, - request: document_processor_service.DeleteProcessorRequest = None, - *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Deletes the processor, unloads all deployed model - artifacts if it was enabled and then deletes all - artifacts associated with this processor. - - Args: - request (google.cloud.documentai_v1beta3.types.DeleteProcessorRequest): - The request object. Request message for the delete - processor method. - name (str): - Required. The processor resource name - to be deleted. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - The JSON representation for Empty is empty JSON - object {}. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.DeleteProcessorRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.DeleteProcessorRequest): - request = document_processor_service.DeleteProcessorRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_processor] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - empty_pb2.Empty, - metadata_type=document_processor_service.DeleteProcessorMetadata, - ) - - # Done; return the response. - return response - - def enable_processor(self, - request: document_processor_service.EnableProcessorRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Enables a processor - - Args: - request (google.cloud.documentai_v1beta3.types.EnableProcessorRequest): - The request object. Request message for the enable - processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.EnableProcessorResponse` - Response message for the enable processor method. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.EnableProcessorRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.EnableProcessorRequest): - request = document_processor_service.EnableProcessorRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.enable_processor] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.EnableProcessorResponse, - metadata_type=document_processor_service.EnableProcessorMetadata, - ) - - # Done; return the response. - return response - - def disable_processor(self, - request: document_processor_service.DisableProcessorRequest = None, - *, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Disables a processor - - Args: - request (google.cloud.documentai_v1beta3.types.DisableProcessorRequest): - The request object. Request message for the disable - processor method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.DisableProcessorResponse` - Response message for the disable processor method. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.DisableProcessorRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.DisableProcessorRequest): - request = document_processor_service.DisableProcessorRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.disable_processor] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.DisableProcessorResponse, - metadata_type=document_processor_service.DisableProcessorMetadata, - ) - - # Done; return the response. - return response - - def review_document(self, - request: document_processor_service.ReviewDocumentRequest = None, - *, - human_review_config: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, - timeout: float = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Send a document for Human Review. The input document - should be processed by the specified processor. - - Args: - request (google.cloud.documentai_v1beta3.types.ReviewDocumentRequest): - The request object. Request message for review document - method. Next Id: 6. - human_review_config (str): - Required. The resource name of the - HumanReviewConfig that the document will - be reviewed with. - - This corresponds to the ``human_review_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.documentai_v1beta3.types.ReviewDocumentResponse` - Response message for review document method. - - """ - # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([human_review_config]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a document_processor_service.ReviewDocumentRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, document_processor_service.ReviewDocumentRequest): - request = document_processor_service.ReviewDocumentRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if human_review_config is not None: - request.human_review_config = human_review_config - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.review_document] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("human_review_config", request.human_review_config), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - document_processor_service.ReviewDocumentResponse, - metadata_type=document_processor_service.ReviewDocumentOperationMetadata, - ) - - # Done; return the response. - return response - - - - - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - "google-cloud-documentai", - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - - -__all__ = ( - "DocumentProcessorServiceClient", -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py deleted file mode 100644 index aedf0ca5..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/pagers.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple, Optional - -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor - - -class ListProcessorsPager: - """A pager for iterating through ``list_processors`` requests. - - This class thinly wraps an initial - :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``processors`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProcessors`` requests and continue to iterate - through the ``processors`` field on the - corresponding responses. - - All the usual :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., document_processor_service.ListProcessorsResponse], - request: document_processor_service.ListProcessorsRequest, - response: document_processor_service.ListProcessorsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): - The initial request object. - response (google.cloud.documentai_v1beta3.types.ListProcessorsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = document_processor_service.ListProcessorsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterable[document_processor_service.ListProcessorsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterable[processor.Processor]: - for page in self.pages: - yield from page.processors - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProcessorsAsyncPager: - """A pager for iterating through ``list_processors`` requests. - - This class thinly wraps an initial - :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``processors`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProcessors`` requests and continue to iterate - through the ``processors`` field on the - corresponding responses. - - All the usual :class:`google.cloud.documentai_v1beta3.types.ListProcessorsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[document_processor_service.ListProcessorsResponse]], - request: document_processor_service.ListProcessorsRequest, - response: document_processor_service.ListProcessorsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.documentai_v1beta3.types.ListProcessorsRequest): - The initial request object. - response (google.cloud.documentai_v1beta3.types.ListProcessorsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = document_processor_service.ListProcessorsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterable[document_processor_service.ListProcessorsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - - def __aiter__(self) -> AsyncIterable[processor.Processor]: - async def async_generator(): - async for page in self.pages: - for response in page.processors: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py deleted file mode 100644 index 38f9c440..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import DocumentProcessorServiceTransport -from .grpc import DocumentProcessorServiceGrpcTransport -from .grpc_asyncio import DocumentProcessorServiceGrpcAsyncIOTransport - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[DocumentProcessorServiceTransport]] -_transport_registry['grpc'] = DocumentProcessorServiceGrpcTransport -_transport_registry['grpc_asyncio'] = DocumentProcessorServiceGrpcAsyncIOTransport - -__all__ = ( - 'DocumentProcessorServiceTransport', - 'DocumentProcessorServiceGrpcTransport', - 'DocumentProcessorServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py deleted file mode 100644 index dc126fc5..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ /dev/null @@ -1,309 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version -import pkg_resources - -import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore - -try: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution( - 'google-cloud-documentai', - ).version, - ) -except pkg_resources.DistributionNotFound: - DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() - -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - - -class DocumentProcessorServiceTransport(abc.ABC): - """Abstract transport class for DocumentProcessorService.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - ) - - DEFAULT_HOST: str = 'documentai.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - - # If the credentials is service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.process_document: gapic_v1.method.wrap_method( - self.process_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - self.batch_process_documents: gapic_v1.method.wrap_method( - self.batch_process_documents, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - self.fetch_processor_types: gapic_v1.method.wrap_method( - self.fetch_processor_types, - default_timeout=None, - client_info=client_info, - ), - self.list_processors: gapic_v1.method.wrap_method( - self.list_processors, - default_timeout=None, - client_info=client_info, - ), - self.create_processor: gapic_v1.method.wrap_method( - self.create_processor, - default_timeout=None, - client_info=client_info, - ), - self.delete_processor: gapic_v1.method.wrap_method( - self.delete_processor, - default_timeout=None, - client_info=client_info, - ), - self.enable_processor: gapic_v1.method.wrap_method( - self.enable_processor, - default_timeout=None, - client_info=client_info, - ), - self.disable_processor: gapic_v1.method.wrap_method( - self.disable_processor, - default_timeout=None, - client_info=client_info, - ), - self.review_document: gapic_v1.method.wrap_method( - self.review_document, - default_retry=retries.Retry( -initial=0.1,maximum=60.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=120.0, - ), - default_timeout=120.0, - client_info=client_info, - ), - } - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - Union[ - document_processor_service.ProcessResponse, - Awaitable[document_processor_service.ProcessResponse] - ]]: - raise NotImplementedError() - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def fetch_processor_types(self) -> Callable[ - [document_processor_service.FetchProcessorTypesRequest], - Union[ - document_processor_service.FetchProcessorTypesResponse, - Awaitable[document_processor_service.FetchProcessorTypesResponse] - ]]: - raise NotImplementedError() - - @property - def list_processors(self) -> Callable[ - [document_processor_service.ListProcessorsRequest], - Union[ - document_processor_service.ListProcessorsResponse, - Awaitable[document_processor_service.ListProcessorsResponse] - ]]: - raise NotImplementedError() - - @property - def create_processor(self) -> Callable[ - [document_processor_service.CreateProcessorRequest], - Union[ - gcd_processor.Processor, - Awaitable[gcd_processor.Processor] - ]]: - raise NotImplementedError() - - @property - def delete_processor(self) -> Callable[ - [document_processor_service.DeleteProcessorRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def enable_processor(self) -> Callable[ - [document_processor_service.EnableProcessorRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def disable_processor(self) -> Callable[ - [document_processor_service.DisableProcessorRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - -__all__ = ( - 'DocumentProcessorServiceTransport', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py deleted file mode 100644 index 05d45a4b..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ /dev/null @@ -1,490 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO - - -class DocumentProcessorServiceGrpcTransport(DocumentProcessorServiceTransport): - """gRPC backend transport for DocumentProcessorService. - - Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Sequence[str] = None, - channel: grpc.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: str = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - document_processor_service.ProcessResponse]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessRequest], - ~.ProcessResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ProcessDocument', - request_serializer=document_processor_service.ProcessRequest.serialize, - response_deserializer=document_processor_service.ProcessResponse.deserialize, - ) - return self._stubs['process_document'] - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - operations_pb2.Operation]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/BatchProcessDocuments', - request_serializer=document_processor_service.BatchProcessRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def fetch_processor_types(self) -> Callable[ - [document_processor_service.FetchProcessorTypesRequest], - document_processor_service.FetchProcessorTypesResponse]: - r"""Return a callable for the fetch processor types method over gRPC. - - Fetches processor types. - - Returns: - Callable[[~.FetchProcessorTypesRequest], - ~.FetchProcessorTypesResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'fetch_processor_types' not in self._stubs: - self._stubs['fetch_processor_types'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/FetchProcessorTypes', - request_serializer=document_processor_service.FetchProcessorTypesRequest.serialize, - response_deserializer=document_processor_service.FetchProcessorTypesResponse.deserialize, - ) - return self._stubs['fetch_processor_types'] - - @property - def list_processors(self) -> Callable[ - [document_processor_service.ListProcessorsRequest], - document_processor_service.ListProcessorsResponse]: - r"""Return a callable for the list processors method over gRPC. - - Lists all processors which belong to this project. - - Returns: - Callable[[~.ListProcessorsRequest], - ~.ListProcessorsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_processors' not in self._stubs: - self._stubs['list_processors'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ListProcessors', - request_serializer=document_processor_service.ListProcessorsRequest.serialize, - response_deserializer=document_processor_service.ListProcessorsResponse.deserialize, - ) - return self._stubs['list_processors'] - - @property - def create_processor(self) -> Callable[ - [document_processor_service.CreateProcessorRequest], - gcd_processor.Processor]: - r"""Return a callable for the create processor method over gRPC. - - Creates a processor from the type processor that the - user chose. The processor will be at "ENABLED" state by - default after its creation. - - Returns: - Callable[[~.CreateProcessorRequest], - ~.Processor]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_processor' not in self._stubs: - self._stubs['create_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/CreateProcessor', - request_serializer=document_processor_service.CreateProcessorRequest.serialize, - response_deserializer=gcd_processor.Processor.deserialize, - ) - return self._stubs['create_processor'] - - @property - def delete_processor(self) -> Callable[ - [document_processor_service.DeleteProcessorRequest], - operations_pb2.Operation]: - r"""Return a callable for the delete processor method over gRPC. - - Deletes the processor, unloads all deployed model - artifacts if it was enabled and then deletes all - artifacts associated with this processor. - - Returns: - Callable[[~.DeleteProcessorRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_processor' not in self._stubs: - self._stubs['delete_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/DeleteProcessor', - request_serializer=document_processor_service.DeleteProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['delete_processor'] - - @property - def enable_processor(self) -> Callable[ - [document_processor_service.EnableProcessorRequest], - operations_pb2.Operation]: - r"""Return a callable for the enable processor method over gRPC. - - Enables a processor - - Returns: - Callable[[~.EnableProcessorRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'enable_processor' not in self._stubs: - self._stubs['enable_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/EnableProcessor', - request_serializer=document_processor_service.EnableProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['enable_processor'] - - @property - def disable_processor(self) -> Callable[ - [document_processor_service.DisableProcessorRequest], - operations_pb2.Operation]: - r"""Return a callable for the disable processor method over gRPC. - - Disables a processor - - Returns: - Callable[[~.DisableProcessorRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'disable_processor' not in self._stubs: - self._stubs['disable_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/DisableProcessor', - request_serializer=document_processor_service.DisableProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['disable_processor'] - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - operations_pb2.Operation]: - r"""Return a callable for the review document method over gRPC. - - Send a document for Human Review. The input document - should be processed by the specified processor. - - Returns: - Callable[[~.ReviewDocumentRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'review_document' not in self._stubs: - self._stubs['review_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ReviewDocument', - request_serializer=document_processor_service.ReviewDocumentRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['review_document'] - - -__all__ = ( - 'DocumentProcessorServiceGrpcTransport', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py deleted file mode 100644 index 47040964..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ /dev/null @@ -1,494 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.longrunning import operations_pb2 # type: ignore -from .base import DocumentProcessorServiceTransport, DEFAULT_CLIENT_INFO -from .grpc import DocumentProcessorServiceGrpcTransport - - -class DocumentProcessorServiceGrpcAsyncIOTransport(DocumentProcessorServiceTransport): - """gRPC AsyncIO backend transport for DocumentProcessorService. - - Service to call Cloud DocumentAI to process documents - according to the processor's definition. Processors are built - using state-of-the-art Google AI such as natural language, - computer vision, and translation to extract structured - information from unstructured or semi-structured documents. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'documentai.googleapis.com', - credentials: ga_credentials.Credentials = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: aio.Channel = None, - api_mtls_endpoint: str = None, - client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - ssl_channel_credentials: grpc.ChannelCredentials = None, - client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id=None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - credentials=self._credentials, - credentials_file=credentials_file, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsAsyncClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Sanity check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def process_document(self) -> Callable[ - [document_processor_service.ProcessRequest], - Awaitable[document_processor_service.ProcessResponse]]: - r"""Return a callable for the process document method over gRPC. - - Processes a single document. - - Returns: - Callable[[~.ProcessRequest], - Awaitable[~.ProcessResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'process_document' not in self._stubs: - self._stubs['process_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ProcessDocument', - request_serializer=document_processor_service.ProcessRequest.serialize, - response_deserializer=document_processor_service.ProcessResponse.deserialize, - ) - return self._stubs['process_document'] - - @property - def batch_process_documents(self) -> Callable[ - [document_processor_service.BatchProcessRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the batch process documents method over gRPC. - - LRO endpoint to batch process many documents. The output is - written to Cloud Storage as JSON in the [Document] format. - - Returns: - Callable[[~.BatchProcessRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_process_documents' not in self._stubs: - self._stubs['batch_process_documents'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/BatchProcessDocuments', - request_serializer=document_processor_service.BatchProcessRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['batch_process_documents'] - - @property - def fetch_processor_types(self) -> Callable[ - [document_processor_service.FetchProcessorTypesRequest], - Awaitable[document_processor_service.FetchProcessorTypesResponse]]: - r"""Return a callable for the fetch processor types method over gRPC. - - Fetches processor types. - - Returns: - Callable[[~.FetchProcessorTypesRequest], - Awaitable[~.FetchProcessorTypesResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'fetch_processor_types' not in self._stubs: - self._stubs['fetch_processor_types'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/FetchProcessorTypes', - request_serializer=document_processor_service.FetchProcessorTypesRequest.serialize, - response_deserializer=document_processor_service.FetchProcessorTypesResponse.deserialize, - ) - return self._stubs['fetch_processor_types'] - - @property - def list_processors(self) -> Callable[ - [document_processor_service.ListProcessorsRequest], - Awaitable[document_processor_service.ListProcessorsResponse]]: - r"""Return a callable for the list processors method over gRPC. - - Lists all processors which belong to this project. - - Returns: - Callable[[~.ListProcessorsRequest], - Awaitable[~.ListProcessorsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_processors' not in self._stubs: - self._stubs['list_processors'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ListProcessors', - request_serializer=document_processor_service.ListProcessorsRequest.serialize, - response_deserializer=document_processor_service.ListProcessorsResponse.deserialize, - ) - return self._stubs['list_processors'] - - @property - def create_processor(self) -> Callable[ - [document_processor_service.CreateProcessorRequest], - Awaitable[gcd_processor.Processor]]: - r"""Return a callable for the create processor method over gRPC. - - Creates a processor from the type processor that the - user chose. The processor will be at "ENABLED" state by - default after its creation. - - Returns: - Callable[[~.CreateProcessorRequest], - Awaitable[~.Processor]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_processor' not in self._stubs: - self._stubs['create_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/CreateProcessor', - request_serializer=document_processor_service.CreateProcessorRequest.serialize, - response_deserializer=gcd_processor.Processor.deserialize, - ) - return self._stubs['create_processor'] - - @property - def delete_processor(self) -> Callable[ - [document_processor_service.DeleteProcessorRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the delete processor method over gRPC. - - Deletes the processor, unloads all deployed model - artifacts if it was enabled and then deletes all - artifacts associated with this processor. - - Returns: - Callable[[~.DeleteProcessorRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_processor' not in self._stubs: - self._stubs['delete_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/DeleteProcessor', - request_serializer=document_processor_service.DeleteProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['delete_processor'] - - @property - def enable_processor(self) -> Callable[ - [document_processor_service.EnableProcessorRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the enable processor method over gRPC. - - Enables a processor - - Returns: - Callable[[~.EnableProcessorRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'enable_processor' not in self._stubs: - self._stubs['enable_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/EnableProcessor', - request_serializer=document_processor_service.EnableProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['enable_processor'] - - @property - def disable_processor(self) -> Callable[ - [document_processor_service.DisableProcessorRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the disable processor method over gRPC. - - Disables a processor - - Returns: - Callable[[~.DisableProcessorRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'disable_processor' not in self._stubs: - self._stubs['disable_processor'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/DisableProcessor', - request_serializer=document_processor_service.DisableProcessorRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['disable_processor'] - - @property - def review_document(self) -> Callable[ - [document_processor_service.ReviewDocumentRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the review document method over gRPC. - - Send a document for Human Review. The input document - should be processed by the specified processor. - - Returns: - Callable[[~.ReviewDocumentRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'review_document' not in self._stubs: - self._stubs['review_document'] = self.grpc_channel.unary_unary( - '/google.cloud.documentai.v1beta3.DocumentProcessorService/ReviewDocument', - request_serializer=document_processor_service.ReviewDocumentRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['review_document'] - - -__all__ = ( - 'DocumentProcessorServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py deleted file mode 100644 index 4e9a90e4..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/__init__.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .document import ( - Document, -) -from .document_io import ( - BatchDocumentsInputConfig, - DocumentOutputConfig, - GcsDocument, - GcsDocuments, - GcsPrefix, - RawDocument, -) -from .document_processor_service import ( - BatchProcessMetadata, - BatchProcessRequest, - BatchProcessResponse, - CreateProcessorRequest, - DeleteProcessorMetadata, - DeleteProcessorRequest, - DisableProcessorMetadata, - DisableProcessorRequest, - DisableProcessorResponse, - EnableProcessorMetadata, - EnableProcessorRequest, - EnableProcessorResponse, - FetchProcessorTypesRequest, - FetchProcessorTypesResponse, - HumanReviewStatus, - ListProcessorsRequest, - ListProcessorsResponse, - ProcessRequest, - ProcessResponse, - ReviewDocumentOperationMetadata, - ReviewDocumentRequest, - ReviewDocumentResponse, -) -from .geometry import ( - BoundingPoly, - NormalizedVertex, - Vertex, -) -from .operation_metadata import ( - CommonOperationMetadata, -) -from .processor import ( - Processor, -) -from .processor_type import ( - ProcessorType, -) - -__all__ = ( - 'Document', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'RawDocument', - 'BatchProcessMetadata', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'CreateProcessorRequest', - 'DeleteProcessorMetadata', - 'DeleteProcessorRequest', - 'DisableProcessorMetadata', - 'DisableProcessorRequest', - 'DisableProcessorResponse', - 'EnableProcessorMetadata', - 'EnableProcessorRequest', - 'EnableProcessorResponse', - 'FetchProcessorTypesRequest', - 'FetchProcessorTypesResponse', - 'HumanReviewStatus', - 'ListProcessorsRequest', - 'ListProcessorsResponse', - 'ProcessRequest', - 'ProcessResponse', - 'ReviewDocumentOperationMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'BoundingPoly', - 'NormalizedVertex', - 'Vertex', - 'CommonOperationMetadata', - 'Processor', - 'ProcessorType', -) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py deleted file mode 100644 index 62f69bfc..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document.py +++ /dev/null @@ -1,1373 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1beta3.types import geometry -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import date_pb2 # type: ignore -from google.type import datetime_pb2 # type: ignore -from google.type import money_pb2 # type: ignore -from google.type import postal_address_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'Document', - }, -) - - -class Document(proto.Message): - r"""Document represents the canonical document resource in - Document Understanding AI. - It is an interchange format that provides insights into - documents and allows for collaboration between users and - Document Understanding AI to iterate and optimize for quality. - - Attributes: - uri (str): - Optional. Currently supports Google Cloud Storage URI of the - form ``gs://bucket_name/object_name``. Object versioning is - not supported. See `Google Cloud Storage Request - URIs `__ - for more info. - content (bytes): - Optional. Inline document content, represented as a stream - of bytes. Note: As with all ``bytes`` fields, protobuffers - use a pure binary representation, whereas JSON - representations use base64. - mime_type (str): - An IANA published MIME type (also referred to - as media type). For more information, see - https://www.iana.org/assignments/media- - types/media-types.xhtml. - text (str): - Optional. UTF-8 encoded text in reading order - from the document. - text_styles (Sequence[google.cloud.documentai_v1beta3.types.Document.Style]): - Styles for the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - pages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page]): - Visual page layout for the - [Document][google.cloud.documentai.v1beta3.Document]. - entities (Sequence[google.cloud.documentai_v1beta3.types.Document.Entity]): - A list of entities detected on - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - For document shards, entities in this list may cross shard - boundaries. - entity_relations (Sequence[google.cloud.documentai_v1beta3.types.Document.EntityRelation]): - Relationship among - [Document.entities][google.cloud.documentai.v1beta3.Document.entities]. - text_changes (Sequence[google.cloud.documentai_v1beta3.types.Document.TextChange]): - A list of text corrections made to [Document.text]. This is - usually used for annotating corrections to OCR mistakes. - Text changes for a given revision may not overlap with each - other. - shard_info (google.cloud.documentai_v1beta3.types.Document.ShardInfo): - Information about the sharding if this - document is sharded part of a larger document. - If the document is not sharded, this message is - not specified. - error (google.rpc.status_pb2.Status): - Any error that occurred while processing this - document. - revisions (Sequence[google.cloud.documentai_v1beta3.types.Document.Revision]): - Revision history of this document. - """ - - class ShardInfo(proto.Message): - r"""For a large document, sharding may be performed to produce - several document shards. Each document shard contains this field - to detail which shard it is. - - Attributes: - shard_index (int): - The 0-based index of this shard. - shard_count (int): - Total number of shards. - text_offset (int): - The index of the first character in - [Document.text][google.cloud.documentai.v1beta3.Document.text] - in the overall document global text. - """ - - shard_index = proto.Field( - proto.INT64, - number=1, - ) - shard_count = proto.Field( - proto.INT64, - number=2, - ) - text_offset = proto.Field( - proto.INT64, - number=3, - ) - - class Style(proto.Message): - r"""Annotation for common text style attributes. This adheres to - CSS conventions as much as possible. - - Attributes: - text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): - Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - color (google.type.color_pb2.Color): - Text color. - background_color (google.type.color_pb2.Color): - Text background color. - font_weight (str): - Font weight. Possible values are normal, bold, bolder, and - lighter. https://www.w3schools.com/cssref/pr_font_weight.asp - text_style (str): - Text style. Possible values are normal, italic, and oblique. - https://www.w3schools.com/cssref/pr_font_font-style.asp - text_decoration (str): - Text decoration. Follows CSS standard. - https://www.w3schools.com/cssref/pr_text_text-decoration.asp - font_size (google.cloud.documentai_v1beta3.types.Document.Style.FontSize): - Font size. - """ - - class FontSize(proto.Message): - r"""Font size with unit. - Attributes: - size (float): - Font size for the text. - unit (str): - Unit for the font size. Follows CSS naming - (in, px, pt, etc.). - """ - - size = proto.Field( - proto.FLOAT, - number=1, - ) - unit = proto.Field( - proto.STRING, - number=2, - ) - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - color = proto.Field( - proto.MESSAGE, - number=2, - message=color_pb2.Color, - ) - background_color = proto.Field( - proto.MESSAGE, - number=3, - message=color_pb2.Color, - ) - font_weight = proto.Field( - proto.STRING, - number=4, - ) - text_style = proto.Field( - proto.STRING, - number=5, - ) - text_decoration = proto.Field( - proto.STRING, - number=6, - ) - font_size = proto.Field( - proto.MESSAGE, - number=7, - message='Document.Style.FontSize', - ) - - class Page(proto.Message): - r"""A page in a [Document][google.cloud.documentai.v1beta3.Document]. - Attributes: - page_number (int): - 1-based index for current - [Page][google.cloud.documentai.v1beta3.Document.Page] in a - parent [Document][google.cloud.documentai.v1beta3.Document]. - Useful when a page is taken out of a - [Document][google.cloud.documentai.v1beta3.Document] for - individual processing. - image (google.cloud.documentai_v1beta3.types.Document.Page.Image): - Rendered image for this page. This image is - preprocessed to remove any skew, rotation, and - distortions such that the annotation bounding - boxes can be upright and axis-aligned. - transforms (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Matrix]): - Transformation matrices that were applied to the original - document image to produce - [Page.image][google.cloud.documentai.v1beta3.Document.Page.image]. - dimension (google.cloud.documentai_v1beta3.types.Document.Page.Dimension): - Physical dimension of the page. - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for the page. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - blocks (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Block]): - A list of visually detected text blocks on - the page. A block has a set of lines (collected - into paragraphs) that have a common line-spacing - and orientation. - paragraphs (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Paragraph]): - A list of visually detected text paragraphs - on the page. A collection of lines that a human - would perceive as a paragraph. - lines (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Line]): - A list of visually detected text lines on the - page. A collection of tokens that a human would - perceive as a line. - tokens (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Token]): - A list of visually detected tokens on the - page. - visual_elements (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.VisualElement]): - A list of detected non-text visual elements - e.g. checkbox, signature etc. on the page. - tables (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table]): - A list of visually detected tables on the - page. - form_fields (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.FormField]): - A list of visually detected form fields on - the page. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this page. - """ - - class Dimension(proto.Message): - r"""Dimension for the page. - Attributes: - width (float): - Page width. - height (float): - Page height. - unit (str): - Dimension unit. - """ - - width = proto.Field( - proto.FLOAT, - number=1, - ) - height = proto.Field( - proto.FLOAT, - number=2, - ) - unit = proto.Field( - proto.STRING, - number=3, - ) - - class Image(proto.Message): - r"""Rendered image contents for this page. - Attributes: - content (bytes): - Raw byte content of the image. - mime_type (str): - Encoding mime type for the image. - width (int): - Width of the image in pixels. - height (int): - Height of the image in pixels. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - width = proto.Field( - proto.INT32, - number=3, - ) - height = proto.Field( - proto.INT32, - number=4, - ) - - class Matrix(proto.Message): - r"""Representation for transformation matrix, intended to be - compatible and used with OpenCV format for image manipulation. - - Attributes: - rows (int): - Number of rows in the matrix. - cols (int): - Number of columns in the matrix. - type_ (int): - This encodes information about what data type the matrix - uses. For example, 0 (CV_8U) is an unsigned 8-bit image. For - the full list of OpenCV primitive data types, please refer - to - https://docs.opencv.org/4.3.0/d1/d1b/group__core__hal__interface.html - data (bytes): - The matrix data. - """ - - rows = proto.Field( - proto.INT32, - number=1, - ) - cols = proto.Field( - proto.INT32, - number=2, - ) - type_ = proto.Field( - proto.INT32, - number=3, - ) - data = proto.Field( - proto.BYTES, - number=4, - ) - - class Layout(proto.Message): - r"""Visual element describing a layout unit on a page. - Attributes: - text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): - Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - confidence (float): - Confidence of the current - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - within context of the object this layout is for. e.g. - confidence can be for a single token, a table, a visual - element, etc. depending on context. Range [0, 1]. - bounding_poly (google.cloud.documentai_v1beta3.types.BoundingPoly): - The bounding polygon for the - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout]. - orientation (google.cloud.documentai_v1beta3.types.Document.Page.Layout.Orientation): - Detected orientation for the - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout]. - """ - class Orientation(proto.Enum): - r"""Detected human reading orientation.""" - ORIENTATION_UNSPECIFIED = 0 - PAGE_UP = 1 - PAGE_RIGHT = 2 - PAGE_DOWN = 3 - PAGE_LEFT = 4 - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=3, - message=geometry.BoundingPoly, - ) - orientation = proto.Field( - proto.ENUM, - number=4, - enum='Document.Page.Layout.Orientation', - ) - - class Block(proto.Message): - r"""A block has a set of lines (collected into paragraphs) that - have a common line-spacing and orientation. - - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [Block][google.cloud.documentai.v1beta3.Document.Page.Block]. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - class Paragraph(proto.Message): - r"""A collection of lines that a human would perceive as a - paragraph. - - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [Paragraph][google.cloud.documentai.v1beta3.Document.Page.Paragraph]. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - class Line(proto.Message): - r"""A collection of tokens that a human would perceive as a line. - Does not cross column boundaries, can be horizontal, vertical, - etc. - - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [Line][google.cloud.documentai.v1beta3.Document.Page.Line]. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this annotation. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - class Token(proto.Message): - r"""A detected token. - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. - detected_break (google.cloud.documentai_v1beta3.types.Document.Page.Token.DetectedBreak): - Detected break at the end of a - [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this annotation. - """ - - class DetectedBreak(proto.Message): - r"""Detected break at the end of a - [Token][google.cloud.documentai.v1beta3.Document.Page.Token]. - - Attributes: - type_ (google.cloud.documentai_v1beta3.types.Document.Page.Token.DetectedBreak.Type): - Detected break type. - """ - class Type(proto.Enum): - r"""Enum to denote the type of break found.""" - TYPE_UNSPECIFIED = 0 - SPACE = 1 - WIDE_SPACE = 2 - HYPHEN = 3 - - type_ = proto.Field( - proto.ENUM, - number=1, - enum='Document.Page.Token.DetectedBreak.Type', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - detected_break = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Token.DetectedBreak', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - provenance = proto.Field( - proto.MESSAGE, - number=4, - message='Document.Provenance', - ) - - class VisualElement(proto.Message): - r"""Detected non-text visual elements e.g. checkbox, signature - etc. on the page. - - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [VisualElement][google.cloud.documentai.v1beta3.Document.Page.VisualElement]. - type_ (str): - Type of the - [VisualElement][google.cloud.documentai.v1beta3.Document.Page.VisualElement]. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - - class Table(proto.Message): - r"""A table representation similar to HTML table structure. - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [Table][google.cloud.documentai.v1beta3.Document.Page.Table]. - header_rows (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableRow]): - Header rows of the table. - body_rows (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableRow]): - Body rows of the table. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - class TableRow(proto.Message): - r"""A row of table cells. - Attributes: - cells (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.Table.TableCell]): - Cells that make up this row. - """ - - cells = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.Page.Table.TableCell', - ) - - class TableCell(proto.Message): - r"""A cell representation inside the table. - Attributes: - layout (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for - [TableCell][google.cloud.documentai.v1beta3.Document.Page.Table.TableCell]. - row_span (int): - How many rows this cell spans. - col_span (int): - How many columns this cell spans. - detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages together with - confidence. - """ - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - row_span = proto.Field( - proto.INT32, - number=2, - ) - col_span = proto.Field( - proto.INT32, - number=3, - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - layout = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - header_rows = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='Document.Page.Table.TableRow', - ) - body_rows = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.Table.TableRow', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - - class FormField(proto.Message): - r"""A form field detected on the page. - Attributes: - field_name (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for the - [FormField][google.cloud.documentai.v1beta3.Document.Page.FormField] - name. e.g. ``Address``, ``Email``, ``Grand total``, - ``Phone number``, etc. - field_value (google.cloud.documentai_v1beta3.types.Document.Page.Layout): - [Layout][google.cloud.documentai.v1beta3.Document.Page.Layout] - for the - [FormField][google.cloud.documentai.v1beta3.Document.Page.FormField] - value. - name_detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages for name - together with confidence. - value_detected_languages (Sequence[google.cloud.documentai_v1beta3.types.Document.Page.DetectedLanguage]): - A list of detected languages for value - together with confidence. - value_type (str): - If the value is non-textual, this field represents the type. - Current valid values are: - - - blank (this indicates the field_value is normal text) - - "unfilled_checkbox" - - "filled_checkbox". - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - The history of this annotation. - """ - - field_name = proto.Field( - proto.MESSAGE, - number=1, - message='Document.Page.Layout', - ) - field_value = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Layout', - ) - name_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Page.DetectedLanguage', - ) - value_detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - value_type = proto.Field( - proto.STRING, - number=5, - ) - provenance = proto.Field( - proto.MESSAGE, - number=8, - message='Document.Provenance', - ) - - 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 - more information, see - http://www.unicode.org/reports/tr35/#Unicode_locale_identifier. - confidence (float): - Confidence of detected language. Range [0, 1]. - """ - - language_code = proto.Field( - proto.STRING, - number=1, - ) - confidence = proto.Field( - proto.FLOAT, - number=2, - ) - - page_number = proto.Field( - proto.INT32, - number=1, - ) - image = proto.Field( - proto.MESSAGE, - number=13, - message='Document.Page.Image', - ) - transforms = proto.RepeatedField( - proto.MESSAGE, - number=14, - message='Document.Page.Matrix', - ) - dimension = proto.Field( - proto.MESSAGE, - number=2, - message='Document.Page.Dimension', - ) - layout = proto.Field( - proto.MESSAGE, - number=3, - message='Document.Page.Layout', - ) - detected_languages = proto.RepeatedField( - proto.MESSAGE, - number=4, - message='Document.Page.DetectedLanguage', - ) - blocks = proto.RepeatedField( - proto.MESSAGE, - number=5, - message='Document.Page.Block', - ) - paragraphs = proto.RepeatedField( - proto.MESSAGE, - number=6, - message='Document.Page.Paragraph', - ) - lines = proto.RepeatedField( - proto.MESSAGE, - number=7, - message='Document.Page.Line', - ) - tokens = proto.RepeatedField( - proto.MESSAGE, - number=8, - message='Document.Page.Token', - ) - visual_elements = proto.RepeatedField( - proto.MESSAGE, - number=9, - message='Document.Page.VisualElement', - ) - tables = proto.RepeatedField( - proto.MESSAGE, - number=10, - message='Document.Page.Table', - ) - form_fields = proto.RepeatedField( - proto.MESSAGE, - number=11, - message='Document.Page.FormField', - ) - provenance = proto.Field( - proto.MESSAGE, - number=16, - message='Document.Provenance', - ) - - class Entity(proto.Message): - r"""A phrase in the text that is a known entity type, such as a - person, an organization, or location. - - Attributes: - text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): - Optional. Provenance of the entity. Text anchor indexing - into the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - type_ (str): - Entity type from a schema e.g. ``Address``. - mention_text (str): - Optional. Text value in the document e.g. - ``1600 Amphitheatre Pkwy``. - mention_id (str): - Optional. Deprecated. Use ``id`` field instead. - confidence (float): - Optional. Confidence of detected Schema entity. Range [0, - 1]. - page_anchor (google.cloud.documentai_v1beta3.types.Document.PageAnchor): - Optional. Represents the provenance of this - entity wrt. the location on the page where it - was found. - id (str): - Optional. Canonical id. This will be a unique - value in the entity list for this document. - normalized_value (google.cloud.documentai_v1beta3.types.Document.Entity.NormalizedValue): - Optional. Normalized entity value. Absent if - the extracted value could not be converted or - the type (e.g. address) is not supported for - certain parsers. This field is also only - populated for certain supported document types. - properties (Sequence[google.cloud.documentai_v1beta3.types.Document.Entity]): - Optional. Entities can be nested to form a - hierarchical data structure representing the - content in the document. - provenance (google.cloud.documentai_v1beta3.types.Document.Provenance): - Optional. The history of this annotation. - redacted (bool): - Optional. Whether the entity will be redacted - for de-identification purposes. - """ - - class NormalizedValue(proto.Message): - r"""Parsed and normalized entity value. - Attributes: - money_value (google.type.money_pb2.Money): - Money value. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/money.proto - date_value (google.type.date_pb2.Date): - Date value. Includes year, month, day. See - also: - https://github.com/googleapis/googleapis/blob/master/google/type/date.proto - datetime_value (google.type.datetime_pb2.DateTime): - DateTime value. Includes date, time, and - timezone. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/datetime.proto - address_value (google.type.postal_address_pb2.PostalAddress): - Postal address. See also: - https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto - boolean_value (bool): - Boolean value. Can be used for entities with - binary values, or for checkboxes. - text (str): - Required. Normalized entity value stored as a string. This - field is populated for supported document type (e.g. - Invoice). For some entity types, one of respective - 'structured_value' fields may also be populated. - - - Money/Currency type (``money_value``) is in the ISO 4217 - text format. - - Date type (``date_value``) is in the ISO 8601 text - format. - - Datetime type (``datetime_value``) is in the ISO 8601 - text format. - """ - - money_value = proto.Field( - proto.MESSAGE, - number=2, - oneof='structured_value', - message=money_pb2.Money, - ) - date_value = proto.Field( - proto.MESSAGE, - number=3, - oneof='structured_value', - message=date_pb2.Date, - ) - datetime_value = proto.Field( - proto.MESSAGE, - number=4, - oneof='structured_value', - message=datetime_pb2.DateTime, - ) - address_value = proto.Field( - proto.MESSAGE, - number=5, - oneof='structured_value', - message=postal_address_pb2.PostalAddress, - ) - boolean_value = proto.Field( - proto.BOOL, - number=6, - oneof='structured_value', - ) - text = proto.Field( - proto.STRING, - number=1, - ) - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - mention_text = proto.Field( - proto.STRING, - number=3, - ) - mention_id = proto.Field( - proto.STRING, - number=4, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - page_anchor = proto.Field( - proto.MESSAGE, - number=6, - message='Document.PageAnchor', - ) - id = proto.Field( - proto.STRING, - number=7, - ) - normalized_value = proto.Field( - proto.MESSAGE, - number=9, - message='Document.Entity.NormalizedValue', - ) - properties = proto.RepeatedField( - proto.MESSAGE, - number=10, - message='Document.Entity', - ) - provenance = proto.Field( - proto.MESSAGE, - number=11, - message='Document.Provenance', - ) - redacted = proto.Field( - proto.BOOL, - number=12, - ) - - class EntityRelation(proto.Message): - r"""Relationship between - [Entities][google.cloud.documentai.v1beta3.Document.Entity]. - - Attributes: - subject_id (str): - Subject entity id. - object_id (str): - Object entity id. - relation (str): - Relationship description. - """ - - subject_id = proto.Field( - proto.STRING, - number=1, - ) - object_id = proto.Field( - proto.STRING, - number=2, - ) - relation = proto.Field( - proto.STRING, - number=3, - ) - - class TextAnchor(proto.Message): - r"""Text reference indexing into the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - - Attributes: - text_segments (Sequence[google.cloud.documentai_v1beta3.types.Document.TextAnchor.TextSegment]): - The text segments from the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - content (str): - Contains the content of the text span so that users do not - have to look it up in the text_segments. - """ - - class TextSegment(proto.Message): - r"""A text segment in the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. The - indices may be out of bounds which indicate that the text extends - into another document shard for large sharded documents. See - [ShardInfo.text_offset][google.cloud.documentai.v1beta3.Document.ShardInfo.text_offset] - - Attributes: - start_index (int): - [TextSegment][google.cloud.documentai.v1beta3.Document.TextAnchor.TextSegment] - start UTF-8 char index in the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - end_index (int): - [TextSegment][google.cloud.documentai.v1beta3.Document.TextAnchor.TextSegment] - half open end UTF-8 char index in the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - """ - - start_index = proto.Field( - proto.INT64, - number=1, - ) - end_index = proto.Field( - proto.INT64, - number=2, - ) - - text_segments = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.TextAnchor.TextSegment', - ) - content = proto.Field( - proto.STRING, - number=2, - ) - - class PageAnchor(proto.Message): - r"""Referencing the visual context of the entity in the - [Document.pages][google.cloud.documentai.v1beta3.Document.pages]. - Page anchors can be cross-page, consist of multiple bounding - polygons and optionally reference specific layout element types. - - Attributes: - page_refs (Sequence[google.cloud.documentai_v1beta3.types.Document.PageAnchor.PageRef]): - One or more references to visual page - elements - """ - - class PageRef(proto.Message): - r"""Represents a weak reference to a page element within a - document. - - Attributes: - page (int): - Required. Index into the - [Document.pages][google.cloud.documentai.v1beta3.Document.pages] - element, for example using [Document.pages][page_refs.page] - to locate the related page element. This field is skipped - when its value is the default 0. See - https://developers.google.com/protocol-buffers/docs/proto3#json. - layout_type (google.cloud.documentai_v1beta3.types.Document.PageAnchor.PageRef.LayoutType): - Optional. The type of the layout element that - is being referenced if any. - layout_id (str): - Optional. Deprecated. Use - [PageRef.bounding_poly][google.cloud.documentai.v1beta3.Document.PageAnchor.PageRef.bounding_poly] - instead. - bounding_poly (google.cloud.documentai_v1beta3.types.BoundingPoly): - Optional. Identifies the bounding polygon of - a layout element on the page. - confidence (float): - Optional. Confidence of detected page element, if - applicable. Range [0, 1]. - """ - class LayoutType(proto.Enum): - r"""The type of layout that is being referenced.""" - LAYOUT_TYPE_UNSPECIFIED = 0 - BLOCK = 1 - PARAGRAPH = 2 - LINE = 3 - TOKEN = 4 - VISUAL_ELEMENT = 5 - TABLE = 6 - FORM_FIELD = 7 - - page = proto.Field( - proto.INT64, - number=1, - ) - layout_type = proto.Field( - proto.ENUM, - number=2, - enum='Document.PageAnchor.PageRef.LayoutType', - ) - layout_id = proto.Field( - proto.STRING, - number=3, - ) - bounding_poly = proto.Field( - proto.MESSAGE, - number=4, - message=geometry.BoundingPoly, - ) - confidence = proto.Field( - proto.FLOAT, - number=5, - ) - - page_refs = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Document.PageAnchor.PageRef', - ) - - class Provenance(proto.Message): - r"""Structure to identify provenance relationships between - annotations in different revisions. - - Attributes: - revision (int): - The index of the revision that produced this - element. - id (int): - The Id of this operation. Needs to be unique - within the scope of the revision. - parents (Sequence[google.cloud.documentai_v1beta3.types.Document.Provenance.Parent]): - References to the original elements that are - replaced. - type_ (google.cloud.documentai_v1beta3.types.Document.Provenance.OperationType): - The type of provenance operation. - """ - class OperationType(proto.Enum): - r"""If a processor or agent does an explicit operation on - existing elements. - """ - OPERATION_TYPE_UNSPECIFIED = 0 - ADD = 1 - REMOVE = 2 - REPLACE = 3 - EVAL_REQUESTED = 4 - EVAL_APPROVED = 5 - EVAL_SKIPPED = 6 - - class Parent(proto.Message): - r"""Structure for referencing parent provenances. When an - element replaces one of more other elements parent references - identify the elements that are replaced. - - Attributes: - revision (int): - The index of the [Document.revisions] identifying the parent - revision. - index (int): - The index of the parent revisions - corresponding collection of items (eg. list of - entities, properties within entities, etc.) - id (int): - The id of the parent provenance. - """ - - revision = proto.Field( - proto.INT32, - number=1, - ) - index = proto.Field( - proto.INT32, - number=3, - ) - id = proto.Field( - proto.INT32, - number=2, - ) - - revision = proto.Field( - proto.INT32, - number=1, - ) - id = proto.Field( - proto.INT32, - number=2, - ) - parents = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Provenance.Parent', - ) - type_ = proto.Field( - proto.ENUM, - number=4, - enum='Document.Provenance.OperationType', - ) - - 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 - the name or id of that person. - processor (str): - If the annotation was made by processor - identify the processor by its resource name. - id (str): - Id of the revision. Unique within the - context of the document. - parent (Sequence[int]): - The revisions that this revision is based on. This can - include one or more parent (when documents are merged.) This - field represents the index into the ``revisions`` field. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time that the revision was created. - human_review (google.cloud.documentai_v1beta3.types.Document.Revision.HumanReview): - Human Review information of this revision. - """ - - class HumanReview(proto.Message): - r"""Human Review information of the document. - Attributes: - state (str): - Human review state. e.g. ``requested``, ``succeeded``, - ``rejected``. - state_message (str): - A message providing more details about the current state of - processing. For example, the rejection reason when the state - is ``rejected``. - """ - - state = proto.Field( - proto.STRING, - number=1, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - - agent = proto.Field( - proto.STRING, - number=4, - oneof='source', - ) - processor = proto.Field( - proto.STRING, - number=5, - oneof='source', - ) - id = proto.Field( - proto.STRING, - number=1, - ) - parent = proto.RepeatedField( - proto.INT32, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - human_review = proto.Field( - proto.MESSAGE, - number=6, - message='Document.Revision.HumanReview', - ) - - class TextChange(proto.Message): - r"""This message is used for text changes aka. OCR corrections. - Attributes: - text_anchor (google.cloud.documentai_v1beta3.types.Document.TextAnchor): - Provenance of the correction. Text anchor indexing into the - [Document.text][google.cloud.documentai.v1beta3.Document.text]. - There can only be a single ``TextAnchor.text_segments`` - element. If the start and end index of the text segment are - the same, the text change is inserted before that index. - changed_text (str): - The text that replaces the text identified in the - ``text_anchor``. - provenance (Sequence[google.cloud.documentai_v1beta3.types.Document.Provenance]): - The history of this annotation. - """ - - text_anchor = proto.Field( - proto.MESSAGE, - number=1, - message='Document.TextAnchor', - ) - changed_text = proto.Field( - proto.STRING, - number=2, - ) - provenance = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='Document.Provenance', - ) - - uri = proto.Field( - proto.STRING, - number=1, - oneof='source', - ) - content = proto.Field( - proto.BYTES, - number=2, - oneof='source', - ) - mime_type = proto.Field( - proto.STRING, - number=3, - ) - text = proto.Field( - proto.STRING, - number=4, - ) - text_styles = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=Style, - ) - pages = proto.RepeatedField( - proto.MESSAGE, - number=6, - message=Page, - ) - entities = proto.RepeatedField( - proto.MESSAGE, - number=7, - message=Entity, - ) - entity_relations = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=EntityRelation, - ) - text_changes = proto.RepeatedField( - proto.MESSAGE, - number=14, - message=TextChange, - ) - shard_info = proto.Field( - proto.MESSAGE, - number=9, - message=ShardInfo, - ) - error = proto.Field( - proto.MESSAGE, - number=10, - message=status_pb2.Status, - ) - revisions = proto.RepeatedField( - proto.MESSAGE, - number=13, - message=Revision, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py deleted file mode 100644 index 37bc8b94..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_io.py +++ /dev/null @@ -1,158 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'RawDocument', - 'GcsDocument', - 'GcsDocuments', - 'GcsPrefix', - 'BatchDocumentsInputConfig', - 'DocumentOutputConfig', - }, -) - - -class RawDocument(proto.Message): - r"""Payload message of raw document content (bytes). - Attributes: - content (bytes): - Inline document content. - mime_type (str): - An IANA MIME type (RFC6838) indicating the nature and format - of the [content]. - """ - - content = proto.Field( - proto.BYTES, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class GcsDocument(proto.Message): - r"""Specifies a document stored on Cloud Storage. - Attributes: - gcs_uri (str): - The Cloud Storage object uri. - mime_type (str): - An IANA MIME type (RFC6838) of the content. - """ - - gcs_uri = proto.Field( - proto.STRING, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - -class GcsDocuments(proto.Message): - r"""Specifies a set of documents on Cloud Storage. - Attributes: - documents (Sequence[google.cloud.documentai_v1beta3.types.GcsDocument]): - The list of documents. - """ - - documents = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='GcsDocument', - ) - - -class GcsPrefix(proto.Message): - r"""Specifies all documents on Cloud Storage with a common - prefix. - - Attributes: - gcs_uri_prefix (str): - The URI prefix. - """ - - gcs_uri_prefix = proto.Field( - proto.STRING, - number=1, - ) - - -class BatchDocumentsInputConfig(proto.Message): - r"""The common config to specify a set of documents used as - input. - - Attributes: - gcs_prefix (google.cloud.documentai_v1beta3.types.GcsPrefix): - The set of documents that match the specified Cloud Storage - [gcs_prefix]. - gcs_documents (google.cloud.documentai_v1beta3.types.GcsDocuments): - The set of documents individually specified - on Cloud Storage. - """ - - gcs_prefix = proto.Field( - proto.MESSAGE, - number=1, - oneof='source', - message='GcsPrefix', - ) - gcs_documents = proto.Field( - proto.MESSAGE, - number=2, - oneof='source', - message='GcsDocuments', - ) - - -class DocumentOutputConfig(proto.Message): - r"""Config that controls the output of documents. All documents - will be written as a JSON file. - - Attributes: - gcs_output_config (google.cloud.documentai_v1beta3.types.DocumentOutputConfig.GcsOutputConfig): - Output config to write the results to Cloud - Storage. - """ - - class GcsOutputConfig(proto.Message): - r"""The configuration used when outputting documents. - Attributes: - gcs_uri (str): - The Cloud Storage uri (a directory) of the - output. - """ - - gcs_uri = proto.Field( - proto.STRING, - number=1, - ) - - gcs_output_config = proto.Field( - proto.MESSAGE, - number=1, - oneof='destination', - message=GcsOutputConfig, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py deleted file mode 100644 index 77ceba10..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/document_processor_service.py +++ /dev/null @@ -1,698 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.cloud.documentai_v1beta3.types import document as gcd_document -from google.cloud.documentai_v1beta3.types import document_io -from google.cloud.documentai_v1beta3.types import operation_metadata -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.cloud.documentai_v1beta3.types import processor_type -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'ProcessRequest', - 'HumanReviewStatus', - 'ProcessResponse', - 'BatchProcessRequest', - 'BatchProcessResponse', - 'BatchProcessMetadata', - 'FetchProcessorTypesRequest', - 'FetchProcessorTypesResponse', - 'ListProcessorsRequest', - 'ListProcessorsResponse', - 'CreateProcessorRequest', - 'DeleteProcessorRequest', - 'DeleteProcessorMetadata', - 'EnableProcessorRequest', - 'EnableProcessorResponse', - 'EnableProcessorMetadata', - 'DisableProcessorRequest', - 'DisableProcessorResponse', - 'DisableProcessorMetadata', - 'ReviewDocumentRequest', - 'ReviewDocumentResponse', - 'ReviewDocumentOperationMetadata', - }, -) - - -class ProcessRequest(proto.Message): - r"""Request message for the process document method. - Attributes: - inline_document (google.cloud.documentai_v1beta3.types.Document): - An inline document proto. - raw_document (google.cloud.documentai_v1beta3.types.RawDocument): - A raw document content (bytes). - name (str): - Required. The processor resource name. - document (google.cloud.documentai_v1beta3.types.Document): - The document payload, the [content] and [mime_type] fields - must be set. - skip_human_review (bool): - Whether Human Review feature should be - skipped for this request. Default to false. - """ - - inline_document = proto.Field( - proto.MESSAGE, - number=4, - oneof='source', - message=gcd_document.Document, - ) - raw_document = proto.Field( - proto.MESSAGE, - number=5, - oneof='source', - message=document_io.RawDocument, - ) - name = proto.Field( - proto.STRING, - number=1, - ) - document = proto.Field( - proto.MESSAGE, - number=2, - message=gcd_document.Document, - ) - skip_human_review = proto.Field( - proto.BOOL, - number=3, - ) - - -class HumanReviewStatus(proto.Message): - r"""The status of human review on a processed document. - Attributes: - state (google.cloud.documentai_v1beta3.types.HumanReviewStatus.State): - The state of human review on the processing - request. - state_message (str): - A message providing more details about the - human review state. - human_review_operation (str): - The name of the operation triggered by the processed - document. This field is populated only when the [state] is - [HUMAN_REVIEW_IN_PROGRESS]. It has the same response type - and metadata as the long running operation returned by - [ReviewDocument] method. - """ - class State(proto.Enum): - r"""The final state of human review on a processed document.""" - STATE_UNSPECIFIED = 0 - SKIPPED = 1 - VALIDATION_PASSED = 2 - IN_PROGRESS = 3 - ERROR = 4 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - human_review_operation = proto.Field( - proto.STRING, - number=3, - ) - - -class ProcessResponse(proto.Message): - r"""Response message for the process document method. - Attributes: - document (google.cloud.documentai_v1beta3.types.Document): - The document payload, will populate fields - based on the processor's behavior. - human_review_operation (str): - The name of the operation triggered by the - processed document. If the human review process - is not triggered, this field will be empty. It - has the same response type and metadata as the - long running operation returned by - ReviewDocument method. - human_review_status (google.cloud.documentai_v1beta3.types.HumanReviewStatus): - The status of human review on the processed - document. - """ - - document = proto.Field( - proto.MESSAGE, - number=1, - message=gcd_document.Document, - ) - human_review_operation = proto.Field( - proto.STRING, - number=2, - ) - human_review_status = proto.Field( - proto.MESSAGE, - number=3, - message='HumanReviewStatus', - ) - - -class BatchProcessRequest(proto.Message): - r"""Request message for batch process document method. - Attributes: - name (str): - Required. The processor resource name. - input_configs (Sequence[google.cloud.documentai_v1beta3.types.BatchProcessRequest.BatchInputConfig]): - The input config for each single document in - the batch process. - output_config (google.cloud.documentai_v1beta3.types.BatchProcessRequest.BatchOutputConfig): - The overall output config for batch process. - input_documents (google.cloud.documentai_v1beta3.types.BatchDocumentsInputConfig): - The input documents for batch process. - document_output_config (google.cloud.documentai_v1beta3.types.DocumentOutputConfig): - The overall output config for batch process. - skip_human_review (bool): - Whether Human Review feature should be - skipped for this request. Default to false. - """ - - class BatchInputConfig(proto.Message): - r"""The message for input config in batch process. - Attributes: - gcs_source (str): - The Cloud Storage location as the source of - the document. - mime_type (str): - Mimetype of the input. If the input is a raw document, the - supported mimetypes are application/pdf, image/tiff, and - image/gif. If the input is a [Document] proto, the type - should be application/json. - """ - - gcs_source = proto.Field( - proto.STRING, - number=1, - ) - mime_type = proto.Field( - proto.STRING, - number=2, - ) - - class BatchOutputConfig(proto.Message): - r"""The message for output config in batch process. - Attributes: - gcs_destination (str): - The output Cloud Storage directory to put the - processed documents. - """ - - gcs_destination = proto.Field( - proto.STRING, - number=1, - ) - - name = proto.Field( - proto.STRING, - number=1, - ) - input_configs = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=BatchInputConfig, - ) - output_config = proto.Field( - proto.MESSAGE, - number=3, - message=BatchOutputConfig, - ) - input_documents = proto.Field( - proto.MESSAGE, - number=5, - message=document_io.BatchDocumentsInputConfig, - ) - document_output_config = proto.Field( - proto.MESSAGE, - number=6, - message=document_io.DocumentOutputConfig, - ) - skip_human_review = proto.Field( - proto.BOOL, - number=4, - ) - - -class BatchProcessResponse(proto.Message): - 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_v1beta3.types.BatchProcessMetadata.State): - The state of the current batch processing. - state_message (str): - A message providing more details about the - current state of processing. For example, the - error message if the operation is failed. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - individual_process_statuses (Sequence[google.cloud.documentai_v1beta3.types.BatchProcessMetadata.IndividualProcessStatus]): - The list of response details of each - document. - """ - class State(proto.Enum): - r"""Possible states of the batch processing operation.""" - STATE_UNSPECIFIED = 0 - WAITING = 1 - RUNNING = 2 - SUCCEEDED = 3 - CANCELLING = 4 - CANCELLED = 5 - FAILED = 6 - - class IndividualProcessStatus(proto.Message): - r"""The status of a each individual document in the batch - process. - - Attributes: - input_gcs_source (str): - The source of the document, same as the [input_gcs_source] - field in the request when the batch process started. The - batch process is started by take snapshot of that document, - since a user can move or change that document during the - process. - status (google.rpc.status_pb2.Status): - The status of the processing of the document. - output_gcs_destination (str): - The output_gcs_destination (in the request as - 'output_gcs_destination') of the processed document if it - was successful, otherwise empty. - human_review_operation (str): - The name of the operation triggered by the - processed document. If the human review process - is not triggered, this field will be empty. It - has the same response type and metadata as the - long running operation returned by - ReviewDocument method. - human_review_status (google.cloud.documentai_v1beta3.types.HumanReviewStatus): - The status of human review on the processed - document. - """ - - input_gcs_source = proto.Field( - proto.STRING, - number=1, - ) - status = proto.Field( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - output_gcs_destination = proto.Field( - proto.STRING, - number=3, - ) - human_review_operation = proto.Field( - proto.STRING, - number=4, - ) - human_review_status = proto.Field( - proto.MESSAGE, - number=5, - message='HumanReviewStatus', - ) - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - individual_process_statuses = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=IndividualProcessStatus, - ) - - -class FetchProcessorTypesRequest(proto.Message): - r"""Request message for fetch processor types. - Attributes: - parent (str): - Required. The project of processor type to - list. Format: - projects/{project}/locations/{location} - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - - -class FetchProcessorTypesResponse(proto.Message): - r"""Response message for fetch processor types. - Attributes: - processor_types (Sequence[google.cloud.documentai_v1beta3.types.ProcessorType]): - The list of processor types. - """ - - processor_types = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=processor_type.ProcessorType, - ) - - -class ListProcessorsRequest(proto.Message): - r"""Request message for list all processors belongs to a project. - Attributes: - parent (str): - Required. The parent (project and location) - which owns this collection of Processors. - Format: projects/{project}/locations/{location} - page_size (int): - The maximum number of processors to return. - If unspecified, at most 50 processors will be - returned. The maximum value is 100; values above - 100 will be coerced to 100. - page_token (str): - We will return the processors sorted by - creation time. The page token will point to the - next processor. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - page_size = proto.Field( - proto.INT32, - number=2, - ) - page_token = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProcessorsResponse(proto.Message): - r"""Response message for list processors. - Attributes: - processors (Sequence[google.cloud.documentai_v1beta3.types.Processor]): - The list of processors. - next_page_token (str): - Points to the next processor, otherwise - empty. - """ - - @property - def raw_page(self): - return self - - processors = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=gcd_processor.Processor, - ) - next_page_token = proto.Field( - proto.STRING, - number=2, - ) - - -class CreateProcessorRequest(proto.Message): - r"""Request message for create a processor. Notice this request - is sent to a regionalized backend service, and if the processor - type is not available on that region, the creation will fail. - - Attributes: - parent (str): - Required. The parent (project and location) - under which to create the processor. Format: - projects/{project}/locations/{location} - processor (google.cloud.documentai_v1beta3.types.Processor): - Required. The processor to be created, requires - [processor_type] and [display_name] to be set. Also, the - processor is under CMEK if CMEK fields are set. - """ - - parent = proto.Field( - proto.STRING, - number=1, - ) - processor = proto.Field( - proto.MESSAGE, - number=2, - message=gcd_processor.Processor, - ) - - -class DeleteProcessorRequest(proto.Message): - r"""Request message for the delete processor method. - Attributes: - name (str): - Required. The processor resource name to be - deleted. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class DeleteProcessorMetadata(proto.Message): - r"""The long running operation metadata for delete processor - method. - - Attributes: - common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): - The basic metadata of the long running - operation. - """ - - common_metadata = proto.Field( - proto.MESSAGE, - number=5, - message=operation_metadata.CommonOperationMetadata, - ) - - -class EnableProcessorRequest(proto.Message): - r"""Request message for the enable processor method. - Attributes: - name (str): - Required. The processor resource name to be - enabled. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class EnableProcessorResponse(proto.Message): - r"""Response message for the enable processor method. """ - - -class EnableProcessorMetadata(proto.Message): - r"""The long running operation metadata for enable processor - method. - - Attributes: - common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): - The basic metadata of the long running - operation. - """ - - common_metadata = proto.Field( - proto.MESSAGE, - number=5, - message=operation_metadata.CommonOperationMetadata, - ) - - -class DisableProcessorRequest(proto.Message): - r"""Request message for the disable processor method. - Attributes: - name (str): - Required. The processor resource name to be - disabled. - """ - - name = proto.Field( - proto.STRING, - number=1, - ) - - -class DisableProcessorResponse(proto.Message): - r"""Response message for the disable processor method. """ - - -class DisableProcessorMetadata(proto.Message): - r"""The long running operation metadata for disable processor - method. - - Attributes: - common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): - The basic metadata of the long running - operation. - """ - - common_metadata = proto.Field( - proto.MESSAGE, - number=5, - message=operation_metadata.CommonOperationMetadata, - ) - - -class ReviewDocumentRequest(proto.Message): - r"""Request message for review document method. - Next Id: 6. - - Attributes: - inline_document (google.cloud.documentai_v1beta3.types.Document): - An inline document proto. - human_review_config (str): - Required. The resource name of the - HumanReviewConfig that the document will be - reviewed with. - document (google.cloud.documentai_v1beta3.types.Document): - The document that needs human review. - enable_schema_validation (bool): - Whether the validation should be performed on - the ad-hoc review request. - priority (google.cloud.documentai_v1beta3.types.ReviewDocumentRequest.Priority): - The priority of the human review task. - """ - class Priority(proto.Enum): - r"""The priority level of the human review task.""" - DEFAULT = 0 - URGENT = 1 - - inline_document = proto.Field( - proto.MESSAGE, - number=4, - oneof='source', - message=gcd_document.Document, - ) - human_review_config = proto.Field( - proto.STRING, - number=1, - ) - document = proto.Field( - proto.MESSAGE, - number=2, - message=gcd_document.Document, - ) - enable_schema_validation = proto.Field( - proto.BOOL, - number=3, - ) - priority = proto.Field( - proto.ENUM, - number=5, - enum=Priority, - ) - - -class ReviewDocumentResponse(proto.Message): - r"""Response message for review document method. - Attributes: - gcs_destination (str): - The Cloud Storage uri for the human reviewed - document. - """ - - gcs_destination = proto.Field( - proto.STRING, - number=1, - ) - - -class ReviewDocumentOperationMetadata(proto.Message): - r"""The long running operation metadata for review document - method. - - Attributes: - state (google.cloud.documentai_v1beta3.types.ReviewDocumentOperationMetadata.State): - Used only when Operation.done is false. - state_message (str): - A message providing more details about the - current state of processing. For example, the - error message if the operation is failed. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - common_metadata (google.cloud.documentai_v1beta3.types.CommonOperationMetadata): - The basic metadata of the long running - operation. - """ - class State(proto.Enum): - r"""State of the longrunning operation.""" - STATE_UNSPECIFIED = 0 - RUNNING = 1 - CANCELLING = 2 - SUCCEEDED = 3 - FAILED = 4 - CANCELLED = 5 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - common_metadata = proto.Field( - proto.MESSAGE, - number=5, - message=operation_metadata.CommonOperationMetadata, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py deleted file mode 100644 index 8dfa1bba..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/geometry.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'Vertex', - 'NormalizedVertex', - 'BoundingPoly', - }, -) - - -class Vertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the vertex coordinates are in the same scale as the - original image. - - Attributes: - x (int): - X coordinate. - y (int): - Y coordinate (starts from the top of the - image). - """ - - x = proto.Field( - proto.INT32, - number=1, - ) - y = proto.Field( - proto.INT32, - number=2, - ) - - -class NormalizedVertex(proto.Message): - r"""A vertex represents a 2D point in the image. - NOTE: the normalized vertex coordinates are relative to the - original image and range from 0 to 1. - - Attributes: - x (float): - X coordinate. - y (float): - Y coordinate (starts from the top of the - image). - """ - - x = proto.Field( - proto.FLOAT, - number=1, - ) - y = proto.Field( - proto.FLOAT, - number=2, - ) - - -class BoundingPoly(proto.Message): - r"""A bounding polygon for the detected image annotation. - Attributes: - vertices (Sequence[google.cloud.documentai_v1beta3.types.Vertex]): - The bounding polygon vertices. - normalized_vertices (Sequence[google.cloud.documentai_v1beta3.types.NormalizedVertex]): - The bounding polygon normalized vertices. - """ - - vertices = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Vertex', - ) - normalized_vertices = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='NormalizedVertex', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py deleted file mode 100644 index 07ae7a1d..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/operation_metadata.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'CommonOperationMetadata', - }, -) - - -class CommonOperationMetadata(proto.Message): - r"""The common metadata for long running operations. - Attributes: - state (google.cloud.documentai_v1beta3.types.CommonOperationMetadata.State): - The state of the operation. - state_message (str): - A message providing more details about the - current state of processing. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The creation time of the operation. - update_time (google.protobuf.timestamp_pb2.Timestamp): - The last update time of the operation. - """ - class State(proto.Enum): - r"""State of the longrunning operation.""" - STATE_UNSPECIFIED = 0 - RUNNING = 1 - CANCELLING = 2 - SUCCEEDED = 3 - FAILED = 4 - CANCELLED = 5 - - state = proto.Field( - proto.ENUM, - number=1, - enum=State, - ) - state_message = proto.Field( - proto.STRING, - number=2, - ) - create_time = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - update_time = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py deleted file mode 100644 index 22632689..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'Processor', - }, -) - - -class Processor(proto.Message): - r"""The first-class citizen for DocumentAI. Each processor - defines how to extract structural information from a document. - - Attributes: - name (str): - Output only. Immutable. The resource name of - the processor. Format: - projects/{project}/locations/{location}/processors/{processor} - type_ (str): - The processor type. - display_name (str): - The display name of the processor. - state (google.cloud.documentai_v1beta3.types.Processor.State): - Output only. The state of the processor. - default_processor_version (str): - The default processor version. - process_endpoint (str): - Output only. Immutable. The http endpoint - that can be called to invoke processing. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time the processor was created. - kms_key_name (str): - The KMS key used for encryption/decryption in - CMEK scenarios. See - https://cloud.google.com/security-key- - management. - """ - class State(proto.Enum): - r"""The possible states of the processor.""" - STATE_UNSPECIFIED = 0 - ENABLED = 1 - DISABLED = 2 - ENABLING = 3 - DISABLING = 4 - CREATING = 5 - FAILED = 6 - DELETING = 7 - - name = proto.Field( - proto.STRING, - number=1, - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - display_name = proto.Field( - proto.STRING, - number=3, - ) - state = proto.Field( - proto.ENUM, - number=4, - enum=State, - ) - default_processor_version = proto.Field( - proto.STRING, - number=9, - ) - process_endpoint = proto.Field( - proto.STRING, - number=6, - ) - create_time = proto.Field( - proto.MESSAGE, - number=7, - message=timestamp_pb2.Timestamp, - ) - kms_key_name = proto.Field( - proto.STRING, - number=8, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py b/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py deleted file mode 100644 index 3bdc8f0f..00000000 --- a/owl-bot-staging/v1beta3/google/cloud/documentai_v1beta3/types/processor_type.py +++ /dev/null @@ -1,85 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.cloud.documentai.v1beta3', - manifest={ - 'ProcessorType', - }, -) - - -class ProcessorType(proto.Message): - r"""A processor type is responsible for performing a certain - document understanding task on a certain type of document. - - Attributes: - name (str): - The resource name of the processor type. - type_ (str): - The type of the processor. - category (str): - The processor category. - available_locations (Sequence[google.cloud.documentai_v1beta3.types.ProcessorType.LocationInfo]): - The locations in which this processor is - available. - allow_creation (bool): - Whether the processor type allows creation. - If yes, user can create a processor of this - processor type. Otherwise, user needs to require - for whitelisting. - """ - - class LocationInfo(proto.Message): - r"""The location information about where the processor is - available. - - Attributes: - location_id (str): - The location id. - """ - - location_id = proto.Field( - proto.STRING, - number=1, - ) - - name = proto.Field( - proto.STRING, - number=1, - ) - type_ = proto.Field( - proto.STRING, - number=2, - ) - category = proto.Field( - proto.STRING, - number=3, - ) - available_locations = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=LocationInfo, - ) - allow_creation = proto.Field( - proto.BOOL, - number=6, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/v1beta3/mypy.ini b/owl-bot-staging/v1beta3/mypy.ini deleted file mode 100644 index 4505b485..00000000 --- a/owl-bot-staging/v1beta3/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.6 -namespace_packages = True diff --git a/owl-bot-staging/v1beta3/noxfile.py b/owl-bot-staging/v1beta3/noxfile.py deleted file mode 100644 index 2f5c8bba..00000000 --- a/owl-bot-staging/v1beta3/noxfile.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", -] - -@nox.session(python=['3.6', '3.7', '3.8', '3.9']) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'asyncmock', 'pytest-asyncio') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/documentai_v1beta3/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python='3.7') -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=['3.6', '3.7']) -def mypy(session): - """Run the type checker.""" - session.install('mypy', 'types-pkg_resources') - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python='3.6') -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx<3.0.0", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) diff --git a/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py b/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py deleted file mode 100644 index fcfc5540..00000000 --- a/owl-bot-staging/v1beta3/scripts/fixup_documentai_v1beta3_keywords.py +++ /dev/null @@ -1,184 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class documentaiCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_process_documents': ('name', 'input_configs', 'output_config', 'input_documents', 'document_output_config', 'skip_human_review', ), - 'create_processor': ('parent', 'processor', ), - 'delete_processor': ('name', ), - 'disable_processor': ('name', ), - 'enable_processor': ('name', ), - 'fetch_processor_types': ('parent', ), - 'list_processors': ('parent', 'page_size', 'page_token', ), - 'process_document': ('name', 'inline_document', 'raw_document', 'document', 'skip_human_review', ), - 'review_document': ('human_review_config', 'inline_document', 'document', 'enable_schema_validation', 'priority', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: not a.keyword.value in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=documentaiCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the documentai client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/v1beta3/setup.py b/owl-bot-staging/v1beta3/setup.py deleted file mode 100644 index 90b5b3cf..00000000 --- a/owl-bot-staging/v1beta3/setup.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os -import setuptools # type: ignore - -version = '0.1.0' - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, 'README.rst') -with io.open(readme_filename, encoding='utf-8') as readme_file: - readme = readme_file.read() - -setuptools.setup( - name='google-cloud-documentai', - version=version, - long_description=readme, - packages=setuptools.PEP420PackageFinder.find(), - namespace_packages=('google', 'google.cloud'), - platforms='Posix; MacOS X; Windows', - include_package_data=True, - install_requires=( - 'google-api-core[grpc] >= 1.27.0, < 2.0.0dev', - 'libcst >= 0.2.5', - 'proto-plus >= 1.15.0', - 'packaging >= 14.3', ), - python_requires='>=3.6', - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Internet', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - zip_safe=False, -) diff --git a/owl-bot-staging/v1beta3/tests/__init__.py b/owl-bot-staging/v1beta3/tests/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta3/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta3/tests/unit/__init__.py b/owl-bot-staging/v1beta3/tests/unit/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta3/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py b/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta3/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py deleted file mode 100644 index b54a5fcc..00000000 --- a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py deleted file mode 100644 index 6dbbe6e7..00000000 --- a/owl-bot-staging/v1beta3/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ /dev/null @@ -1,3158 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import mock -import packaging.version - -import grpc -from grpc.experimental import aio -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule - - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.documentai_v1beta3.services.document_processor_service import DocumentProcessorServiceAsyncClient -from google.cloud.documentai_v1beta3.services.document_processor_service import DocumentProcessorServiceClient -from google.cloud.documentai_v1beta3.services.document_processor_service import pagers -from google.cloud.documentai_v1beta3.services.document_processor_service import transports -from google.cloud.documentai_v1beta3.services.document_processor_service.transports.base import _GOOGLE_AUTH_VERSION -from google.cloud.documentai_v1beta3.types import document -from google.cloud.documentai_v1beta3.types import document_io -from google.cloud.documentai_v1beta3.types import document_processor_service -from google.cloud.documentai_v1beta3.types import geometry -from google.cloud.documentai_v1beta3.types import processor -from google.cloud.documentai_v1beta3.types import processor as gcd_processor -from google.cloud.documentai_v1beta3.types import processor_type -from google.longrunning import operations_pb2 -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.protobuf import wrappers_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import color_pb2 # type: ignore -from google.type import date_pb2 # type: ignore -from google.type import datetime_pb2 # type: ignore -from google.type import money_pb2 # type: ignore -from google.type import postal_address_pb2 # type: ignore -import google.auth - - -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(None) is None - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert DocumentProcessorServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_from_service_account_info(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'documentai.googleapis.com:443' - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_service_account_always_use_jwt(client_class): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_service_account_always_use_jwt_true(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - -@pytest.mark.parametrize("client_class", [ - DocumentProcessorServiceClient, - DocumentProcessorServiceAsyncClient, -]) -def test_document_processor_service_client_from_service_account_file(client_class): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json") - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == 'documentai.googleapis.com:443' - - -def test_document_processor_service_client_get_transport_class(): - transport = DocumentProcessorServiceClient.get_transport_class() - available_transports = [ - transports.DocumentProcessorServiceGrpcTransport, - ] - assert transport in available_transports - - transport = DocumentProcessorServiceClient.get_transport_class("grpc") - assert transport == transports.DocumentProcessorServiceGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) -@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) -def test_document_processor_service_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(DocumentProcessorServiceClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "true"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc", "false"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), -]) -@mock.patch.object(DocumentProcessorServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceClient)) -@mock.patch.object(DocumentProcessorServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentProcessorServiceAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_document_processor_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DocumentProcessorServiceClient, transports.DocumentProcessorServiceGrpcTransport, "grpc"), - (DocumentProcessorServiceAsyncClient, transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), -]) -def test_document_processor_service_client_client_options_credentials_file(client_class, transport_class, transport_name): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_document_processor_service_client_client_options_from_dict(): - with mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = DocumentProcessorServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) - - -def test_process_document(transport: str = 'grpc', request_type=document_processor_service.ProcessRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse( - human_review_operation='human_review_operation_value', - ) - response = client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.ProcessResponse) - assert response.human_review_operation == 'human_review_operation_value' - - -def test_process_document_from_dict(): - test_process_document(request_type=dict) - - -def test_process_document_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - client.process_document() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - -@pytest.mark.asyncio -async def test_process_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ProcessRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse( - human_review_operation='human_review_operation_value', - )) - response = await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.ProcessResponse) - assert response.human_review_operation == 'human_review_operation_value' - - -@pytest.mark.asyncio -async def test_process_document_async_from_dict(): - await test_process_document_async(request_type=dict) - - -def test_process_document_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = document_processor_service.ProcessResponse() - client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_process_document_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) - await client.process_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_process_document_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.process_document( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -def test_process_document_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.process_document( - document_processor_service.ProcessRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_process_document_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.process_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ProcessResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ProcessResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.process_document( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -@pytest.mark.asyncio -async def test_process_document_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.process_document( - document_processor_service.ProcessRequest(), - name='name_value', - ) - - -def test_batch_process_documents(transport: str = 'grpc', request_type=document_processor_service.BatchProcessRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_batch_process_documents_from_dict(): - test_batch_process_documents(request_type=dict) - - -def test_batch_process_documents_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - client.batch_process_documents() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - -@pytest.mark.asyncio -async def test_batch_process_documents_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.BatchProcessRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.BatchProcessRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_batch_process_documents_async_from_dict(): - await test_batch_process_documents_async(request_type=dict) - - -def test_batch_process_documents_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.BatchProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_batch_process_documents_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.BatchProcessRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.batch_process_documents(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_batch_process_documents_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_process_documents( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -def test_batch_process_documents_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.batch_process_documents( - document_processor_service.BatchProcessRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_process_documents), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_process_documents( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -@pytest.mark.asyncio -async def test_batch_process_documents_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.batch_process_documents( - document_processor_service.BatchProcessRequest(), - name='name_value', - ) - - -def test_fetch_processor_types(transport: str = 'grpc', request_type=document_processor_service.FetchProcessorTypesRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.FetchProcessorTypesResponse( - ) - response = client.fetch_processor_types(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.FetchProcessorTypesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.FetchProcessorTypesResponse) - - -def test_fetch_processor_types_from_dict(): - test_fetch_processor_types(request_type=dict) - - -def test_fetch_processor_types_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - client.fetch_processor_types() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.FetchProcessorTypesRequest() - - -@pytest.mark.asyncio -async def test_fetch_processor_types_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.FetchProcessorTypesRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse( - )) - response = await client.fetch_processor_types(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.FetchProcessorTypesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, document_processor_service.FetchProcessorTypesResponse) - - -@pytest.mark.asyncio -async def test_fetch_processor_types_async_from_dict(): - await test_fetch_processor_types_async(request_type=dict) - - -def test_fetch_processor_types_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.FetchProcessorTypesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - call.return_value = document_processor_service.FetchProcessorTypesResponse() - client.fetch_processor_types(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_fetch_processor_types_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.FetchProcessorTypesRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse()) - await client.fetch_processor_types(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -def test_fetch_processor_types_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.FetchProcessorTypesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.fetch_processor_types( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - - -def test_fetch_processor_types_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.fetch_processor_types( - document_processor_service.FetchProcessorTypesRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_fetch_processor_types_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.fetch_processor_types), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.FetchProcessorTypesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.FetchProcessorTypesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.fetch_processor_types( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - - -@pytest.mark.asyncio -async def test_fetch_processor_types_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.fetch_processor_types( - document_processor_service.FetchProcessorTypesRequest(), - parent='parent_value', - ) - - -def test_list_processors(transport: str = 'grpc', request_type=document_processor_service.ListProcessorsRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ListProcessorsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_processors(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ListProcessorsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProcessorsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_processors_from_dict(): - test_list_processors(request_type=dict) - - -def test_list_processors_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - client.list_processors() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ListProcessorsRequest() - - -@pytest.mark.asyncio -async def test_list_processors_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ListProcessorsRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_processors(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ListProcessorsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProcessorsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_processors_async_from_dict(): - await test_list_processors_async(request_type=dict) - - -def test_list_processors_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ListProcessorsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - call.return_value = document_processor_service.ListProcessorsResponse() - client.list_processors(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_processors_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ListProcessorsRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse()) - await client.list_processors(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -def test_list_processors_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ListProcessorsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_processors( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - - -def test_list_processors_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_processors( - document_processor_service.ListProcessorsRequest(), - parent='parent_value', - ) - - -@pytest.mark.asyncio -async def test_list_processors_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = document_processor_service.ListProcessorsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document_processor_service.ListProcessorsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_processors( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - - -@pytest.mark.asyncio -async def test_list_processors_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_processors( - document_processor_service.ListProcessorsRequest(), - parent='parent_value', - ) - - -def test_list_processors_pager(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - processor.Processor(), - ], - next_page_token='abc', - ), - document_processor_service.ListProcessorsResponse( - processors=[], - next_page_token='def', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - ], - next_page_token='ghi', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_processors(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, processor.Processor) - for i in results) - -def test_list_processors_pages(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - processor.Processor(), - ], - next_page_token='abc', - ), - document_processor_service.ListProcessorsResponse( - processors=[], - next_page_token='def', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - ], - next_page_token='ghi', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - ], - ), - RuntimeError, - ) - pages = list(client.list_processors(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_processors_async_pager(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - processor.Processor(), - ], - next_page_token='abc', - ), - document_processor_service.ListProcessorsResponse( - processors=[], - next_page_token='def', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - ], - next_page_token='ghi', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_processors(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, processor.Processor) - for i in responses) - -@pytest.mark.asyncio -async def test_list_processors_async_pages(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_processors), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - processor.Processor(), - ], - next_page_token='abc', - ), - document_processor_service.ListProcessorsResponse( - processors=[], - next_page_token='def', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - ], - next_page_token='ghi', - ), - document_processor_service.ListProcessorsResponse( - processors=[ - processor.Processor(), - processor.Processor(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_processors(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -def test_create_processor(transport: str = 'grpc', request_type=document_processor_service.CreateProcessorRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gcd_processor.Processor( - name='name_value', - type_='type__value', - display_name='display_name_value', - state=gcd_processor.Processor.State.ENABLED, - default_processor_version='default_processor_version_value', - process_endpoint='process_endpoint_value', - kms_key_name='kms_key_name_value', - ) - response = client.create_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.CreateProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, gcd_processor.Processor) - assert response.name == 'name_value' - assert response.type_ == 'type__value' - assert response.display_name == 'display_name_value' - assert response.state == gcd_processor.Processor.State.ENABLED - assert response.default_processor_version == 'default_processor_version_value' - assert response.process_endpoint == 'process_endpoint_value' - assert response.kms_key_name == 'kms_key_name_value' - - -def test_create_processor_from_dict(): - test_create_processor(request_type=dict) - - -def test_create_processor_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - client.create_processor() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.CreateProcessorRequest() - - -@pytest.mark.asyncio -async def test_create_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.CreateProcessorRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor( - name='name_value', - type_='type__value', - display_name='display_name_value', - state=gcd_processor.Processor.State.ENABLED, - default_processor_version='default_processor_version_value', - process_endpoint='process_endpoint_value', - kms_key_name='kms_key_name_value', - )) - response = await client.create_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.CreateProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, gcd_processor.Processor) - assert response.name == 'name_value' - assert response.type_ == 'type__value' - assert response.display_name == 'display_name_value' - assert response.state == gcd_processor.Processor.State.ENABLED - assert response.default_processor_version == 'default_processor_version_value' - assert response.process_endpoint == 'process_endpoint_value' - assert response.kms_key_name == 'kms_key_name_value' - - -@pytest.mark.asyncio -async def test_create_processor_async_from_dict(): - await test_create_processor_async(request_type=dict) - - -def test_create_processor_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.CreateProcessorRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - call.return_value = gcd_processor.Processor() - client.create_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_processor_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.CreateProcessorRequest() - - request.parent = 'parent/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor()) - await client.create_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent/value', - ) in kw['metadata'] - - -def test_create_processor_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gcd_processor.Processor() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_processor( - parent='parent_value', - processor=gcd_processor.Processor(name='name_value'), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - assert args[0].processor == gcd_processor.Processor(name='name_value') - - -def test_create_processor_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_processor( - document_processor_service.CreateProcessorRequest(), - parent='parent_value', - processor=gcd_processor.Processor(name='name_value'), - ) - - -@pytest.mark.asyncio -async def test_create_processor_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gcd_processor.Processor() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcd_processor.Processor()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_processor( - parent='parent_value', - processor=gcd_processor.Processor(name='name_value'), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].parent == 'parent_value' - assert args[0].processor == gcd_processor.Processor(name='name_value') - - -@pytest.mark.asyncio -async def test_create_processor_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_processor( - document_processor_service.CreateProcessorRequest(), - parent='parent_value', - processor=gcd_processor.Processor(name='name_value'), - ) - - -def test_delete_processor(transport: str = 'grpc', request_type=document_processor_service.DeleteProcessorRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.delete_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DeleteProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_delete_processor_from_dict(): - test_delete_processor(request_type=dict) - - -def test_delete_processor_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - client.delete_processor() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DeleteProcessorRequest() - - -@pytest.mark.asyncio -async def test_delete_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.DeleteProcessorRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.delete_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DeleteProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_delete_processor_async_from_dict(): - await test_delete_processor_async(request_type=dict) - - -def test_delete_processor_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.DeleteProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.delete_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_processor_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.DeleteProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.delete_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_delete_processor_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_processor( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -def test_delete_processor_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_processor( - document_processor_service.DeleteProcessorRequest(), - name='name_value', - ) - - -@pytest.mark.asyncio -async def test_delete_processor_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_processor( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].name == 'name_value' - - -@pytest.mark.asyncio -async def test_delete_processor_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_processor( - document_processor_service.DeleteProcessorRequest(), - name='name_value', - ) - - -def test_enable_processor(transport: str = 'grpc', request_type=document_processor_service.EnableProcessorRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.enable_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.enable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.EnableProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_enable_processor_from_dict(): - test_enable_processor(request_type=dict) - - -def test_enable_processor_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.enable_processor), - '__call__') as call: - client.enable_processor() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.EnableProcessorRequest() - - -@pytest.mark.asyncio -async def test_enable_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.EnableProcessorRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.enable_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.enable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.EnableProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_enable_processor_async_from_dict(): - await test_enable_processor_async(request_type=dict) - - -def test_enable_processor_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.EnableProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.enable_processor), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.enable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_enable_processor_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.EnableProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.enable_processor), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.enable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_disable_processor(transport: str = 'grpc', request_type=document_processor_service.DisableProcessorRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.disable_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.disable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DisableProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_disable_processor_from_dict(): - test_disable_processor(request_type=dict) - - -def test_disable_processor_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.disable_processor), - '__call__') as call: - client.disable_processor() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DisableProcessorRequest() - - -@pytest.mark.asyncio -async def test_disable_processor_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.DisableProcessorRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.disable_processor), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.disable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.DisableProcessorRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_disable_processor_async_from_dict(): - await test_disable_processor_async(request_type=dict) - - -def test_disable_processor_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.DisableProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.disable_processor), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.disable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_disable_processor_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.DisableProcessorRequest() - - request.name = 'name/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.disable_processor), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.disable_processor(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name/value', - ) in kw['metadata'] - - -def test_review_document(transport: str = 'grpc', request_type=document_processor_service.ReviewDocumentRequest): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_review_document_from_dict(): - test_review_document(request_type=dict) - - -def test_review_document_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - client.review_document() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - -@pytest.mark.asyncio -async def test_review_document_async(transport: str = 'grpc_asyncio', request_type=document_processor_service.ReviewDocumentRequest): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == document_processor_service.ReviewDocumentRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_review_document_async_from_dict(): - await test_review_document_async(request_type=dict) - - -def test_review_document_field_headers(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ReviewDocumentRequest() - - request.human_review_config = 'human_review_config/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'human_review_config=human_review_config/value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_review_document_field_headers_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = document_processor_service.ReviewDocumentRequest() - - request.human_review_config = 'human_review_config/value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.review_document(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'human_review_config=human_review_config/value', - ) in kw['metadata'] - - -def test_review_document_flattened(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.review_document( - human_review_config='human_review_config_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].human_review_config == 'human_review_config_value' - - -def test_review_document_flattened_error(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.review_document( - document_processor_service.ReviewDocumentRequest(), - human_review_config='human_review_config_value', - ) - - -@pytest.mark.asyncio -async def test_review_document_flattened_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.review_document), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.review_document( - human_review_config='human_review_config_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].human_review_config == 'human_review_config_value' - - -@pytest.mark.asyncio -async def test_review_document_flattened_error_async(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.review_document( - document_processor_service.ReviewDocumentRequest(), - human_review_config='human_review_config_value', - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DocumentProcessorServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = DocumentProcessorServiceClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.DocumentProcessorServiceGrpcTransport, - ) - -def test_document_processor_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_document_processor_service_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'process_document', - 'batch_process_documents', - 'fetch_processor_types', - 'list_processors', - 'create_processor', - 'delete_processor', - 'enable_processor', - 'disable_processor', - 'review_document', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - ), - quota_project_id="octopus", - ) - - -def test_document_processor_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DocumentProcessorServiceTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id=None, - ) - - -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DocumentProcessorServiceClient() - adc.assert_called_once_with( - scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_document_processor_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DocumentProcessorServiceGrpcTransport, - transports.DocumentProcessorServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_document_processor_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with(scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_document_processor_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', -), - scopes=["1", "2"], - default_host="documentai.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - - -def test_document_processor_service_host_no_port(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com'), - ) - assert client.transport._host == 'documentai.googleapis.com:443' - - -def test_document_processor_service_host_with_port(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='documentai.googleapis.com:8000'), - ) - assert client.transport._host == 'documentai.googleapis.com:8000' - -def test_document_processor_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentProcessorServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_document_processor_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DocumentProcessorServiceGrpcTransport, transports.DocumentProcessorServiceGrpcAsyncIOTransport]) -def test_document_processor_service_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_document_processor_service_grpc_lro_client(): - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_document_processor_service_grpc_lro_async_client(): - client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc_asyncio', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsAsyncClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_human_review_config_path(): - project = "squid" - location = "clam" - processor = "whelk" - expected = "projects/{project}/locations/{location}/processors/{processor}/humanReviewConfig".format(project=project, location=location, processor=processor, ) - actual = DocumentProcessorServiceClient.human_review_config_path(project, location, processor) - assert expected == actual - - -def test_parse_human_review_config_path(): - expected = { - "project": "octopus", - "location": "oyster", - "processor": "nudibranch", - } - path = DocumentProcessorServiceClient.human_review_config_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_human_review_config_path(path) - assert expected == actual - -def test_processor_path(): - project = "cuttlefish" - location = "mussel" - processor = "winkle" - expected = "projects/{project}/locations/{location}/processors/{processor}".format(project=project, location=location, processor=processor, ) - actual = DocumentProcessorServiceClient.processor_path(project, location, processor) - assert expected == actual - - -def test_parse_processor_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "processor": "abalone", - } - path = DocumentProcessorServiceClient.processor_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_processor_path(path) - assert expected == actual - -def test_processor_type_path(): - project = "squid" - location = "clam" - processor_type = "whelk" - expected = "projects/{project}/locations/{location}/processorTypes/{processor_type}".format(project=project, location=location, processor_type=processor_type, ) - actual = DocumentProcessorServiceClient.processor_type_path(project, location, processor_type) - assert expected == actual - - -def test_parse_processor_type_path(): - expected = { - "project": "octopus", - "location": "oyster", - "processor_type": "nudibranch", - } - path = DocumentProcessorServiceClient.processor_type_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_processor_type_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = DocumentProcessorServiceClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "mussel", - } - path = DocumentProcessorServiceClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "winkle" - expected = "folders/{folder}".format(folder=folder, ) - actual = DocumentProcessorServiceClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "nautilus", - } - path = DocumentProcessorServiceClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "scallop" - expected = "organizations/{organization}".format(organization=organization, ) - actual = DocumentProcessorServiceClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "abalone", - } - path = DocumentProcessorServiceClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "squid" - expected = "projects/{project}".format(project=project, ) - actual = DocumentProcessorServiceClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "clam", - } - path = DocumentProcessorServiceClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "whelk" - location = "octopus" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = DocumentProcessorServiceClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - } - path = DocumentProcessorServiceClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = DocumentProcessorServiceClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: - client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.DocumentProcessorServiceTransport, '_prep_wrapped_messages') as prep: - transport_class = DocumentProcessorServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index b68164f2..1b05c04c 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -41,9 +41,6 @@ DocumentProcessorServiceClient, ) from google.cloud.documentai_v1.services.document_processor_service import transports -from google.cloud.documentai_v1.services.document_processor_service.transports.base import ( - _API_CORE_VERSION, -) from google.cloud.documentai_v1.services.document_processor_service.transports.base import ( _GOOGLE_AUTH_VERSION, ) @@ -66,8 +63,9 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases # - Delete these pytest markers (Make the "greater than or equal to" tests the default). requires_google_auth_lt_1_25_0 = pytest.mark.skipif( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), @@ -78,16 +76,6 @@ reason="This test requires google-auth >= 1.25.0", ) -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -152,6 +140,37 @@ def test_document_processor_service_client_from_service_account_info(client_clas assert client.transport._host == "documentai.googleapis.com:443" +@pytest.mark.parametrize( + "client_class", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], +) +def test_document_processor_service_client_service_account_always_use_jwt(client_class): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_document_processor_service_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + @pytest.mark.parametrize( "client_class", [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], @@ -1406,7 +1425,6 @@ def test_document_processor_service_transport_auth_adc_old_google_auth(transport (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_document_processor_service_transport_create_channel( transport_class, grpc_helpers ): @@ -1437,79 +1455,6 @@ def test_document_processor_service_transport_create_channel( ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_processor_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_processor_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1534,7 +1479,7 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1643,7 +1588,7 @@ def test_document_processor_service_transport_channel_mtls_with_client_cert_sour "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1690,7 +1635,7 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index 4b80d6e1..e3a98af8 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -43,9 +43,6 @@ from google.cloud.documentai_v1beta2.services.document_understanding_service import ( transports, ) -from google.cloud.documentai_v1beta2.services.document_understanding_service.transports.base import ( - _API_CORE_VERSION, -) from google.cloud.documentai_v1beta2.services.document_understanding_service.transports.base import ( _GOOGLE_AUTH_VERSION, ) @@ -58,8 +55,9 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases # - Delete these pytest markers (Make the "greater than or equal to" tests the default). requires_google_auth_lt_1_25_0 = pytest.mark.skipif( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), @@ -70,16 +68,6 @@ reason="This test requires google-auth >= 1.25.0", ) -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -146,6 +134,39 @@ def test_document_understanding_service_client_from_service_account_info(client_ assert client.transport._host == "us-documentai.googleapis.com:443" +@pytest.mark.parametrize( + "client_class", + [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient,], +) +def test_document_understanding_service_client_service_account_always_use_jwt( + client_class, +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DocumentUnderstandingServiceGrpcTransport, "grpc"), + (transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_document_understanding_service_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + @pytest.mark.parametrize( "client_class", [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient,], @@ -1137,7 +1158,6 @@ def test_document_understanding_service_transport_auth_adc_old_google_auth( ), ], ) -@requires_api_core_gte_1_26_0 def test_document_understanding_service_transport_create_channel( transport_class, grpc_helpers ): @@ -1168,85 +1188,6 @@ def test_document_understanding_service_transport_create_channel( ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentUnderstandingServiceGrpcTransport, grpc_helpers), - ( - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_understanding_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "us-documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentUnderstandingServiceGrpcTransport, grpc_helpers), - ( - transports.DocumentUnderstandingServiceGrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_understanding_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "us-documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1271,7 +1212,7 @@ def test_document_understanding_service_grpc_transport_client_cert_source_for_mt "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1380,7 +1321,7 @@ def test_document_understanding_service_transport_channel_mtls_with_client_cert_ "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1429,7 +1370,7 @@ def test_document_understanding_service_transport_channel_mtls_with_adc( "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 8c210ecf..d264e511 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -44,9 +44,6 @@ from google.cloud.documentai_v1beta3.services.document_processor_service import ( transports, ) -from google.cloud.documentai_v1beta3.services.document_processor_service.transports.base import ( - _API_CORE_VERSION, -) from google.cloud.documentai_v1beta3.services.document_processor_service.transports.base import ( _GOOGLE_AUTH_VERSION, ) @@ -72,8 +69,9 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively +# through google-api-core: +# - Delete the auth "less than" test cases # - Delete these pytest markers (Make the "greater than or equal to" tests the default). requires_google_auth_lt_1_25_0 = pytest.mark.skipif( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), @@ -84,16 +82,6 @@ reason="This test requires google-auth >= 1.25.0", ) -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -158,6 +146,37 @@ def test_document_processor_service_client_from_service_account_info(client_clas assert client.transport._host == "documentai.googleapis.com:443" +@pytest.mark.parametrize( + "client_class", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], +) +def test_document_processor_service_client_service_account_always_use_jwt(client_class): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + client = client_class(credentials=creds) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DocumentProcessorServiceGrpcTransport, "grpc"), + (transports.DocumentProcessorServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_document_processor_service_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + @pytest.mark.parametrize( "client_class", [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient,], @@ -2754,7 +2773,6 @@ def test_document_processor_service_transport_auth_adc_old_google_auth(transport (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_document_processor_service_transport_create_channel( transport_class, grpc_helpers ): @@ -2785,79 +2803,6 @@ def test_document_processor_service_transport_create_channel( ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_processor_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DocumentProcessorServiceGrpcTransport, grpc_helpers), - (transports.DocumentProcessorServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_document_processor_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "documentai.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2882,7 +2827,7 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2991,7 +2936,7 @@ def test_document_processor_service_transport_channel_mtls_with_client_cert_sour "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3038,7 +2983,7 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ From f204a09f635dc542dd0998ae307a522cbd5cac25 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Wed, 30 Jun 2021 16:49:21 -0600 Subject: [PATCH 3/6] fix: require google-api-core >= 1.26.0 --- setup.py | 2 +- testing/constraints-3.6.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 03e8c9f6..184c6da2 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ platforms="Posix; MacOS X; Windows", include_package_data=True, install_requires=( - "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", + "google-api-core[grpc] >= 1.26.0, <2.0.0dev", "proto-plus >= 1.10.0", "packaging >= 14.3", ), diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 23cdd2b8..63d16e7e 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,7 +5,7 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.22.2 +google-api-core==1.26.0 proto-plus==1.10.0 packaging==14.3 google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core From 259bb97d81a45f93ccb292bf56d487546890f95c Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 8 Jul 2021 19:05:14 +0000 Subject: [PATCH 4/6] fix: never use self-signed jwt --- .../transports/base.py | 9 +++++++- .../transports/base.py | 9 +++++++- .../transports/base.py | 9 +++++++- owlbot.py | 23 +++++++++++++++++++ .../test_document_processor_service.py | 4 ++-- .../test_document_understanding_service.py | 4 ++-- .../test_document_processor_service.py | 4 ++-- 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index 26811788..446db239 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -147,7 +147,14 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + # Documentai uses a regional host (us-documentai.googleapis.com) as the default + # so self-signed JWT cannot be used. + # Intentionally pass default scopes as user scopes so the auth library + # does not use the self-signed JWT flow. + scopes_kwargs = { + "scopes": scopes or cls.AUTH_SCOPES, + "default_scopes": cls.AUTH_SCOPES, + } else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index b59623e7..27542730 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -148,7 +148,14 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + # Documentai uses a regional host (us-documentai.googleapis.com) as the default + # so self-signed JWT cannot be used. + # Intentionally pass default scopes as user scopes so the auth library + # does not use the self-signed JWT flow. + scopes_kwargs = { + "scopes": scopes or cls.AUTH_SCOPES, + "default_scopes": cls.AUTH_SCOPES, + } else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index f87da34b..0685a88a 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -148,7 +148,14 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + # Documentai uses a regional host (us-documentai.googleapis.com) as the default + # so self-signed JWT cannot be used. + # Intentionally pass default scopes as user scopes so the auth library + # does not use the self-signed JWT flow. + scopes_kwargs = { + "scopes": scopes or cls.AUTH_SCOPES, + "default_scopes": cls.AUTH_SCOPES, + } else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/owlbot.py b/owlbot.py index b3763809..e8ea9848 100644 --- a/owlbot.py +++ b/owlbot.py @@ -13,6 +13,7 @@ # limitations under the License. """This script is used to synthesize generated parts of this library.""" +import re from synthtool.languages import python @@ -34,6 +35,28 @@ "setup.py", "scripts/fixup_documentai_v*", # this library was always generated with the microgenerator ] + + s.replace(library / "google/**/base.py", + """scopes_kwargs = \{"scopes": scopes, "default_scopes": cls\.AUTH_SCOPES\}""", + """# Documentai uses a regional host (us-documentai.googleapis.com) as the default + # so self-signed JWT cannot be used. + # Intentionally pass default scopes as user scopes so the auth library + # does not use the self-signed JWT flow. + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES}""") + + s.replace(library / "tests/**/*.py", + """(@requires_google_auth_gte_1_25_0 +def test_document_.*?_service_base_transport_with_credentials_file.*?)scopes=None,""", + """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", + flags=re.MULTILINE | re.DOTALL, + ) + + s.replace(library / "tests/**/*.py", + """(@requires_google_auth_gte_1_25_0 +def test_document_.*?_service_auth_adc.*?)scopes=None,""", + """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", + flags=re.MULTILINE | re.DOTALL, + ) s.move(library, excludes=excludes) s.remove_staging_dirs() diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index 1b05c04c..2ff4ab8f 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -1315,7 +1315,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -1359,7 +1359,7 @@ def test_document_processor_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, ) diff --git a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index e3a98af8..edf64f1d 100644 --- a/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -1043,7 +1043,7 @@ def test_document_understanding_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -1087,7 +1087,7 @@ def test_document_understanding_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentUnderstandingServiceClient() adc.assert_called_once_with( - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, ) diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index d264e511..10caadd6 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -2663,7 +2663,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -2707,7 +2707,7 @@ def test_document_processor_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( - scopes=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, ) From 83593fcd405450660f33332bce6b41cbcc604896 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 8 Jul 2021 19:07:07 +0000 Subject: [PATCH 5/6] chore: add link to issue --- owlbot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/owlbot.py b/owlbot.py index e8ea9848..d20abadb 100644 --- a/owlbot.py +++ b/owlbot.py @@ -42,6 +42,7 @@ # so self-signed JWT cannot be used. # Intentionally pass default scopes as user scopes so the auth library # does not use the self-signed JWT flow. + # https://github.com/googleapis/python-documentai/issues/174 scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES}""") s.replace(library / "tests/**/*.py", From 7d5b6a5850cf1aefc60c29ae98595abe4fa25cd3 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim Date: Thu, 8 Jul 2021 19:20:31 +0000 Subject: [PATCH 6/6] fix: just disable for v1beta2 --- .../document_processor_service/transports/base.py | 9 +-------- .../document_understanding_service/transports/base.py | 1 + .../document_processor_service/transports/base.py | 9 +-------- owlbot.py | 6 +++--- .../documentai_v1/test_document_processor_service.py | 4 ++-- .../test_document_processor_service.py | 4 ++-- 6 files changed, 10 insertions(+), 23 deletions(-) diff --git a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index 446db239..26811788 100644 --- a/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -147,14 +147,7 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - # Documentai uses a regional host (us-documentai.googleapis.com) as the default - # so self-signed JWT cannot be used. - # Intentionally pass default scopes as user scopes so the auth library - # does not use the self-signed JWT flow. - scopes_kwargs = { - "scopes": scopes or cls.AUTH_SCOPES, - "default_scopes": cls.AUTH_SCOPES, - } + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index 27542730..c29c565c 100644 --- a/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -152,6 +152,7 @@ def _get_scopes_kwargs( # so self-signed JWT cannot be used. # Intentionally pass default scopes as user scopes so the auth library # does not use the self-signed JWT flow. + # https://github.com/googleapis/python-documentai/issues/174 scopes_kwargs = { "scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES, diff --git a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index 0685a88a..f87da34b 100644 --- a/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -148,14 +148,7 @@ def _get_scopes_kwargs( packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0") ): - # Documentai uses a regional host (us-documentai.googleapis.com) as the default - # so self-signed JWT cannot be used. - # Intentionally pass default scopes as user scopes so the auth library - # does not use the self-signed JWT flow. - scopes_kwargs = { - "scopes": scopes or cls.AUTH_SCOPES, - "default_scopes": cls.AUTH_SCOPES, - } + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} else: scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} diff --git a/owlbot.py b/owlbot.py index d20abadb..3072f992 100644 --- a/owlbot.py +++ b/owlbot.py @@ -36,7 +36,7 @@ "scripts/fixup_documentai_v*", # this library was always generated with the microgenerator ] - s.replace(library / "google/**/base.py", + s.replace(library / "google/cloud/documentai_v1beta2/**/base.py", """scopes_kwargs = \{"scopes": scopes, "default_scopes": cls\.AUTH_SCOPES\}""", """# Documentai uses a regional host (us-documentai.googleapis.com) as the default # so self-signed JWT cannot be used. @@ -45,14 +45,14 @@ # https://github.com/googleapis/python-documentai/issues/174 scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES, "default_scopes": cls.AUTH_SCOPES}""") - s.replace(library / "tests/**/*.py", + s.replace(library / "tests/**/documentai_v1beta2/*.py", """(@requires_google_auth_gte_1_25_0 def test_document_.*?_service_base_transport_with_credentials_file.*?)scopes=None,""", """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", flags=re.MULTILINE | re.DOTALL, ) - s.replace(library / "tests/**/*.py", + s.replace(library / "tests/**/documentai_v1beta2/*.py", """(@requires_google_auth_gte_1_25_0 def test_document_.*?_service_auth_adc.*?)scopes=None,""", """\g<1>scopes=("https://www.googleapis.com/auth/cloud-platform",),""", diff --git a/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/tests/unit/gapic/documentai_v1/test_document_processor_service.py index 2ff4ab8f..1b05c04c 100644 --- a/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -1315,7 +1315,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -1359,7 +1359,7 @@ def test_document_processor_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, ) diff --git a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 10caadd6..d264e511 100644 --- a/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -2663,7 +2663,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): ) load_creds.assert_called_once_with( "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id="octopus", ) @@ -2707,7 +2707,7 @@ def test_document_processor_service_auth_adc(): adc.return_value = (ga_credentials.AnonymousCredentials(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, default_scopes=("https://www.googleapis.com/auth/cloud-platform",), quota_project_id=None, )